1
+ import re
2
+ import praw
3
+ from login import reddit
4
+
5
+ def action ():
6
+ for sub_id in reddit .subreddit ('all' ).stream .submissions ():
7
+ blockeduser = 0
8
+ item_written_to = 0
9
+ for item in reddit .inbox .unread (limit = None ):
10
+ if str (item .subject ) == 'Remove me from posts' :
11
+ 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 :
16
+ newstring = username .replace (r'/u/' ,'' )
17
+ 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
23
+ duplicates = []
24
+ submission = praw .models .Submission (reddit , id = sub_id )
25
+ with open ('blockusers.txt' ,'r' ) as newfile :
26
+ for line in newfile .readlines ():
27
+ if submission .author == line and blockeduser == 0 :
28
+ pass
29
+ else :
30
+ blockeduser = 1
31
+ if blockeduser == 0 and item_written_to == 0 :
32
+ for duplicate in submission .duplicates ():
33
+ 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'
41
+ try :
42
+ 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 ):
49
+ pass
50
+
51
+
52
+ if __name__ == '__main__' :
53
+ action ()
0 commit comments