-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
executable file
·149 lines (129 loc) · 6.79 KB
/
main.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#--- Official /r/MurderedByWords bot by /u/jackson1442 ---#
# This bot is now licensed with the MIT license. See the licensefile for more
# details. See more cool stuff with extremely specific applications at
# github.com/jackson1442
import praw, time, ConfigParser
Config = ConfigParser.ConfigParser()
print(Config.read("botconfig.ini"))
nextline = "\n\n"
def getstring(section):
dict1 = {}
options = Config.options(section)
for option in options:
try:
dict1[option] = Config.get(section, option)
if dict1[option] == -1:
DebugPrint("skip: %s" % option)
except:
print("exception on %s!" % option)
dict1[option] = None
return dict1
accountName = Config.get("basics", 'account name')
# import kdapi
r = praw.Reddit(accountName, user_agent="trying this garbage again")
# poltags = ['[pol]', '[political]', '[politics]', '[politician]']
def uniqid():
return hex(int(time.time()*10000000))[2:17]
currentSubreddit = Config.get("basics", 'subreddit')
print(currentSubreddit)
logsub = Config.get("logging", 'logsub')
scoreA = Config.getint("flairing", "flair a")
scoreB = Config.getint("flairing", "flair b")
removeB = Config.getint("flairing", "remove b")
removeA = Config.getint("flairing", "remove a")
commentText = Config.get("basics", 'autocomment').decode("string-escape")
commentA = commentText + Config.get("flairing", 'flair success a').decode("string-escape")
commentB = commentText + Config.get("flairing", 'flair success b').decode("string-escape")
nameA = Config.get("flairing", 'flair a name')
classA = Config.get("flairing", 'flair a class')
nameB = Config.get("flairing", 'flair b name')
classB = Config.get("flairing", 'flair b class')
footer = Config.get("basics", 'footer').decode("string-escape") + '\n\n^bot ^by ^jackson1442 ^| ^[faq](https://jackson1442.github.io/flairbot/#faq) ^| ^[source](https://github.com/jackson1442/redditBot) ^| ^action ^#'
notice1 = Config.get("notices", 'message 1').decode("string-escape")
notice2 = Config.get("notices", 'message 2').decode("string-escape")
override = Config.getboolean("flairing", "override")
overrideClassA = Config.get("flairing", "override class a")
overrideClassB = Config.get("flairing", "override class b")
if time.time() < Config.getint("notices", "timestamp 1"):
specialNotice = notice1
else:
specialNotice = ""
if time.time() < Config.getint("notices", "timestamp 2"):
specialNotice += notice2
f = open("logfile.txt", "a+")
#--- comment on new posts, hide from /new ---#
for p in r.subreddit(currentSubreddit).new():
actionID = uniqid()
lp = r.subreddit(logsub).submit(actionID + ' - Commented on post "' + p.title[:50] + '"', url='https://reddit.com' + p.permalink)
lp.mod.lock()
if time.time() - p.created_utc > 86400: break
c = p.reply(commentText + specialNotice + footer + '['+actionID+']('+lp.permalink+')')
c.mod.distinguish(how='yes', sticky=True)
c.save()
p.hide()
print('Commented on post id ' + p.id)
f.write('\nCommented on post ' + p.permalink + ' - ' + actionID)
c.clear_vote()
lp.mod.approve()
#--- check for unapproved posts ---#
if Config.getboolean("approval", "required") == 'yes':
for u in r.subreddit(currentSubreddit).mod.unmoderated():
if u.score > Config.getint("approval", "threshold"):
link = u.permalink
author = str(u.author)
actionID = uniqid()
lp = r.subreddit(logsub).submit(actionID + ' - Temporarily removed post "' + u.title[:50] + '"', url='https://reddit.com' + u.permalink)
lp.mod.lock()
tempRemovalMessage = Config.get("approval", 'comment')
r.subreddit(currentSubreddit).modmail.create('Post temporarily removed', tempRemovalMessage + footer + '['+actionID+']('+lp.permalink+')', str(u.author))
c = u.reply(tempRemovalMessage + footer + '['+actionID+']('+lp.permalink+')')
c.mod.distinguish(how='yes', sticky=True)
u.mod.remove()
u.report("Temporarily removed due to upvotes with no approval. Please verify.")
print('temporarily removed post ' + u.permalink)
f.write('\nRemoved post ' + u.permalink + ' temporarily for review - ' + actionID)
lp.mod.approve()
time.sleep(10)
#--- Sort through previously made comments, flair/edit accordingly. ---#
for c in r.redditor(accountName).saved():
currentComment = c.body.split('#')[0]
actionID = uniqid()
print(c.parent().permalink)
if time.time() - c.created_utc > 423000:
c.parent().mod.flair(text=nameB, css_class=classB)
c.parent().mod.approve()
print('removed comment id ' + c.permalink + ' because of oldeness')
r.subreddit(logsub).submit(actionID + ' - Flaired post "' + c.parent().title[:50] + '" as ' + nameB + ' (auto-old)', url='https://reddit.com' + c.parent().permalink).mod.lock()
c.delete()
continue
if c.stickied != True: c.delete(); continue
if c.author != accountName: continue
if c.parent().author == '[deleted]': c.delete(); continue
if c.score > scoreA:
if currentComment != commentA + specialNotice + footer[:-1]:
lp = r.subreddit(logsub).submit(actionID + ' - Flaired post "' + c.parent().title[:50] + '"... as ' + nameA, url='https://reddit.com' + c.parent().permalink)
lp.mod.lock()
c.edit(commentA + specialNotice + footer + '['+actionID+']('+lp.permalink+')')
print('edited comment ' + c.permalink)
c.parent().mod.flair(text=nameA, css_class=classA)
f.write('\nFlaired post ' + c.parent().permalink + ' as ' + nameA + ' - ' + actionID)
lp.mod.approve()
if c.score > removeA: c.delete()
elif c.score < scoreB:
if currentComment != commentB + specialNotice + footer[:-1]:
lp = r.subreddit(logsub).submit(actionID + ' - Flaired post "' + c.parent().title[:50] + '"... as ' + nameB, url='https://reddit.com' + c.parent().permalink)
lp.mod.lock()
c.edit(commentB + specialNotice + footer + '['+actionID+']('+lp.permalink+')')
print('edited comment id ' + c.permalink)
c.parent().mod.flair(text=nameB, css_class=classB);
f.write('\nFlaired post ' + c.parent().permalink + ' as ' + nameB + ' - ' + actionID)
lp.mod.approve()
if (c.score < removeB) and Config.getboolean("flairing", "report"):
c.parent().report(Config.get("flairing", 'reason') + actionID)
f.write('\nReported post ' + c.parent().permalink + ' as potential low quality - ' + actionID)
r.subreddit(logsub).submit(actionID + ' - Reported post "' + c.parent().title[:50] + '" as potential LQ', url='https://reddit.com' + c.parent().permalink).mod.lock()
c.delete()
else: continue
print(c.parent().permalink)
f.close()
exit()