Example #1
0
    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
Example #2
0
    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
Example #3
0
    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
Example #4
0
    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