Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit 39870b6

Browse files
author
PokestarFan
committed
Push new files and changes
1 parent 7983307 commit 39870b6

File tree

4 files changed

+76
-31
lines changed

4 files changed

+76
-31
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,4 @@ login.py
107107
blockusers.txt
108108
posts_written_to.txt
109109
writes.txt
110+
replies.txt

delete.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import praw
2+
from login import reddit
3+
4+
5+
def main(limit, count=0):
6+
for comment in r.redditor(str(user)).comments.new(limit=limit):
7+
comment.delete()
8+
count = count + 1
9+
print('Finished comment #'+str(count))
10+
11+
if __name__ == '__main__':
12+
limit = input('How many recent comments to delete? Type None for all comments')
13+
count = 0
14+
main(limit, count)
15+
print('Complete')

duplicate.py

+33-31
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,55 @@
1-
import re
1+
import datetime
22
import praw
33
from login import reddit
44

55
def action():
66
for sub_id in reddit.subreddit('all').stream.submissions():
77
blockeduser = 0
8-
item_written_to = 0
9-
for item in reddit.inbox.unread(limit=None):
8+
for item in reddit.inbox.messages(limit=5):
109
if str(item.subject) == 'Remove me from posts':
1110
body = str(item.body)
12-
yes = re.search('\/u\/[a-zA-Z0-9]+',body)
13-
username = yes.group(0)
14-
if str(item.author) == username:
15-
with open('blockedusers.txt', 'a') as file:
11+
with open('blockusers.txt', 'a+') as file:
12+
if str(item.author) == body and body not in file.read():
1613
newstring = username.replace(r'/u/','')
14+
newstring = newstring = '\n'
1715
file.write(newstring)
18-
with open('posts_written_to.txt','r') as writefile:
19-
for id_to_use in writefile.readlines():
20-
if item_written_to == 0:
21-
if sub_id == id_to_use:
22-
item_written_to = 1
2316
duplicates = []
2417
submission = praw.models.Submission(reddit, id = sub_id)
2518
with open('blockusers.txt','r') as newfile:
2619
for line in newfile.readlines():
27-
if submission.author == line and blockeduser == 0:
28-
pass
29-
else:
20+
line = line.strip('\n')
21+
if str(submission.author) == line:
3022
blockeduser = 1
31-
if blockeduser == 0 and item_written_to == 0:
23+
else:
24+
pass
25+
if blockeduser == 0:
3226
for duplicate in submission.duplicates():
3327
dup_sub = praw.models.Submission(reddit, id = duplicate)
34-
duplicates.append({'title':str(dup_sub.title), 'subreddit':str(dup_sub.subreddit), 'link':str(
35-
dup_sub.shortlink)})
36-
if len(duplicates) > 0:
37-
message = 'Here is a list of threads in other subreddits about the same content:\n'
38-
for dup in duplicates:
39-
message = str(message + '\n # [{}]({}) on /r/{}').format(dup['title'], dup['link'], dup['subreddit'])
40-
message = message + '\n\n ---- \n\n ^^I^^am^^a^^bot^^[FAQ](https://www.reddit.com/r/DuplicatesBot/wiki/index)-[Code](https://github.com/PokestarFan/DuplicateBot-[Bugs](https://www.reddit.com/r/DuplicatesBot/comments/6ypgmx/bugs_and_problems/)-[Suggestions](https://www.reddit.com/r/DuplicatesBot/comments/6ypg85/suggestion_for_duplicatesbot/)-[How to block](https://www.reddit.com/r/DuplicatesBot/wiki/index#wiki_block_bot_from_tagging_on_your_posts'
28+
if 'ImagesOf' not in str(dup_sub.subreddit) and 'auto' not in str(dup_sub.subreddit):
29+
time = dup_sub.created
30+
time = str(datetime.datetime.fromtimestamp(time))
31+
author = str(dup_sub.author)
32+
if str(submission.author) == author:
33+
author = author + '[author of both threads]'
34+
duplicates.append({'title':str(dup_sub.title), 'subreddit':str(dup_sub.subreddit), 'link':'https://www.reddit.com'+str(dup_sub.permalink), 'time':str(time), 'author':author})
35+
if len(duplicates) > 0:
36+
message = 'Here is a list of threads in other subreddits about the same content:\n'
37+
for dup in duplicates:
38+
message = str(message + '\n * [{}]({}) on /r/{} (created at {} by {})').format(dup['title'], dup['link'], dup['subreddit'], dup['time'], dup['author'])
39+
message = message + '\n\n ---- \n\n ^^I ^^am ^^a ^^bot ^^[FAQ](https://www.reddit.com/r/DuplicatesBot/wiki/index)-[Code](https://github.com/PokestarFan/DuplicateBot-[Bugs](https://www.reddit.com/r/DuplicatesBot/comments/6ypgmx/bugs_and_problems/)-[Suggestions](https://www.reddit.com/r/DuplicatesBot/comments/6ypg85/suggestion_for_duplicatesbot/)-[Block](https://www.reddit.com/r/DuplicatesBot/wiki/index#wiki_block_bot_from_tagging_on_your_posts)'
4140
try:
4241
submission.reply(message)
43-
with open('writes.log', 'a') as logfile:
44-
logfile.write('Replied to submission id {}'.format(sub_id))
45-
print('Replied to submission id {}'.format(sub_id))
46-
with open('posts_written_to.txt','a') as writefile2:
47-
writefile2.write(sub_id)
48-
except(UnboundLocalError):
42+
message = ''
43+
except:
4944
pass
50-
45+
message = ''
46+
5147

5248
if __name__ == '__main__':
53-
action()
49+
while True:
50+
try:
51+
action()
52+
except(KeyboardInterrupt):
53+
raise KeyboardInterrupt
54+
except:
55+
pass

goodbadbot.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import time
2+
import praw
3+
from login import reddit
4+
5+
6+
def main():
7+
while True:
8+
for item in reddit.inbox.all(limit=5):
9+
with open('replies.txt', 'r') as readfile:
10+
for line in readfile.readlines():
11+
if line == item:
12+
pass
13+
else:
14+
try:
15+
if 'good' and 'bot' in item.body:
16+
item.reply('Good human')
17+
with open('replies.txt', 'a') as file:
18+
file.write(str(item)+'\n')
19+
elif 'bad' and 'bot' in item.body:
20+
item.reply('bad human')
21+
with open('replies.txt', 'a') as file:
22+
file.write(str(item)+'\n')
23+
except:
24+
pass
25+
26+
if __name__ == '__main__':
27+
main()

0 commit comments

Comments
 (0)