Example #1
0
    def respond_to_delete_request(self, msg):
        """ Responds to a delete request. The bot will attempt to open the
        comment which has been requested to be deleted. If the submitter of
        the delete request matches the author of the comment that triggered
        the VerseBot response, the comment will be deleted. The bot will then
        send a message to the user letting them know that their verse
        quotation comment has been removed.

        :param msg: Submitted deletion request
        """
        try:
            comment_url = re.search("\{(.*?)\}", msg.body).group(1)
            comment = self.r.get_submission(comment_url)
        except:
            try:
                msg.reply("An error occurred while processing your deletion "
                          "request. Please make sure that you do not modify "
                          "the subject line of your message to %s." %
                          REDDIT_USERNAME)
            except requests.ConnectionError:
                pass
            return

        if msg.author == comment.author and comment:
            for reply in comment.comments[0].replies:
                if str(reply.author) == REDDIT_USERNAME:
                    try:
                        self.log.info(
                            "%s has requested a comment deletion..." %
                            comment.author)
                        link = re.search("/r/(.*?)/", comment_url).group(1)
                        database.remove_invalid_stats(reply.body, link)
                        database.decrement_comment_count()
                        reply.delete()
                        self.log.info("%s's comment has been deleted." %
                                      comment.author)
                        try:
                            msg.reply("%s's response to [your comment](%s)"
                                      " has been deleted. Sorry for any "
                                      "inconvenience!" %
                                      (REDDIT_USERNAME, comment_url))
                        except requests.ConnectionError:
                            pass
                        break
                    except:
                        self.log.warning("Comment deletion failed. "
                                         "Will try again later...")
Example #2
0
    def respond_to_delete_request(self, msg):
        """ Responds to a delete request. The bot will attempt to open the
        comment which has been requested to be deleted. If the submitter of
        the delete request matches the author of the comment that triggered
        the VerseBot response, the comment will be deleted. The bot will then
        send a message to the user letting them know that their verse
        quotation comment has been removed.

        :param msg: Submitted deletion request
        """
        try:
            comment_url = re.search("\{(.*?)\}", msg.body).group(1)
            comment = self.r.get_submission(comment_url)
        except:
            try:
                msg.reply("An error occurred while processing your deletion "
                          "request. Please make sure that you do not modify "
                          "the subject line of your message to %s."
                          % REDDIT_USERNAME)
            except requests.ConnectionError:
                pass
            return

        if msg.author == comment.author and comment:
            for reply in comment.comments[0].replies:
                if str(reply.author) == REDDIT_USERNAME:
                    try:
                        self.log.info("%s has requested a comment deletion..."
                                      % comment.author)
                        link = re.search("/r/(.*?)/", comment_url).group(1)
                        database.remove_invalid_stats(reply.body, link)
                        database.decrement_comment_count()
                        reply.delete()
                        self.log.info("%s's comment has been deleted."
                                      % comment.author)
                        try:
                            msg.reply("%s's response to [your comment](%s)"
                                      " has been deleted. Sorry for any "
                                      "inconvenience!"
                                      % (REDDIT_USERNAME, comment_url))
                        except requests.ConnectionError:
                            pass
                        break
                    except:
                        self.log.warning("Comment deletion failed. "
                                         "Will try again later...")
Example #3
0
    def respond_to_edit_request(self, msg):
        """ Responds to an edit request. The bot will parse the body of the
        message, looking for verse quotations. These will replace the
        quotations that were placed in the original response to the user.
        Once the comment has been successfully edited, the bot then sends a
        message to the user letting them know that their verse quotations
        have been updated.

        :param msg: The message that contains the edit request
        """
        try:
            comment_url = re.search("\{(.*?)\}", msg.body).group(1)
            comment = self.r.get_submission(comment_url)
        except:
            try:
                msg.reply("An error occurred while processing your edit "
                          "request. Please make sure that you do not modify "
                          "the subject line of your message to %s." %
                          REDDIT_USERNAME)
            except requests.ConnectionError:
                pass
            return

        if msg.author == comment.author and comment:
            verses = find_verses(msg.body)
            if verses is not None:
                for reply in comment.comments[0].replies:
                    if str(reply.author) == REDDIT_USERNAME:
                        try:
                            self.log.info(
                                "%s has requested a comment edit..." %
                                comment.author)
                            sub = re.search("/r/(.*?)/", comment_url).group(1)
                            response = Response(msg, self.parser, comment_url)
                            for verse in verses:
                                book_name = books.get_book(verse[0])
                                if book_name is not None:
                                    v = Verse(
                                        book_name,  # Book
                                        verse[1],  # Chapter
                                        verse[3],  # Translation
                                        msg.author,  # User
                                        sub,  # Subreddit
                                        verse[2])  # Verse
                                    if not response.is_duplicate_verse(v):
                                        response.add_verse(v)
                            if len(response.verse_list) != 0:
                                msg_response = ("*^This ^comment ^has ^been "
                                                "^edited ^by ^%s.*\n\n" %
                                                msg.author)
                                msg_response += response.construct_message()
                                if msg_response is not None:
                                    self.log.info(
                                        "Editing %s's comment with "
                                        "updated verse quotations..." %
                                        msg.author)
                                    database.remove_invalid_stats(
                                        reply.body, sub)
                                    reply.edit(msg_response)
                                    database.update_db_stats(
                                        response.verse_list)
                                    try:
                                        msg.reply(
                                            "[Your triggered %s "
                                            "response](%s) has been "
                                            "successfully edited to "
                                            "reflect your updated "
                                            "quotations." %
                                            (REDDIT_USERNAME, comment_url))
                                    except requests.ConnectionError:
                                        pass
                                    break
                        except:
                            self.log.warning("Comment edit failed. "
                                             "Will try again later...")
Example #4
0
    def respond_to_edit_request(self, msg):
        """ Responds to an edit request. The bot will parse the body of the
        message, looking for verse quotations. These will replace the
        quotations that were placed in the original response to the user.
        Once the comment has been successfully edited, the bot then sends a
        message to the user letting them know that their verse quotations
        have been updated.

        :param msg: The message that contains the edit request
        """
        try:
            comment_url = re.search("\{(.*?)\}", msg.body).group(1)
            comment = self.r.get_submission(comment_url)
        except:
            try:
                msg.reply("An error occurred while processing your edit "
                          "request. Please make sure that you do not modify "
                          "the subject line of your message to %s."
                          % REDDIT_USERNAME)
            except requests.ConnectionError:
                pass
            return

        if msg.author == comment.author and comment:
            verses = find_verses(msg.body)
            if verses is not None:
                for reply in comment.comments[0].replies:
                    if str(reply.author) == REDDIT_USERNAME:
                        try:
                            self.log.info("%s has requested a comment edit..."
                                          % comment.author)
                            sub = re.search("/r/(.*?)/", comment_url).group(1)
                            response = Response(msg, self.parser, comment_url)
                            for verse in verses:
                                book_name = books.get_book(verse[0])
                                if book_name is not None:
                                    v = Verse(book_name,      # Book
                                              verse[1],       # Chapter
                                              verse[3],       # Translation
                                              msg.author,     # User
                                              sub,            # Subreddit
                                              verse[2])       # Verse
                                    if not response.is_duplicate_verse(v):
                                        response.add_verse(v)
                            if len(response.verse_list) != 0:
                                msg_response = ("*^This ^comment ^has ^been "
                                                "^edited ^by ^%s.*\n\n"
                                                % msg.author)
                                msg_response += response.construct_message()
                                if msg_response is not None:
                                    self.log.info("Editing %s's comment with "
                                                  "updated verse quotations..."
                                                  % msg.author)
                                    database.remove_invalid_stats(reply.body,
                                                                  sub)
                                    reply.edit(msg_response)
                                    database.update_db_stats(
                                        response.verse_list)
                                    try:
                                        msg.reply("[Your triggered %s "
                                                  "response](%s) has been "
                                                  "successfully edited to "
                                                  "reflect your updated "
                                                  "quotations."
                                                  % (REDDIT_USERNAME,
                                                     comment_url))
                                    except requests.ConnectionError:
                                        pass
                                    break
                        except:
                            self.log.warning("Comment edit failed. "
                                             "Will try again later...")