Skip to content

Instantly share code, notes, and snippets.

@GrapeApple0
Created February 16, 2024 08:35
Show Gist options
  • Select an option

  • Save GrapeApple0/a93bb6bae3747f0e1423d79167b3cd2a to your computer and use it in GitHub Desktop.

Select an option

Save GrapeApple0/a93bb6bae3747f0e1423d79167b3cd2a to your computer and use it in GitHub Desktop.
AutoSpamBan
import requests
import re
import datetime
SERVER = "対象インスタンス"
TOKEN = "トークン"
meta = requests.post(f'https://{SERVER}/api/admin/meta',
headers={'Content-Type': 'application/json'},
json={'i': TOKEN}, timeout=10).json()
BANNED_SERVER = meta['blockedHosts']
ban_user_list = []
ban_username_list = []
for server in BANNED_SERVER:
offset = 0
now = datetime.datetime.now()
while True:
param = {
'limit': 10,
'offset': offset,
'sort': '+createdAt',
'origin': 'remote',
'hostname': server,
'state': 'available',
'i': TOKEN
}
try:
res = requests.post(f"https://{SERVER}/api/admin/show-users",
headers={'Content-Type': 'application/json'},
json=param, timeout=30).json()
except:
break
for user in res:
if re.compile(r"[0-9a-z]{10}").match(user["username"]) is not None and len(user["username"]) == 10:
dt = datetime.datetime.strptime(user["createdAt"], '%Y-%m-%dT%H:%M:%S.%fZ')
if datetime.datetime.today() - dt < datetime.timedelta(days=1):
print(f"@{user['username']}@{user['host']}")
ban_user_list.append(user["id"])
ban_username_list.append(user["username"])
offset += 10
if len(res) < 10:
break
print(f"Found {len(ban_user_list)} users.")
for user in ban_user_list:
requests.post(f'https://{SERVER}/api/admin/suspend-user',
headers={'Content-Type': 'application/json'},
json={'userId': user, 'i': TOKEN}, timeout=10)
print(f"Suspended {user}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment