Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 3
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
Exemplo n.º 4
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