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_delete_request(self, message):
        """ 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. """

        try:
            comment_url = message.body[1:message.body.find("}")]
            comment = self.r.get_submission(comment_url)
        except:
            try:
                message.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.exceptions.ConnectionError:
                pass
            return

        if message.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 = reply.permalink[24:comment.permalink.
                                               find("/", 24)]
                        database.remove_invalid_statistics(reply.body, link)
                        database.decrement_comment_count()
                        reply.delete()
                        self.log.info("%s's comment has been deleted." %
                                      comment.author)
                        try:
                            message.reply(
                                "%s's response to [your comment](%s) has been deleted. "
                                "Sorry for any inconvenience!" %
                                (REDDIT_USERNAME, comment_url))
                        except requests.exceptions.ConnectionError:
                            pass
                        break
                    except:
                        self.log.warning(
                            "Comment deletion failed. Will try again later...")
Example #4
0
    def respond_to_delete_request(self, message):
        """ 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. """

        try:
            comment_url = message.body[1:message.body.find("}")]
            comment = self.r.get_submission(comment_url)
        except:
            try:
                message.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.exceptions.ConnectionError:
                pass
            return

        if message.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 = reply.permalink[24:comment.permalink.find("/", 24)]
                        database.remove_invalid_statistics(reply.body, link)
                        database.decrement_comment_count()
                        reply.delete()
                        self.log.info("%s's comment has been deleted." % comment.author)
                        try:
                            message.reply("%s's response to [your comment](%s) has been deleted. "
                                "Sorry for any inconvenience!" % (REDDIT_USERNAME, comment_url))
                        except requests.exceptions.ConnectionError:
                            pass
                        break
                    except:
                        self.log.warning("Comment deletion failed. Will try again later...")