-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathautoreply.py
More file actions
40 lines (31 loc) · 1.45 KB
/
Copy pathautoreply.py
File metadata and controls
40 lines (31 loc) · 1.45 KB
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
from config import *
import praw
from time import sleep
ooto_message = "Hello, r/cybersecurity is currently participating in a blackout and will not be accessible for 48h. Please monitor https://cybersecurity.page for updates, thanks!"
ooto_subreddit = "cybersecurity"
reddit = praw.Reddit(
client_id=praw_client_id,
client_secret=praw_client_secret,
refresh_token=praw_refresh_token,
user_agent="r-cybersecurity/modmail-autoreply",
)
replied_conversations = []
while True:
try:
subreddit = reddit.subreddit(ooto_subreddit)
for conversations in subreddit.mod.stream.modmail_conversations(state="inbox"):
conversation_id = conversations.id
if conversation_id in replied_conversations:
print(f"Skipped reply to {conversation_id} as autoreply already fired")
continue
# want to do more to analyze or reply? here are the ModmailConversation docs:
# https://praw.readthedocs.io/en/stable/code_overview/models/modmailconversation.html
message = subreddit.modmail(conversation_id, mark_read=True)
message.reply(body=ooto_message, author_hidden=True)
message.archive()
print(f"Replied to {conversation_id} and archived")
replied_conversations.append(conversation_id)
except Exception as e:
print(f"Caught exception: {e}, restarting conversation bus in 10s")
sleep(10)
exit(1)