Created
February 16, 2024 07:30
-
-
Save GrapeApple0/2aff023a0a5baec237bc13ec86cda8f3 to your computer and use it in GitHub Desktop.
AutoSpamFilter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| SERVER = "対象インスタンス" | |
| TOKEN = "トークン" | |
| FILTER_WORDS = ["吹き飛ばしたいワード","てすとほげほげ"] | |
| notes = [] | |
| untilId = "" | |
| ban_host = [] | |
| for filter_word in FILTER_WORDS: | |
| while True: | |
| param = {'query': filter_word, 'limit': 10, 'i': TOKEN} | |
| if untilId != "": | |
| param = {'query': filter_word, 'limit': 10, 'i': TOKEN, 'untilId': untilId} | |
| try: | |
| res = requests.post(f'https://{SERVER}/api/notes/search', | |
| headers={'Content-Type': 'application/json'}, | |
| json=param, timeout=10).json() | |
| except: | |
| break | |
| notes += res | |
| if len(res) == 0: | |
| print("No more notes.") | |
| break | |
| else: | |
| print(f"Found {len(notes)} notes.") | |
| untilId = res[(len(res) - 1)]["id"] | |
| for note in res: | |
| text = str(note['text'][:10]).replace('\n', ' ') | |
| print(f"{note['user']['username']} said: {text}") | |
| print(f"until: {untilId}") | |
| if len(res) < 10: | |
| break | |
| print(f"Found {len(notes)} notes.") | |
| for note in notes: | |
| requests.post(f'https://{SERVER}/api/notes/delete', | |
| headers={'Content-Type': 'application/json'}, | |
| json={'noteId': note['id'], 'i': TOKEN}, timeout=10) | |
| print(f"Deleted {note['id']}") | |
| requests.post(f'https://{SERVER}/api/admin/suspend-user', | |
| headers={'Content-Type': 'application/json'}, | |
| json={'userId': note['userId'], 'i': TOKEN}, timeout=10) | |
| print(f"Suspended {note['userId']}") | |
| ban_host.append(note['user']["host"]) | |
| ban_host = list(set(ban_host)) | |
| meta = requests.post(f'https://{SERVER}/api/admin/meta', | |
| headers={'Content-Type': 'application/json'}, | |
| json={'i': TOKEN}, timeout=10).json() | |
| blocked_hosts = meta['blockedHosts'] | |
| blocked_hosts.extend(ban_host) | |
| requests.post(f'https://{SERVER}/api/admin/update-meta', | |
| headers={'Content-Type': 'application/json'}, | |
| json={'blockedHosts': blocked_hosts, 'i': TOKEN}, timeout=10) | |
| print(f"Suspended {ban_host}") | |
| print(f"Deleted {len(notes)} notes.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment