From 038181fdd1f555d7d0123e6075e874e3d8754ce7 Mon Sep 17 00:00:00 2001 From: micah <42517495+catgoat@users.noreply.github.com> Date: Thu, 24 Nov 2022 02:21:00 +0000 Subject: start to add domain blocks --- mastodon/Mastodon.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index f0d9cc5..5cd2c7b 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -3263,6 +3263,68 @@ class Mastodon: id = self.__unpack_id(id) return self.__api_request('POST', '/api/v1/admin/reports/{0}/resolve'.format(id)) + @api_version("2.9.1", "2.9.1", __DICT_VERSION_ADMIN_ACCOUNT) + def admin_domain_blocks(self, id=None): + """ + Fetches a list of blocked domains + + * Set `remote` to True to get remote accounts, otherwise local accounts are returned (default: local accounts) + * Set `by_domain` to a domain to get only accounts from that domain. + * Set `status` to one of "active", "pending", "disabled", "silenced" or "suspended" to get only accounts with that moderation status (default: active) + * Set `username` to a string to get only accounts whose username contains this string. + * Set `display_name` to a string to get only accounts whose display name contains this string. + * Set `email` to an email to get only accounts with that email (this only works on local accounts). + * Set `ip` to an ip (as a string, standard v4/v6 notation) to get only accounts whose last active ip is that ip (this only works on local accounts). + * Set `staff_only` to True to only get staff accounts (this only works on local accounts). + + Note that setting the boolean parameters to False does not mean "give me users to which this does not apply" but + instead means "I do not care if users have this attribute". + + Returns a list of `admin account dicts`_. + """ + id = self.__unpack_id(id) + if id is not None: + return self.__api_request('GET', '/api/v1/admin/domain_blocks/{0}'.format(id)) + else + return self.__api_request('GET', '/api/v1/admin/domain_blocks/'.format(id)) + + @api_version("2.9.1", "2.9.1", "2.9.1") + def admin_domain_block(self, domain: str, severity=None, reject_media=None, reject_reports=None, private_comment=None, public_comment=None, obfuscate=None): + """ + Perform a moderation action on an account. + + Valid actions are: + * "disable" - for a local user, disable login. + * "silence" - hide the users posts from all public timelines. + * "suspend" - irreversibly delete all the user's posts, past and future. + * "sensitive" - forcce an accounts media visibility to always be sensitive. + + If no action is specified, the user is only issued a warning. + + Specify the id of a report as `report_id` to close the report with this moderation action as the resolution. + Specify `warning_preset_id` to use a warning preset as the notification text to the user, or `text` to specify text directly. + If both are specified, they are concatenated (preset first). Note that there is currently no API to retrieve or create + warning presets. + + Set `send_email_notification` to False to not send the user an email notification informing them of the moderation action. + """ + if action is None: + action = "none" + + if not send_email_notification: + send_email_notification = None + + id = self.__unpack_id(id) + if report_id is not None: + report_id = self.__unpack_id(report_id) + + params = self.__generate_params(locals(), ['id', 'action']) + + params["type"] = action + + self.__api_request( + 'POST', '/api/v1/admin/accounts/{0}/action'.format(id), params) + ### # Push subscription crypto utilities ### -- cgit v1.2.3 From cdef1d5107b82ef3f7b1c0c202ddcff93e3558d9 Mon Sep 17 00:00:00 2001 From: micah <42517495+catgoat@users.noreply.github.com> Date: Fri, 25 Nov 2022 01:39:33 +0000 Subject: documentation --- mastodon/Mastodon.py | 60 ++++++++++++++++++---------------------------------- 1 file changed, 20 insertions(+), 40 deletions(-) diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 5cd2c7b..77deef9 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -3263,24 +3263,14 @@ class Mastodon: id = self.__unpack_id(id) return self.__api_request('POST', '/api/v1/admin/reports/{0}/resolve'.format(id)) - @api_version("2.9.1", "2.9.1", __DICT_VERSION_ADMIN_ACCOUNT) + @api_version("4.0.0","4.0.0","4.0.0") def admin_domain_blocks(self, id=None): """ Fetches a list of blocked domains - * Set `remote` to True to get remote accounts, otherwise local accounts are returned (default: local accounts) - * Set `by_domain` to a domain to get only accounts from that domain. - * Set `status` to one of "active", "pending", "disabled", "silenced" or "suspended" to get only accounts with that moderation status (default: active) - * Set `username` to a string to get only accounts whose username contains this string. - * Set `display_name` to a string to get only accounts whose display name contains this string. - * Set `email` to an email to get only accounts with that email (this only works on local accounts). - * Set `ip` to an ip (as a string, standard v4/v6 notation) to get only accounts whose last active ip is that ip (this only works on local accounts). - * Set `staff_only` to True to only get staff accounts (this only works on local accounts). + Provide an `id` to fetch a specific domain block based on its database id. - Note that setting the boolean parameters to False does not mean "give me users to which this does not apply" but - instead means "I do not care if users have this attribute". - - Returns a list of `admin account dicts`_. + Returns a list of `domain dicts`_. """ id = self.__unpack_id(id) if id is not None: @@ -3288,42 +3278,32 @@ class Mastodon: else return self.__api_request('GET', '/api/v1/admin/domain_blocks/'.format(id)) - @api_version("2.9.1", "2.9.1", "2.9.1") + @api_version("4.0.0","4.0.0","4.0.0") def admin_domain_block(self, domain: str, severity=None, reject_media=None, reject_reports=None, private_comment=None, public_comment=None, obfuscate=None): """ - Perform a moderation action on an account. + Perform a moderation action on a domain. - Valid actions are: - * "disable" - for a local user, disable login. - * "silence" - hide the users posts from all public timelines. - * "suspend" - irreversibly delete all the user's posts, past and future. - * "sensitive" - forcce an accounts media visibility to always be sensitive. + Valid severities are: + * "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. + * "suspend" - deny interactions with this instance going forward. This action is reversible. + * "limit" - generally used with reject_media=true to force reject media from an instance without silencing or suspending.. - If no action is specified, the user is only issued a warning. - - Specify the id of a report as `report_id` to close the report with this moderation action as the resolution. - Specify `warning_preset_id` to use a warning preset as the notification text to the user, or `text` to specify text directly. - If both are specified, they are concatenated (preset first). Note that there is currently no API to retrieve or create - warning presets. - - Set `send_email_notification` to False to not send the user an email notification informing them of the moderation action. + If no action is specified, the domain is only silenced. + `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. + `reject_media` will not download remote media on to your local instance media storage. + `reject_reports` ignores all reports from the remote instance. + `private_comment` sets a private admin comment for the domain. + `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. + `obfuscate` sensors some part of the domain name. Useful if the domain name contains unwanted words like slurs. """ - if action is None: - action = "none" - - if not send_email_notification: - send_email_notification = None - - id = self.__unpack_id(id) - if report_id is not None: - report_id = self.__unpack_id(report_id) + if domain is None: + raise AttributeError("Must provide a domain to block a domain") - params = self.__generate_params(locals(), ['id', 'action']) + params = self.__generate_params(locals()) - params["type"] = action self.__api_request( - 'POST', '/api/v1/admin/accounts/{0}/action'.format(id), params) + 'POST', '/api/v1/admin/domain_block/, params) ### # Push subscription crypto utilities -- cgit v1.2.3 From 2c7b58568db735534912b2bc0990294e9d4a9c19 Mon Sep 17 00:00:00 2001 From: micah <42517495+catgoat@users.noreply.github.com> Date: Fri, 25 Nov 2022 01:50:57 +0000 Subject: add delete and modify with comments --- mastodon/Mastodon.py | 56 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 77deef9..3d04955 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -3264,24 +3264,25 @@ class Mastodon: return self.__api_request('POST', '/api/v1/admin/reports/{0}/resolve'.format(id)) @api_version("4.0.0","4.0.0","4.0.0") - def admin_domain_blocks(self, id=None): + def admin_domain_blocks(self, id:str=None, limit:int=None): """ - Fetches a list of blocked domains + Fetches a list of blocked domains. Requires scope `admin:read:domain_blocks`. Provide an `id` to fetch a specific domain block based on its database id. - Returns a list of `domain dicts`_. + Returns a list of `domain dicts`_, or 404 if a domain is queried for and not found. """ id = self.__unpack_id(id) if id is not None: return self.__api_request('GET', '/api/v1/admin/domain_blocks/{0}'.format(id)) else - return self.__api_request('GET', '/api/v1/admin/domain_blocks/'.format(id)) + params = params = self.__generate_params(locals(),['limit']) + return self.__api_request('GET', '/api/v1/admin/domain_blocks/') @api_version("4.0.0","4.0.0","4.0.0") - def admin_domain_block(self, domain: str, severity=None, reject_media=None, reject_reports=None, private_comment=None, public_comment=None, obfuscate=None): + 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): """ - Perform a moderation action on a domain. + Perform a moderation action on a domain. Valid severities are: * "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. @@ -3303,7 +3304,48 @@ class Mastodon: self.__api_request( - 'POST', '/api/v1/admin/domain_block/, params) + 'POST', '/api/v1/admin/domain_blocks/, params) + + @api_version("4.0.0","4.0.0","4.0.0") + 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): + """ + Modify existing moderation action on a domain. + + Valid severities are: + * "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. + * "suspend" - deny interactions with this instance going forward. This action is reversible. + * "limit" - generally used with reject_media=true to force reject media from an instance without silencing or suspending.. + + If no action is specified, the domain is only silenced. + `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. + `reject_media` will not download remote media on to your local instance media storage. + `reject_reports` ignores all reports from the remote instance. + `private_comment` sets a private admin comment for the domain. + `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. + `obfuscate` sensors some part of the domain name. Useful if the domain name contains unwanted words like slurs. + """ + if id is None: + raise AttributeError("Must provide an id to modify the existing moderation actions on a given domain.") + + params = self.__generate_params(locals()) + + self.__api_request( + 'PUT', '/api/v1/admin/domain_blocks/, params) + + @api_version("4.0.0","4.0.0","4.0.0") + def admin_delete_domain_blocks(self, id:str=None): + """ + Removes moderation action against a given domain. Requires scope `admin:write:domain_blocks`. + + Provide an `id` to remove a specific domain block based on its database id. + + Returns 200 OK if successful. + """ + id = self.__unpack_id(id) + if id is not None: + return self.__api_request('DELETE', '/api/v1/admin/domain_blocks/{0}'.format(id)) + else + raise AttributeError("You must provide an id of an existing domain block to remove it.") ### # Push subscription crypto utilities -- cgit v1.2.3 From 2b8c5de03fb81704aac7639539354783f5a5e3c1 Mon Sep 17 00:00:00 2001 From: micah <42517495+catgoat@users.noreply.github.com> Date: Fri, 25 Nov 2022 21:47:54 +0000 Subject: typos lol --- mastodon/Mastodon.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index befb030..c519a0d 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -3376,8 +3376,8 @@ class Mastodon: if id is not None: return self.__api_request('GET', '/api/v1/admin/domain_blocks/{0}'.format(id)) else: - params = params = self.__generate_params(locals(),['limit']) - return self.__api_request('GET', '/api/v1/admin/domain_blocks/') + params = self.__generate_params(locals(),['limit']) + return self.__api_request('GET', '/api/v1/admin/domain_blocks/', params) @api_version("4.0.0","4.0.0","4.0.0") 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): @@ -3413,7 +3413,7 @@ class Mastodon: Valid severities are: * "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. * "suspend" - deny interactions with this instance going forward. This action is reversible. - * "limit" - generally used with reject_media=true to force reject media from an instance without silencing or suspending.. + * "limit" - generally used with reject_media=true to force reject media from an instance without silencing or suspending. If no action is specified, the domain is only silenced. `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. -- cgit v1.2.3 From 677474820f0c4598c03e963e10822d69cda7bdde Mon Sep 17 00:00:00 2001 From: micah <42517495+catgoat@users.noreply.github.com> Date: Fri, 25 Nov 2022 22:01:57 +0000 Subject: update docs, too! --- docs/index.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/index.rst b/docs/index.rst index a1d9695..b95c64d 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -882,6 +882,25 @@ Admin account dicts 'account': # The user's account, as a standard user dict } +Admin domain block dicts +~~~~~~~~~~~~~~~~~~~~~~~~ +.. _domain dicts + +.. code-block::python + mastodon.domain_blocks(id=1) + #Returns the following dictionary: + { + 'id': #Str. The database id of a domain block, + 'domain': #Str. The root domain of a block, ie: "example.com", + 'created_at': #Datetime of the block creation. + 'severity': #Str. Severity of the domain block, ie: "suspend". + 'reject_media': #Boolean. True if media is not downloaded from this domain. + 'reject_reports': #Boolean. True if reports are automatically ignored from this domain. + 'private_comment': #Str. Private admin comment for a block. None if not set. + 'public_comment': #Str. Publicly viewable (depending on settings) comment about this domain. None if not set. + 'obfuscate': #Boolean. True if domain name is obfuscated when listing. + } + Status edit dicts ~~~~~~~~~~~~~~~~~ .. _status edit dict: @@ -1446,6 +1465,10 @@ have admin: scopes attached with a lot of care, but be extra careful with those .. automethod:: Mastodon.admin_trending_tags .. automethod:: Mastodon.admin_trending_statuses .. automethod:: Mastodon.admin_trending_links +.. automethod:: Mastodon.admin_domain_blocks +.. automethod:: Mastodon.admin_domain_block +.. automethod:: Mastodon.admin_update_domain_block +.. automethod:: Mastodon.admin_delete_domain_block Acknowledgements ---------------- -- cgit v1.2.3