def respond_to_user_translation_request(self, message): """ Responds to a user's default translation request. The bot will parse the message which contains the desired translations, and will check them against the database to make sure they are valid. If they are valid, the bot will respond with a confirmation message and add the defaults to the user_translations table. If not valid, the bot will respond with an error message. """ ot_trans, nt_trans, deut_trans = find_default_translations(message.body) if None not in (ot_trans, nt_trans, deut_trans): if (database.is_valid_translation(ot_trans, "Old Testament") and database.is_valid_translation(nt_trans, "New Testament") and database.is_valid_translation(deut_trans, "Deuterocanon")): database.update_user_translation(str(message.author), ot_trans, nt_trans, deut_trans) self.log.info("Updated default translations for %s." % message.author) try: message.reply("Your default translations have been updated successfully!") except requests.exceptions.ConnectionError: pass else: try: message.reply("One or more of your translation choices is invalid. Please review your choices" " and try again.") except requests.exceptions.ConnectionError: pass else: try: message.reply("Your default translation request does not match the required format. Please do not edit" " the message after generating it from the website.") except requests.exceptions.ConnectionError: pass
def respond_to_subreddit_translation_request(self, message): """ Responds to a subreddit's default translation request. The bot will parse the message which contains the desired translations, and will check them against the database to make sure they are valid. If they are valid, the bot will respond with a confirmation message and add the defaults to the subreddit_translations table. If not valid, the bot will respond with an error message. """ subreddit = find_subreddit_in_request(message.body) try: if message.author in self.r.get_moderators(subreddit): ot_trans, nt_trans, deut_trans = find_default_translations(message.body) if None not in (ot_trans, nt_trans, deut_trans): if (database.is_valid_translation(ot_trans, "Old Testament") and database.is_valid_translation(nt_trans, "New Testament") and database.is_valid_translation(deut_trans, "Deuterocanon")): database.update_subreddit_translation(subreddit, ot_trans, nt_trans, deut_trans) self.log.info("Updated default translations for /r/%s." % subreddit) try: self.r.send_message("/r/%s" % subreddit, "/r/%s Default Translation Change Confirmation" % subreddit, "The default /u/%s translation for this subreddit has been changed by /u/%s to the following:\n\n" "Old Testament: %s\nNew Testament: %s\nDeuterocanon: %s\n\nIf this is a mistake," " please [click here](http://matthieugrieger.com/versebot#subreddit-translation-default)" " to submit a new request." % (REDDIT_USERNAME, str(message.author), ot_trans, nt_trans, deut_trans)) except requests.exceptions.ConnectionError: pass else: try: message.reply("One or more of your translation choices is invalid. Please review your choices" " and try again.") except requests.exceptions.ConnectionError: pass else: try: message.reply("Your default translation request does not match the required format. Please do not edit" " the message after generating it from the website.") except requests.exceptions.ConnectionError: pass except requests.exceptions.HTTPError as err: if str(err) == "404 Client Error: Not Found": try: message.reply("The subreddit you entered (/r/%s) does not exist or is private." % subreddit) except requests.exceptions.ConnectionError: pass except praw.errors.RedirectException: try: message.reply("The subreddit you entered (/r/%s) does not exist or is private." % subreddit) except requests.exceptions.ConnectionError: pass
def respond_to_user_translation_request(self, message): """ Responds to a user's default translation request. The bot will parse the message which contains the desired translations, and will check them against the database to make sure they are valid. If they are valid, the bot will respond with a confirmation message and add the defaults to the user_translations table. If not valid, the bot will respond with an error message. """ ot_trans, nt_trans, deut_trans = find_default_translations( message.body) if None not in (ot_trans, nt_trans, deut_trans): if (database.is_valid_translation(ot_trans, "Old Testament") and database.is_valid_translation(nt_trans, "New Testament") and database.is_valid_translation(deut_trans, "Deuterocanon")): database.update_user_translation(str(message.author), ot_trans, nt_trans, deut_trans) self.log.info("Updated default translations for %s." % message.author) try: message.reply( "Your default translations have been updated successfully!" ) except requests.exceptions.ConnectionError: pass else: try: message.reply( "One or more of your translation choices is invalid. Please review your choices" " and try again.") except requests.exceptions.ConnectionError: pass else: try: message.reply( "Your default translation request does not match the required format. Please do not edit" " the message after generating it from the website.") except requests.exceptions.ConnectionError: pass
def __init__(self, book, chapter, translation, user, subreddit, verse): """ Initializes a Verse object with book, chapter, verse (if exists), and translation (if exists). """ self.book = book self.subreddit = subreddit.lower() book_num = books.get_book_number(self.book) if book_num <= 39: self.bible_section = "Old Testament" elif book_num <= 66: self.bible_section = "New Testament" else: self.bible_section = "Deuterocanon" self.chapter = int(chapter.replace(" ", "")) if verse != "": self.verse = verse.replace(" ", "") if "-" in self.verse: start_verse, end_verse = self.verse.split("-") if end_verse != "" and int(start_verse) > int(end_verse): self.verse = None elif end_verse == "" or int(start_verse) == int(end_verse): self.verse = start_verse end_verse = int(start_verse) self.start_verse = int(start_verse) self.end_verse = int(end_verse) else: self.start_verse = int(self.verse) self.end_verse = self.start_verse else: self.verse = None self.start_verse = 0 self.end_verse = 0 if translation != "": trans = translation.upper().replace(" ", "") if database.is_valid_translation(trans, self.bible_section): self.translation = trans else: self.determine_translation(user, subreddit) else: self.determine_translation(user, subreddit) self.translation_title = "" self.contents = "" self.permalink = ""
def respond_to_subreddit_translation_request(self, message): """ Responds to a subreddit's default translation request. The bot will parse the message which contains the desired translations, and will check them against the database to make sure they are valid. If they are valid, the bot will respond with a confirmation message and add the defaults to the subreddit_translations table. If not valid, the bot will respond with an error message. """ subreddit = find_subreddit_in_request(message.body) try: if message.author in self.r.get_moderators(subreddit): ot_trans, nt_trans, deut_trans = find_default_translations( message.body) if None not in (ot_trans, nt_trans, deut_trans): if (database.is_valid_translation(ot_trans, "Old Testament") and database.is_valid_translation( nt_trans, "New Testament") and database.is_valid_translation( deut_trans, "Deuterocanon")): database.update_subreddit_translation( subreddit, ot_trans, nt_trans, deut_trans) self.log.info( "Updated default translations for /r/%s." % subreddit) try: self.r.send_message( "/r/%s" % subreddit, "/r/%s Default Translation Change Confirmation" % subreddit, "The default /u/%s translation for this subreddit has been changed by /u/%s to the following:\n\n" "Old Testament: %s\nNew Testament: %s\nDeuterocanon: %s\n\nIf this is a mistake," " please [click here](http://matthieugrieger.com/versebot#subreddit-translation-default)" " to submit a new request." % (REDDIT_USERNAME, str(message.author), ot_trans, nt_trans, deut_trans)) except requests.exceptions.ConnectionError: pass else: try: message.reply( "One or more of your translation choices is invalid. Please review your choices" " and try again.") except requests.exceptions.ConnectionError: pass else: try: message.reply( "Your default translation request does not match the required format. Please do not edit" " the message after generating it from the website." ) except requests.exceptions.ConnectionError: pass except requests.exceptions.HTTPError as err: if str(err) == "404 Client Error: Not Found": try: message.reply( "The subreddit you entered (/r/%s) does not exist or is private." % subreddit) except requests.exceptions.ConnectionError: pass except praw.errors.RedirectException: try: message.reply( "The subreddit you entered (/r/%s) does not exist or is private." % subreddit) except requests.exceptions.ConnectionError: pass