This repository has been archived by the owner on Dec 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
archiver.py
83 lines (66 loc) · 2.69 KB
/
archiver.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#! /usr/bin/python3
"""
Functioning as intended. Don't modify. (Future self note.)
... immediately followed by me modifying it... super
"""
import os
import sys
import praw
import time
import random
from datetime import datetime
# Rename your archiverconfig.py to arconfig.py so we can import yours.
try:
import arconfig as arcon
# That way, the config can be freely edited by the developer, and won't wipe the user's current settings.
except:
import archiverconfig as arcon
class ModBot:
def __init__(self, site):
self.reddit = praw.Reddit(site)
self.subreddit = self.reddit.subreddit(self.reddit.config.custom['subreddit'])
def archive(self):
users = arcon.INCLUDE
msgs = {value:key for key, value in users.items()}
for k,v in users.items():
if v is None:
users.update({k:random.choice(arcon.RANMSG)})
conversations = self.subreddit.modmail.conversations()
for conv in conversations:
usernames = []
for author in conv.authors:
if author not in usernames:
usernames.append(author)
for user in users:
if user in usernames and conv.unread:
conv = self.subreddit.modmail(conv.id)
r = False
m = False
a = False
# Had issues with these if modmail conversation isn't brand new and untouched.
# So, try each action, and just carry on if something happens. Not very elegant, but hey
try:
conv.reply(users[user])
r = True
except:
pass
try:
conv.mute()
m = True
except:
pass
try:
conv.archive()
a = True
except:
pass
# Had issues with replying, muting and archiving a modmail conversation that has been opened/something/idk
# Therefore, rather than print 3 messages per action like before, just deliver a report based on what went through
report = f"Found: {user.lower()} | Replied to? {r} | Muted? {m} | Archived? {a}"
print(report)
with open(arcon.LOG, "a") as f:
time_now = time.time()
f.write(f"{datetime.fromtimestamp(time_now)} / ({time_now}): {report}\n")
break
if __name__ == '__main__':
ModBot(arcon.AR).archive()