This repository has been archived by the owner on Apr 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
entriesadder.py
52 lines (39 loc) · 1.5 KB
/
entriesadder.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
import logging
from pokestarfansloggingsetup import setup_logger
from modules.entrylogin import reddit
logger = setup_logger('usersubblocker')
def write_to_user_file(text):
with open('blockusers.txt', 'a') as file:
file.write(text)
def write_to_sub_file(text):
with open('blockedsubs.txt', 'a') as file:
file.write(text)
def strip_message(message):
try:
if message.subject == 'remove subreddit':
subreddit = reddit.subreddit(message)
mod = False
for moderator in reddit.subreddit(subreddit).moderator():
if str(message.author) == str(moderator):
mod = True
break
if mod:
write_to_sub_file(message.body)
else:
message.reply('You are not a moderator of the subreddit so your request has not been preformed.')
elif message.subject == 'remove user':
if str(message.author) == message.body:
write_to_user_file(message.body)
else:
message.reply('You are not the OP of the submission so your request has not been preformed.')
except Exception:
logging.warning('', exc_info=True)
def check_for_messages(reddit):
try:
for message in reddit.inbox.unread(mark_read=True):
strip_message(message)
reddit.inbox.mark_read(message)
except Exception:
logging.error('error!', exc_info=True)
while True:
check_for_messages(reddit)