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 | |
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
-rw-r--r-- | docs/index.rst | 23 | ||||
-rw-r--r-- | mastodon/Mastodon.py | 82 |
2 files changed, 105 insertions, 0 deletions
diff --git a/docs/index.rst b/docs/index.rst index 10e18c0..bb6e5b1 100644 --- a/docs/index.rst +++ b/docs/index.rst | |||
@@ -882,6 +882,25 @@ Admin account dicts | |||
882 | 'account': # The user's account, as a standard user dict | 882 | 'account': # The user's account, as a standard user dict |
883 | } | 883 | } |
884 | 884 | ||
885 | Admin domain block dicts | ||
886 | ~~~~~~~~~~~~~~~~~~~~~~~~ | ||
887 | .. _domain dicts | ||
888 | |||
889 | .. code-block::python | ||
890 | mastodon.domain_blocks(id=1) | ||
891 | #Returns the following dictionary: | ||
892 | { | ||
893 | 'id': #Str. The database id of a domain block, | ||
894 | 'domain': #Str. The root domain of a block, ie: "example.com", | ||
895 | 'created_at': #Datetime of the block creation. | ||
896 | 'severity': #Str. Severity of the domain block, ie: "suspend". | ||
897 | 'reject_media': #Boolean. True if media is not downloaded from this domain. | ||
898 | 'reject_reports': #Boolean. True if reports are automatically ignored from this domain. | ||
899 | 'private_comment': #Str. Private admin comment for a block. None if not set. | ||
900 | 'public_comment': #Str. Publicly viewable (depending on settings) comment about this domain. None if not set. | ||
901 | 'obfuscate': #Boolean. True if domain name is obfuscated when listing. | ||
902 | } | ||
903 | |||
885 | Status edit dicts | 904 | Status edit dicts |
886 | ~~~~~~~~~~~~~~~~~ | 905 | ~~~~~~~~~~~~~~~~~ |
887 | .. _status edit dict: | 906 | .. _status edit dict: |
@@ -1446,6 +1465,10 @@ have admin: scopes attached with a lot of care, but be extra careful with those | |||
1446 | .. automethod:: Mastodon.admin_trending_tags | 1465 | .. automethod:: Mastodon.admin_trending_tags |
1447 | .. automethod:: Mastodon.admin_trending_statuses | 1466 | .. automethod:: Mastodon.admin_trending_statuses |
1448 | .. automethod:: Mastodon.admin_trending_links | 1467 | .. automethod:: Mastodon.admin_trending_links |
1468 | .. automethod:: Mastodon.admin_domain_blocks | ||
1469 | .. automethod:: Mastodon.admin_domain_block | ||
1470 | .. automethod:: Mastodon.admin_update_domain_block | ||
1471 | .. automethod:: Mastodon.admin_delete_domain_block | ||
1449 | 1472 | ||
1450 | Acknowledgements | 1473 | Acknowledgements |
1451 | ---------------- | 1474 | ---------------- |
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 | ### |