aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'mastodon')
-rw-r--r--mastodon/Mastodon.py88
1 files changed, 81 insertions, 7 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index 2adcd74..895fa36 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -255,7 +255,7 @@ class Mastodon:
255 __DICT_VERSION_CONVERSATION = bigger_version(bigger_version("2.6.0", __DICT_VERSION_ACCOUNT), __DICT_VERSION_STATUS) 255 __DICT_VERSION_CONVERSATION = bigger_version(bigger_version("2.6.0", __DICT_VERSION_ACCOUNT), __DICT_VERSION_STATUS)
256 __DICT_VERSION_SCHEDULED_STATUS = bigger_version("2.7.0", __DICT_VERSION_STATUS) 256 __DICT_VERSION_SCHEDULED_STATUS = bigger_version("2.7.0", __DICT_VERSION_STATUS)
257 __DICT_VERSION_PREFERENCES = "2.8.0" 257 __DICT_VERSION_PREFERENCES = "2.8.0"
258 __DICT_VERSION_ADMIN_ACCOUNT = bigger_version("2.9.1", __DICT_VERSION_ACCOUNT) 258 __DICT_VERSION_ADMIN_ACCOUNT = bigger_version("4.0.0", __DICT_VERSION_ACCOUNT)
259 __DICT_VERSION_FEATURED_TAG = "3.0.0" 259 __DICT_VERSION_FEATURED_TAG = "3.0.0"
260 __DICT_VERSION_MARKER = "3.0.0" 260 __DICT_VERSION_MARKER = "3.0.0"
261 __DICT_VERSION_REACTION = "3.1.0" 261 __DICT_VERSION_REACTION = "3.1.0"
@@ -666,8 +666,7 @@ class Mastodon:
666 received_scopes += self.__SCOPE_SETS[scope_set] 666 received_scopes += self.__SCOPE_SETS[scope_set]
667 667
668 if not set(scopes) <= set(received_scopes): 668 if not set(scopes) <= set(received_scopes):
669 raise MastodonAPIError( 669 raise MastodonAPIError('Granted scopes "' + " ".join(received_scopes) + '" do not contain all of the requested scopes "' + " ".join(scopes) + '".')
670 'Granted scopes "' + " ".join(received_scopes) + '" do not contain all of the requested scopes "' + " ".join(scopes) + '".')
671 670
672 if to_file is not None: 671 if to_file is not None:
673 with open(to_file, 'w') as token_file: 672 with open(to_file, 'w') as token_file:
@@ -3130,9 +3129,81 @@ class Mastodon:
3130 ### 3129 ###
3131 # Moderation API 3130 # Moderation API
3132 ### 3131 ###
3132 @api_version("2.9.1", "4.0.0", __DICT_VERSION_ADMIN_ACCOUNT)
3133 def admin_accounts_v2(self, origin=None, by_domain=None, status=None, username=None, display_name=None, email=None, ip=None,
3134 permissions=None, invited_by=None, role_ids=None, max_id=None, min_id=None, since_id=None, limit=None):
3135 """
3136 Fetches a list of accounts that match given criteria. By default, local accounts are returned.
3137
3138 * Set `origin` to "local" or "remote" to get only local or remote accounts.
3139 * Set `by_domain` to a domain to get only accounts from that domain.
3140 * Set `status` to one of "active", "pending", "disabled", "silenced" or "suspended" to get only accounts with that moderation status (default: active)
3141 * Set `username` to a string to get only accounts whose username contains this string.
3142 * Set `display_name` to a string to get only accounts whose display name contains this string.
3143 * Set `email` to an email to get only accounts with that email (this only works on local accounts).
3144 * 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).
3145 * Set `permissions` to "staff" to only get accounts with staff permissions.
3146 * Set `invited_by` to an account id to get only accounts invited by this user.
3147 * Set `role_ids` to a list of role IDs to get only accounts with those roles.
3148
3149 Returns a list of `admin account dicts`_.
3150 """
3151 if max_id is not None:
3152 max_id = self.__unpack_id(max_id, dateconv=True)
3153
3154 if min_id is not None:
3155 min_id = self.__unpack_id(min_id, dateconv=True)
3156
3157 if since_id is not None:
3158 since_id = self.__unpack_id(since_id, dateconv=True)
3159
3160 if role_ids is not None:
3161 if not isinstance(role_ids, list):
3162 role_ids = [role_ids]
3163 role_ids = list(map(self.__unpack_id, role_ids))
3164
3165 if invited_by is not None:
3166 invited_by = self.__unpack_id(invited_by)
3167
3168 if permissions is not None and not permissions in ["staff"]:
3169 raise MastodonIllegalArgumentError("Permissions must be staff if passed")
3170
3171 if origin is not None and not origin in ["local", "remote"]:
3172 raise MastodonIllegalArgumentError("Origin must be local or remote")
3173
3174 if status is not None and not status in ["active", "pending", "disabled", "silenced", "suspended"]:
3175 raise MastodonIllegalArgumentError("Status must be local or active, pending, disabled, silenced or suspended")
3176
3177 if not by_domain is None:
3178 by_domain = self.__deprotocolize(by_domain)
3179
3180 params = self.__generate_params(locals())
3181 return self.__api_request('GET', '/api/v2/admin/accounts', params)
3182
3133 @api_version("2.9.1", "2.9.1", __DICT_VERSION_ADMIN_ACCOUNT) 3183 @api_version("2.9.1", "2.9.1", __DICT_VERSION_ADMIN_ACCOUNT)
3134 def admin_accounts(self, remote=False, by_domain=None, status='active', username=None, display_name=None, email=None, ip=None, staff_only=False, max_id=None, min_id=None, since_id=None, limit=None): 3184 def admin_accounts(self, remote=False, by_domain=None, status='active', username=None, display_name=None, email=None, ip=None, staff_only=False, max_id=None, min_id=None, since_id=None, limit=None):
3135 """ 3185 """
3186 Currently a synonym for admin_accounts_v1, now deprecated. You are strongly encouraged to use admin_accounts_v2 instead, since this one is kind of bad.
3187
3188 !!!!! This function may be switched to calling the v2 API in the future. This is your warning. If you want to keep using v1, use it explicitly. !!!!!
3189 """
3190 return self.admin_accounts_v1(
3191 remote=remote,
3192 by_domain=by_domain,
3193 status=status,
3194 username=username,
3195 display_name=display_name,
3196 email=email,
3197 ip=ip,
3198 staff_only=staff_only,
3199 max_id=max_id,
3200 min_id=min_id,
3201 since_id=since_id
3202 )
3203
3204 @api_version("2.9.1", "2.9.1", __DICT_VERSION_ADMIN_ACCOUNT)
3205 def admin_accounts_v1(self, remote=False, by_domain=None, status='active', username=None, display_name=None, email=None, ip=None, staff_only=False, max_id=None, min_id=None, since_id=None, limit=None):
3206 """
3136 Fetches a list of accounts that match given criteria. By default, local accounts are returned. 3207 Fetches a list of accounts that match given criteria. By default, local accounts are returned.
3137 3208
3138 * Set `remote` to True to get remote accounts, otherwise local accounts are returned (default: local accounts) 3209 * Set `remote` to True to get remote accounts, otherwise local accounts are returned (default: local accounts)
@@ -3147,6 +3218,8 @@ class Mastodon:
3147 Note that setting the boolean parameters to False does not mean "give me users to which this does not apply" but 3218 Note that setting the boolean parameters to False does not mean "give me users to which this does not apply" but
3148 instead means "I do not care if users have this attribute". 3219 instead means "I do not care if users have this attribute".
3149 3220
3221 Deprecated in Mastodon version 3.5.0.
3222
3150 Returns a list of `admin account dicts`_. 3223 Returns a list of `admin account dicts`_.
3151 """ 3224 """
3152 if max_id is not None: 3225 if max_id is not None:
@@ -3158,14 +3231,12 @@ class Mastodon:
3158 if since_id is not None: 3231 if since_id is not None:
3159 since_id = self.__unpack_id(since_id, dateconv=True) 3232 since_id = self.__unpack_id(since_id, dateconv=True)
3160 3233
3161 params = self.__generate_params( 3234 params = self.__generate_params(locals(), ['remote', 'status', 'staff_only'])
3162 locals(), ['remote', 'status', 'staff_only'])
3163 3235
3164 if remote: 3236 if remote:
3165 params["remote"] = True 3237 params["remote"] = True
3166 3238
3167 mod_statuses = ["active", "pending", 3239 mod_statuses = ["active", "pending", "disabled", "silenced", "suspended"]
3168 "disabled", "silenced", "suspended"]
3169 if not status in mod_statuses: 3240 if not status in mod_statuses:
3170 raise ValueError("Invalid moderation status requested.") 3241 raise ValueError("Invalid moderation status requested.")
3171 3242
@@ -3176,6 +3247,9 @@ class Mastodon:
3176 if status == mod_status: 3247 if status == mod_status:
3177 params[status] = True 3248 params[status] = True
3178 3249
3250 if not by_domain is None:
3251 by_domain = self.__deprotocolize(by_domain)
3252
3179 return self.__api_request('GET', '/api/v1/admin/accounts', params) 3253 return self.__api_request('GET', '/api/v1/admin/accounts', params)
3180 3254
3181 @api_version("2.9.1", "2.9.1", __DICT_VERSION_ADMIN_ACCOUNT) 3255 @api_version("2.9.1", "2.9.1", __DICT_VERSION_ADMIN_ACCOUNT)
Powered by cgit v1.2.3 (git 2.41.0)