🗝
summary refs log tree commit diff
path: root/conf_mia.py
blob: 9eb0e08c104fb56597a169165241d45b49e98a48 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import math
from datetime import UTC, datetime, timedelta

from com import FilterableNote, Visibility, FilterAction
from sec import connect, tokens

user_id = "9gf2ev4ex5dflllo"
token = tokens["mia"]
api = "https://void.rehab/api"
early_exit = 0xFFF

now = datetime.now(UTC)
threshold = 2.0

def criteria(root: FilterableNote) -> FilterAction:
    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
            return FilterAction.Ignore

    # 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):
        return FilterAction.Ignore

    # get my...
    most_recent_post = max(thread_self, key=lambda note: note.when) # ...most recent post...
    score = lambda note: note.reactions + note.renotes*5 + 1
    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
    if weighted_score < threshold:
        if any(map(
            lambda note: note.visibility in [Visibility.public, Visibility.unlisted] or note.cw,
            thread_self,
        )):
            return FilterAction.Obliterate
        else:
            return FilterAction.Delete
    else:
        return FilterAction.Ignore