33
44import praw
55import prawcore
6+ from markdowntable import Table as ta
67from pokestarfansloggingsetup import setup_logger
78
89from modules .login import reddit
9- from modules .table import starter
1010
1111logger = setup_logger ('duplicates' )
1212
1313
1414# noinspection PyBroadException
1515def generate_and_reply (submission ):
16- footer = '\n \n ----\n \n ^^I ^^am ^^a ^^bot ^^[FAQ](https://www.reddit.com/r/DuplicatesBot/wiki/index)-[' \
17- 'Code](https://github.com/PokestarFan/DuplicateBot)-[Bugs](' \
16+ starter = ta ('Title' )
17+ starter .all_columns ('Subreddit' , 'Author' , 'Time' , 'Karma' )
18+ footer = '\n \n ----\n \n I am a bot [FAQ](https://www.reddit.com/r/DuplicatesBot/wiki/index)-[' \
19+ 'Code](https://github.com/PokestarFan/DuplicateBot)-[Bugs](' \
1820 'https://www.reddit.com/r/DuplicatesBot/comments/6ypgmx/bugs_and_problems/)-[Suggestions](' \
1921 'https://www.reddit.com/r/DuplicatesBot/comments/6ypg85/suggestion_for_duplicatesbot/)-[Block ' \
2022 'user (op only)' \
@@ -23,7 +25,7 @@ def generate_and_reply(submission):
2325 '={user})-[Block from subreddit (mods only)](' \
2426 'https://www.reddit.com/message/compose/?to=DuplicatesBotBlocker&subject=remove%20subreddit' \
2527 '&message={sub})\n ' \
26- ' \n ^^Now ^^ you ^^ can ^^ remove ^^ the ^^ comment ^^ by ^^ replying ^^ delete! ' .format (user =
28+ ' \n Now you can remove the comment by replying delete! ' .format (user =
2729 str (
2830 submission .author ), sub = str (submission .subreddit ))
2931 global message
@@ -36,7 +38,7 @@ def generate_and_reply(submission):
3638 if str (submission .author ) == author :
3739 author = author + ' [author of both threads]'
3840 duplicates .append (['[{}]({})' .format (str (dup_sub .title ), 'https://www.reddit.com' + str (dup_sub .permalink )),
39- str (dup_sub .subreddit ), author , str (time ), str (dup_sub .score )])
41+ '/r/' + str (dup_sub .subreddit ), author , str (time ), str (dup_sub .score )])
4042 if len (duplicates ) > 0 :
4143 message = 'Here is a list of threads in other subreddits about the same content:\n '
4244 for dup in duplicates :
@@ -45,28 +47,24 @@ def generate_and_reply(submission):
4547 message += '\n ' + footer
4648 try :
4749 submission .reply (message )
48- logger .info ('Message posted on {}' .format (sub_id ))
50+ logger .info ('Message posted on {}' .format (str ( submission ) ))
4951 logger .debug ('Message: {}' .format (message ))
50- message = ''
51- except praw .exceptions .APIException :
52+ except (praw .exceptions .APIException , UnboundLocalError ):
5253 logger .debug ('Submission {} has been skipped due to missing text.' .format (sub_id ))
53- message = ''
5454 except prawcore .exceptions .Forbidden :
5555 logger .debug ('You are blocked on /r/{}' .format (str (submission .subreddit )))
56- message = ''
5756 except AssertionError :
5857 logger .debug ('Assertion Error occured! Printing message and traceback.' )
5958 logger .debug (message + str (len (message )), exc_info = True )
60- message = ''
6159 except (KeyboardInterrupt , SystemExit ):
6260 raise
6361 except Exception :
6462 logger .error ('Error occurred!' , exc_info = True )
65- message = ''
6663 except :
6764 logger .critical (
6865 'Massive Error occurred! Not part of the Exception, KeyboardInterrupt or SystemExit exceptions. Fix ASAP.' ,
6966 exc_info = True )
67+ finally :
7068 message = ''
7169
7270
0 commit comments