aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'mastodon')
-rw-r--r--mastodon/Mastodon.py178
1 files changed, 173 insertions, 5 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index 6f84b27..78f8b85 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -167,11 +167,20 @@ class Mastodon:
167 'write:blocks', 167 'write:blocks',
168 'write:follows', 168 'write:follows',
169 'write:mutes', 169 'write:mutes',
170 ] 170 ],
171 'admin:read': [
172 'admin:read:accounts',
173 'admin:read:reports',
174 ],
175 'admin:write': [
176 'admin:write:accounts',
177 'admin:write:reports',
178 ],
171 } 179 }
172 __VALID_SCOPES = ['read', 'write', 'follow', 'push'] + __SCOPE_SETS['read'] + __SCOPE_SETS['write'] 180 __VALID_SCOPES = ['read', 'write', 'follow', 'push', 'admin:read', 'admin:write'] + \
181 __SCOPE_SETS['read'] + __SCOPE_SETS['write'] + __SCOPE_SETS['admin:read'] + __SCOPE_SETS['admin:write']
173 182
174 __SUPPORTED_MASTODON_VERSION = "2.8.4" 183 __SUPPORTED_MASTODON_VERSION = "2.9.2"
175 184
176 # Dict versions 185 # Dict versions
177 __DICT_VERSION_APPLICATION = "2.7.2" 186 __DICT_VERSION_APPLICATION = "2.7.2"
@@ -593,7 +602,7 @@ class Mastodon:
593 602
594 Activity is returned for 12 weeks going back from the current week. 603 Activity is returned for 12 weeks going back from the current week.
595 604
596 Returns a list `activity dicts`_. 605 Returns a list of `activity dicts`_.
597 """ 606 """
598 return self.__api_request('GET', '/api/v1/instance/activity') 607 return self.__api_request('GET', '/api/v1/instance/activity')
599 608
@@ -2318,7 +2327,166 @@ class Mastodon:
2318 """ 2327 """
2319 self.__api_request('DELETE', '/api/v1/push/subscription') 2328 self.__api_request('DELETE', '/api/v1/push/subscription')
2320 2329
2321 2330 ###
2331 # Moderation API
2332 ###
2333 @api_version("2.9.1", "2.9.1", "2.9.1")
2334 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):
2335 """
2336 Fetches a list of accounts that match given criteria. By default, local accounts are returned.
2337
2338 Set `remote` to True to get remote accounts, otherwise local accounts are returned (default: local accounts)
2339 Set `by_domain` to a domain to get only accounts from that domain.
2340 Set `status` to one of "active", "pending", "disabled", "silenced" or "suspended" to get only accounts with that moderation status (default: active)
2341 Set `username` to a string to get only accounts whose username contains this string.
2342 Set `display_name` to a string to get only accounts whose display name contains this string.
2343 Set `email` to an email to get only accounts with that email (this only works on local accounts).
2344 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).
2345 Set `staff_only` to True to only get staff accounts (this only works on local accounts).
2346
2347 Note that setting the boolean parameters to False does not mean "give me users to which this does not apply" but
2348 instead means "I do not care if users have this attribute".
2349
2350 Returns a list of `admin account dicts`_.
2351 """
2352 if max_id != None:
2353 max_id = self.__unpack_id(max_id)
2354
2355 if min_id != None:
2356 min_id = self.__unpack_id(min_id)
2357
2358 if since_id != None:
2359 since_id = self.__unpack_id(since_id)
2360
2361 params = self.__generate_params(locals(), ['remote', 'status', 'staff_only'])
2362
2363 if remote == True:
2364 params["remote"] = True
2365
2366 mod_statuses = ["active", "pending", "disabled", "silenced", "suspended"]
2367 if not status in mod_statuses:
2368 raise ValueError("Invalid moderation status requested.")
2369
2370 if staff_only == True:
2371 params["staff"] = True
2372
2373 for mod_status in mod_statuses:
2374 if status == mod_status:
2375 params[status] = True
2376
2377 return self.__api_request('GET', '/api/v1/admin/accounts', params)
2378
2379 def admin_account(self, id):
2380 """
2381 Fetches a single `admin account dict`_ for the user with the given id.
2382
2383 Returns that dict.
2384 """
2385 id = self.__unpack_id(id)
2386 return self.__api_request('GET', '/api/v1/admin/accounts/{0}'.format(id))
2387
2388 def admin_account_enable(self, id):
2389 """
2390 Reenables login for a local account for which login has been disabled.
2391
2392 Returns the updated `admin account dict`_.
2393 """
2394 id = self.__unpack_id(id)
2395 return self.__api_request('POST', '/api/v1/admin/accounts/{0}/enable'.format(id))
2396
2397 def admin_account_approve(self, id):
2398 """
2399 Approves a pending account.
2400
2401 Returns the updated `admin account dict`_.
2402 """
2403 id = self.__unpack_id(id)
2404 return self.__api_request('POST', '/api/v1/admin/accounts/{0}/approve'.format(id))
2405
2406 def admin_account_reject(self, id):
2407 """
2408 Rejects and deletes a pending account.
2409
2410 Returns the updated `admin account dict`_ for the account that is now gone.
2411 """
2412 id = self.__unpack_id(id)
2413 return self.__api_request('POST', '/api/v1/admin/accounts/{0}/reject'.format(id))
2414
2415 def admin_account_unsilence(self, id):
2416 """
2417 Unsilences an account.
2418
2419 Returns the updated `admin account dict`_.
2420 """
2421 id = self.__unpack_id(id)
2422 return self.__api_request('POST', '/api/v1/admin/accounts/{0}/unsilence'.format(id))
2423
2424 def admin_account_unsuspend(self, id):
2425 """
2426 Unsuspends an account.
2427
2428 Returns the updated `admin account dict`_.
2429 """
2430 id = self.__unpack_id(id)
2431 return self.__api_request('POST', '/api/v1/admin/accounts/{0}/unsuspend'.format(id))
2432
2433 def admin_account_moderate(self, id, action=None, report_id=None, warning_preset_id=None, text=None, send_email_notification=True):
2434 """
2435 Perform a moderation action on an account.
2436
2437 Valid actions are:
2438 * "disable" - for a local user, disable login.
2439 * "silence" - hide the users posts from all public timelines.
2440 * "suspend" - irreversibly delete all the users posts, past and future.
2441 If no action is specified, the user is only issued a warning.
2442
2443 Specify the id of a report as `report_id` to close the report with this moderation action as the resolution.
2444 Specify `warning_preset_id` to use a warning preset as the notification text to the user, or `text` to specify text directly.
2445 If both are specified, they are concatenated (preset first). Note that there is currently no API to retrieve or create
2446 warning presets.
2447
2448 Set `send_email_notification` to False to not send the user an e-mail notification informing them of the moderation action.
2449 """
2450 if action is None:
2451 action = "none"
2452
2453 if send_email_notification == False:
2454 send_email_notification = None
2455
2456 id = self.__unpack_id(id)
2457 if not report_id is None:
2458 report_id = self.__unpack_id(report_id)
2459
2460 params = self.__generate_params(locals(), ['id', 'action'])
2461
2462 params["type"] = action
2463
2464 self.__api_request('POST', '/api/v1/admin/accounts/{0}/action'.format(id), params)
2465
2466 def admin_reports(self, resolved, account_id, target_account_id):
2467 pass
2468 #GET /api/v1/admin/reports Get reports, with params resolved, account_id, target_account_id
2469
2470 def admin_report(self, id):
2471 pass
2472 #GET /api/v1/admin/reports/:id Get a specific report
2473
2474 def admin_report_assign(self, id):
2475 pass
2476 #POST /api/v1/admin/reports/:id/assign_to_self Assign report to self
2477
2478 def admin_report_unassign(self, id):
2479 pass
2480 #POST /api/v1/admin/reports/:id/unassign Unassign report from self
2481
2482 def admin_report_reopen(self, id):
2483 pass
2484 #POST /api/v1/admin/reports/:id/reopen Re-open report
2485
2486 def admin_report_resolve(self, id):
2487 pass
2488 #POST /api/v1/admin/reports/:id/resolve Close report
2489
2322 ### 2490 ###
2323 # Push subscription crypto utilities 2491 # Push subscription crypto utilities
2324 ### 2492 ###
Powered by cgit v1.2.3 (git 2.41.0)