diff options
author | Lorenz Diener <[email protected]> | 2022-11-26 00:15:40 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2022-11-26 00:15:40 +0200 |
commit | 9171760ebfdf72582a9e31404b3a5c6ed9d098fd (patch) | |
tree | a752aa2ca3b1b76dc3987b81de7ef3b13988b853 /mastodon | |
parent | 6c9683cbbff58fac1ce93d6aeac4e3ac0fbd7905 (diff) | |
parent | 677474820f0c4598c03e963e10822d69cda7bdde (diff) | |
download | mastodon.py-9171760ebfdf72582a9e31404b3a5c6ed9d098fd.tar.gz |
Merge pull request #281 from catgoat/catgoat/domain_blocks
Add admin domain blocks
Diffstat (limited to 'mastodon')
-rw-r--r-- | mastodon/Mastodon.py | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index a60994e..c519a0d 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -3363,6 +3363,88 @@ class Mastodon: | |||
3363 | params = self.__generate_params(locals()) | 3363 | params = self.__generate_params(locals()) |
3364 | return self.__api_request('GET', '/api/v1/admin/trends/links', params) | 3364 | return self.__api_request('GET', '/api/v1/admin/trends/links', params) |
3365 | 3365 | ||
3366 | @api_version("4.0.0","4.0.0","4.0.0") | ||
3367 | def admin_domain_blocks(self, id:str=None, limit:int=None): | ||
3368 | """ | ||
3369 | Fetches a list of blocked domains. Requires scope `admin:read:domain_blocks`. | ||
3370 | |||
3371 | Provide an `id` to fetch a specific domain block based on its database id. | ||
3372 | |||
3373 | Returns a list of `domain dicts`_, or 404 if a domain is queried for and not found. | ||
3374 | """ | ||
3375 | id = self.__unpack_id(id) | ||
3376 | if id is not None: | ||
3377 | return self.__api_request('GET', '/api/v1/admin/domain_blocks/{0}'.format(id)) | ||
3378 | else: | ||
3379 | params = self.__generate_params(locals(),['limit']) | ||
3380 | return self.__api_request('GET', '/api/v1/admin/domain_blocks/', params) | ||
3381 | |||
3382 | @api_version("4.0.0","4.0.0","4.0.0") | ||
3383 | def admin_domain_block(self, domain:str, severity:str=None, reject_media:bool=None, reject_reports:bool=None, private_comment:str=None, public_comment:str=None, obfuscate:bool=None): | ||
3384 | """ | ||
3385 | Perform a moderation action on a domain. | ||
3386 | |||
3387 | Valid severities are: | ||
3388 | * "silence" - hide all posts from federated timelines and do not show notifications to local users from the remote instance's users unless they are following the remote user. | ||
3389 | * "suspend" - deny interactions with this instance going forward. This action is reversible. | ||
3390 | * "limit" - generally used with reject_media=true to force reject media from an instance without silencing or suspending.. | ||
3391 | |||
3392 | If no action is specified, the domain is only silenced. | ||
3393 | `domain` is the domain to block. Note that using the top level domain will also imapct all subdomains. ie, example.com will also impact subdomain.example.com. | ||
3394 | `reject_media` will not download remote media on to your local instance media storage. | ||
3395 | `reject_reports` ignores all reports from the remote instance. | ||
3396 | `private_comment` sets a private admin comment for the domain. | ||
3397 | `public_comment` sets a publicly available comment for this domain, which will be available to local users and may be available to everyone depending on your settings. | ||
3398 | `obfuscate` sensors some part of the domain name. Useful if the domain name contains unwanted words like slurs. | ||
3399 | """ | ||
3400 | if domain is None: | ||
3401 | raise AttributeError("Must provide a domain to block a domain") | ||
3402 | |||
3403 | params = self.__generate_params(locals()) | ||
3404 | |||
3405 | |||
3406 | self.__api_request('POST', '/api/v1/admin/domain_blocks/', params) | ||
3407 | |||
3408 | @api_version("4.0.0","4.0.0","4.0.0") | ||
3409 | def admin_update_domain_block(self, id:str, severity:str=None, reject_media:bool=None, reject_reports:bool=None, private_comment:str=None, public_comment:str=None, obfuscate:bool=None): | ||
3410 | """ | ||
3411 | Modify existing moderation action on a domain. | ||
3412 | |||
3413 | Valid severities are: | ||
3414 | * "silence" - hide all posts from federated timelines and do not show notifications to local users from the remote instance's users unless they are following the remote user. | ||
3415 | * "suspend" - deny interactions with this instance going forward. This action is reversible. | ||
3416 | * "limit" - generally used with reject_media=true to force reject media from an instance without silencing or suspending. | ||
3417 | |||
3418 | If no action is specified, the domain is only silenced. | ||
3419 | `domain` is the domain to block. Note that using the top level domain will also imapct all subdomains. ie, example.com will also impact subdomain.example.com. | ||
3420 | `reject_media` will not download remote media on to your local instance media storage. | ||
3421 | `reject_reports` ignores all reports from the remote instance. | ||
3422 | `private_comment` sets a private admin comment for the domain. | ||
3423 | `public_comment` sets a publicly available comment for this domain, which will be available to local users and may be available to everyone depending on your settings. | ||
3424 | `obfuscate` sensors some part of the domain name. Useful if the domain name contains unwanted words like slurs. | ||
3425 | """ | ||
3426 | if id is None: | ||
3427 | raise AttributeError("Must provide an id to modify the existing moderation actions on a given domain.") | ||
3428 | |||
3429 | params = self.__generate_params(locals()) | ||
3430 | |||
3431 | self.__api_request('PUT', '/api/v1/admin/domain_blocks/', params) | ||
3432 | |||
3433 | @api_version("4.0.0","4.0.0","4.0.0") | ||
3434 | def admin_delete_domain_blocks(self, id:str=None): | ||
3435 | """ | ||
3436 | Removes moderation action against a given domain. Requires scope `admin:write:domain_blocks`. | ||
3437 | |||
3438 | Provide an `id` to remove a specific domain block based on its database id. | ||
3439 | |||
3440 | Returns 200 OK if successful. | ||
3441 | """ | ||
3442 | id = self.__unpack_id(id) | ||
3443 | if id is not None: | ||
3444 | return self.__api_request('DELETE', '/api/v1/admin/domain_blocks/{0}'.format(id)) | ||
3445 | else: | ||
3446 | raise AttributeError("You must provide an id of an existing domain block to remove it.") | ||
3447 | |||
3366 | ### | 3448 | ### |
3367 | # Push subscription crypto utilities | 3449 | # Push subscription crypto utilities |
3368 | ### | 3450 | ### |