Beispiel #1
0
    def respond_to_user_trans_request(self, msg):
        """ 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.

        :param msg: Message containing user translation defaults
        """

        ot_trans, nt_trans, deut_trans = find_default_trans(msg.body)
        if None not in (ot_trans, nt_trans, deut_trans):
            if (database.is_valid_trans(ot_trans, "Old Testament")
                    and database.is_valid_trans(nt_trans, "New Testament")
                    and database.is_valid_trans(deut_trans, "Deuterocanon")):
                database.update_user_trans(str(msg.author), ot_trans, nt_trans,
                                           deut_trans)
                self.log.info("Updated default translations for %s." %
                              msg.author)
                try:
                    msg.reply("Your default translations have "
                              "been updated successfully!")
                except requests.ConnectionError:
                    pass
            else:
                try:
                    msg.reply("One or more of your translation choices "
                              "is invalid. Please review your choices "
                              "and try again.")
                except requests.ConnectionError:
                    pass
        else:
            try:
                msg.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.ConnectionError:
                pass
Beispiel #2
0
    def respond_to_user_trans_request(self, msg):
        """ 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.

        :param msg: Message containing user translation defaults
        """

        ot_trans, nt_trans, deut_trans = find_default_trans(msg.body)
        if None not in (ot_trans, nt_trans, deut_trans):
            if (database.is_valid_trans(ot_trans, "Old Testament") and
                    database.is_valid_trans(nt_trans, "New Testament") and
                    database.is_valid_trans(deut_trans, "Deuterocanon")):
                database.update_user_trans(str(msg.author), ot_trans,
                                           nt_trans, deut_trans)
                self.log.info("Updated default translations for %s."
                              % msg.author)
                try:
                    msg.reply("Your default translations have "
                              "been updated successfully!")
                except requests.ConnectionError:
                    pass
            else:
                try:
                    msg.reply("One or more of your translation choices "
                              "is invalid. Please review your choices "
                              "and try again.")
                except requests.ConnectionError:
                    pass
        else:
            try:
                msg.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.ConnectionError:
                pass
Beispiel #3
0
    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_trans(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 = ""
Beispiel #4
0
    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_trans(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 = ""
Beispiel #5
0
    def respond_to_subreddit_trans_request(self, msg):
        """ 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.

        :param msg: Message containing subreddit translation defaults
        """

        subreddit = find_subreddit_in_request(msg.body)
        try:
            if msg.author in self.r.get_moderators(subreddit):
                ot_trans, nt_trans, deut_trans = find_default_trans(msg.body)
                if None not in (ot_trans, nt_trans, deut_trans):
                    if (database.is_valid_trans(ot_trans, "Old Testament")
                            and database.is_valid_trans(
                                nt_trans, "New Testament")
                            and database.is_valid_trans(
                                deut_trans, "Deuterocanon")):
                        database.update_subreddit_trans(
                            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(msg.author), ot_trans,
                                 nt_trans, deut_trans))
                        except requests.ConnectionError:
                            pass
                    else:
                        try:
                            msg.reply("One or more of your translation "
                                      "choices is invalid. Please review your "
                                      "choices and try again.")
                        except requests.ConnectionError:
                            pass
                else:
                    try:
                        msg.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.ConnectionError:
                        pass
        except praw.errors.HTTPException as err:
            if str(err) == "404 Client Error: Not Found":
                try:
                    msg.reply("The subreddit you entered (/r/%s) "
                              "does not exist or is private." % subreddit)
                except requests.ConnectionError:
                    pass
        except praw.errors.RedirectException:
            try:
                msg.reply("The subreddit you entered (/r/%s) does "
                          "not exist or is private." % subreddit)
            except requests.ConnectionError:
                pass
Beispiel #6
0
    def respond_to_subreddit_trans_request(self, msg):
        """ 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.

        :param msg: Message containing subreddit translation defaults
        """

        subreddit = find_subreddit_in_request(msg.body)
        try:
            if msg.author in self.r.get_moderators(subreddit):
                ot_trans, nt_trans, deut_trans = find_default_trans(msg.body)
                if None not in (ot_trans, nt_trans, deut_trans):
                    if (database.is_valid_trans(ot_trans, "Old Testament") and
                            database.is_valid_trans(nt_trans,
                                                    "New Testament") and
                            database.is_valid_trans(deut_trans,
                                                    "Deuterocanon")):
                        database.update_subreddit_trans(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(msg.author),
                                   ot_trans, nt_trans, deut_trans))
                        except requests.ConnectionError:
                            pass
                    else:
                        try:
                            msg.reply("One or more of your translation "
                                      "choices is invalid. Please review your "
                                      "choices and try again.")
                        except requests.ConnectionError:
                            pass
                else:
                    try:
                        msg.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.ConnectionError:
                        pass
        except praw.errors.HTTPException as err:
            if str(err) == "404 Client Error: Not Found":
                try:
                    msg.reply("The subreddit you entered (/r/%s) "
                              "does not exist or is private." % subreddit)
                except requests.ConnectionError:
                    pass
        except praw.errors.RedirectException:
            try:
                msg.reply("The subreddit you entered (/r/%s) does "
                          "not exist or is private." % subreddit)
            except requests.ConnectionError:
                pass