Skip to content

Instantly share code, notes, and snippets.

@ShadowJonathan
Last active August 1, 2023 14:01
Show Gist options
  • Save ShadowJonathan/8d1ab5d189292c21693c0732edf6812d to your computer and use it in GitHub Desktop.
Save ShadowJonathan/8d1ab5d189292c21693c0732edf6812d to your computer and use it in GitHub Desktop.
Fix Mastodon Domain Block Lift Glitch
from mastodon import Mastodon
# Create an application, and fill in these parameters with that.
# You should at least have the following permissions;
# - read
# - admin:read
# - admin:read:accounts
# - admin:write
# - admin:write:accounts
mastodon = Mastodon(
client_id="",
client_secret="",
access_token="",
api_base_url="",
)
accounts = {
# Copy-paste the IDs you get from the database queries,
# make sure they're integer primitives that're comma-seperated.
# Like so:
# 123, 234, 231, etc.
}
# Set this to True if you're unsuspending users, set this to False if you're unlimiting/unsilencing users
SUSPENDED = True
# The total amount of accounts, printed first to allow someone to see how far the script is.
print("total: " + len(accounts))
for i, acc in enumerate(accounts):
# Mastodon has ratelimiting on the admin API,
# due to that, your script is gonna look like it stopped working around every 300 accounts or so.
# It will not have finished until the number before the : will have reached the total amount of accounts above.
print(i + ": " + acc))
if SUSPENDED:
mastodon.admin_account_unsuspend(acc)
else:
mastodon.admin_account_unsilence(acc)
-- Select all accounts that have been limited without any corresponding audit log entry,
-- while they should be unlimited per the domain block rules.
-- SELECT id, username, domain, silenced_at, suspended_at, suspension_origin
SELECT id
FROM accounts a
-- Make sure we're selecting limited accounts (silence = limit)
WHERE silenced_at IS NOT NULL
-- Make sure we're selecting remote accounts
AND domain IS NOT NULL
-- Make sure we're selecting accounts that don't have any relevant audit log related to it
AND id NOT IN (SELECT target_id FROM admin_action_logs WHERE action = 'silence' AND target_type = 'Account')
-- Make sure the account's domain isn't still suspended or limited
AND NOT EXISTS
(SELECT 1
FROM domain_blocks db
WHERE (a.domain = db.domain OR a.domain LIKE CONCAT('%', db.domain)) AND db.severity IN (0, 1));
-- Select all accounts that have been suspended without any corresponding audit log entry,
-- while they should be unsuspended per the domain block rules.
-- SELECT id, username, domain, silenced_at, suspended_at, suspension_origin
SELECT id
FROM accounts a
WHERE
-- Make sure we're selecting suspended accounts
suspended_at IS NOT NULL
-- Make sure the remote server did not cause this suspension entry
AND suspension_origin != 1
-- Make sure we're selecting remote accounts
AND domain IS NOT NULL
-- Make sure we're selecting accounts that don't have any relevant audit log related to it
AND id NOT IN (SELECT target_id FROM admin_action_logs WHERE action = 'suspend' AND target_type = 'Account')
-- Make sure the account's domain isn't still suspended.
AND NOT EXISTS
(SELECT 1
FROM domain_blocks db
-- Where the domain either equals, or the domain block is on a higher level domain
-- e.g. 'threadsproxy.facebook.com' LIKE CONCAT('%', 'facebook.com') -- (matches)
WHERE (a.domain = db.domain OR a.domain LIKE CONCAT('%', db.domain))
-- The domain is suspended
AND db.severity = 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment