Browse Source

add rejection functionality

master
mark 8 months ago
parent
commit
7c44fa95a4
2 changed files with 25 additions and 6 deletions
  1. +24
    -1
      autoreject.py
  2. +1
    -5
      test.py

+ 24
- 1
autoreject.py View File

@@ -5,6 +5,7 @@ import hashlib

import html2text
import requests
from mastodon import Mastodon # type: ignore

Comparison = Enum("Comparison", "GT GE LT LE EQ NE TRUE")

@@ -48,7 +49,7 @@ DEFAULT_AVATAR_HASHES = [
"de7b5ead3476d53f3b943779699b7fa0" # Pleroma's avi.png
]

def check_criteria(user_dict: dict, criteria_settings: dict):
def check_criteria(user_dict: dict, criteria_settings: dict) -> list:
"""
Check an account against criteria for auto-rejection.

@@ -93,3 +94,25 @@ def check_criteria(user_dict: dict, criteria_settings: dict):
rejected_criteria.append(key)
return rejected_criteria

def reject_follows(masto: Mastodon, criteria: dict):
"""
Performs automatic follow request rejection based on a set of criteria.

Arguments:
masto - an instance of mastodon.py's Mastodon class that is logged into an account in some way
criteria - a dict containing the criteria to test on
"""
follow_requests = masto.follow_requests()

rejections = []

for req in follow_requests:
rejected_on = check_criteria(req, criteria)
if rejected_on:
masto.follow_request_reject(req['id'])
req['rejected_on'] = rejected_on
rejections.append(req)
return rejections

+ 1
- 5
test.py View File

@@ -23,8 +23,4 @@ criteria = {
"no_bots": True
}

follow_requests = masto.follow_requests()

for req in follow_requests:
rejected_on = autoreject.check_criteria(req, criteria)
print(f"@{req['acct']}: {rejected_on}")
autoreject.reject_follows(masto, criteria)

Loading…
Cancel
Save