scrubber/conf_mia.py

56 lines
2 KiB
Python
Raw Permalink Normal View History

2024-09-04 05:47:13 -06:00
import math
from datetime import UTC, datetime, timedelta
2024-10-04 16:43:40 -06:00
from com import FilterableNote, Visibility, FilterAction
2024-09-04 05:47:13 -06:00
from sec import connect, tokens
user_id = "9gf2ev4ex5dflllo"
token = tokens["mia"]
2024-10-04 16:43:40 -06:00
api = "https://void.rehab/api"
2024-09-04 05:47:13 -06:00
early_exit = 0xFFF
now = datetime.now(UTC)
2024-11-20 07:52:59 -07:00
threshold = 2.0
2024-09-04 05:47:13 -06:00
2024-10-04 16:43:40 -06:00
def criteria(root: FilterableNote) -> FilterAction:
2024-09-04 05:47:13 -06:00
thread = root.thread()
thread_self = root.thread_self()
# if there are dms involved...
low_vis = min(thread, key=lambda note: note.visibility.value)
if low_vis.visibility == Visibility.direct:
is_direct = lambda note: note.visibility == Visibility.direct
most_recent_direct = max(filter(is_direct, thread), key=lambda note: note.when)
# ...and the dms are younger than two months...
if now - most_recent_direct.when < timedelta(days=30 * 2):
# ...do not delete the thread
2024-10-04 16:43:40 -06:00
return FilterAction.Ignore
2024-09-04 05:47:13 -06:00
# get the most recent post...
others_recency = max(thread, key=lambda note: note.when)
# ...and bail if it's too new
if now - others_recency.when < timedelta(days=14):
2024-10-04 16:43:40 -06:00
return FilterAction.Ignore
2024-09-04 05:47:13 -06:00
# get my...
most_recent_post = max(thread_self, key=lambda note: note.when) # ...most recent post...
2024-11-20 07:52:59 -07:00
score = lambda note: note.reactions + note.renotes*5 + 1
2024-09-04 05:47:13 -06:00
high_score_post = max(thread_self, key=score) # ...highest scoring post...
# ...and their values...
most_recent = most_recent_post.when
most_recent_age = now - most_recent
high_score = score(high_score_post)
# ...weigh it...
weighted_score = high_score / math.sqrt(most_recent_age.days)
# ...and check it against a threshold
2024-10-04 16:43:40 -06:00
if weighted_score < threshold:
if any(map(
2024-11-20 07:52:59 -07:00
lambda note: note.visibility in [Visibility.public, Visibility.unlisted] or note.cw,
2024-10-04 16:43:40 -06:00
thread_self,
)):
return FilterAction.Obliterate
else:
return FilterAction.Delete
else:
return FilterAction.Ignore