-
Notifications
You must be signed in to change notification settings - Fork 0
/
submissions.py
39 lines (27 loc) · 1.13 KB
/
submissions.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
import re
import helpers.firebase as database
from helpers.reddit import login
from helpers.data import load_data
import helpers.logger as logger
if __name__ == "__main__":
db = database.Database()
log = logger.Logger(db)
reddit_creds = db.reddit_cred()
reddit = login(reddit_creds)
if reddit:
bot = reddit.user.me()
target_sub, trigger, script, footer = db.info()
subreddit = reddit.subreddit(target_sub)
for submission in subreddit.stream.submissions(skip_existing = True):
title = submission.title
found = re.search(trigger, title, re.IGNORECASE)
# Reply to submission with trigger word included
if found:
# Skip if the submission is in the cache list
if str(submission.id) in db.cache_list():
continue
reply_message = script["en"] + footer
reply_comment = submission.reply(reply_message)
# Cache the submission id
db.add_cache(str(submission.id))
log.log_response("submission", submission.id, reply_comment.id)