@handle_api_exceptions()
def process_unread(new, r):
    """Parse a new comment or message for various options and ignore reply
    to as appropriate.
    """
    reply = None
    sender = new.author
    log("New {type} {id} from {sender}".format(
        type="mention" if new.was_comment else "message",
        id=new.id, sender=sender))
    if sender.name.lower() in BANNED_USERS:
        log("Ignoring banned user {user}".format(user=sender))
        return
    # Search for a user mention preceded by a '+' which is the signal
    # for CompileBot to create a reply for that comment.
    if (new.was_comment and
        re.search(r'(?i)\+/u/{}'.format(R_USERNAME), new.body)):
        reply = create_reply(new)
        if reply:
            reply.send(new)
    elif ((not new.was_comment) and
          re.match(r'(i?)\s*--help', new.body)):
        # Message a user the help text if comment is a message
        # containing "--help".
        reply = MessageReply(HELP_TEXT, subject='CompileBot Help')
        reply.send(new)
    elif ((not new.was_comment) and
          re.match(r'(i?)\s*--report', new.body) and SUBREDDIT):
        # Forward a reported message to the moderators.
        send_modmail("Report from {author}".format(author=new.author),
                     new.body, r)
        reply = MessageReply("Your message has been forwarded to the "
                             "moderators. Thank you.",
                             subject="CompileBot Report")
        reply.send(new)
    elif ((not new.was_comment) and
          re.match(r'(i?)\s*--recompile', new.body)):
        # Search for the recompile command followed by a comment id.
        # Example: 1tt4jt/post_title/ceb7czt
        # The comment id can optionally be prefixed by a url.
        # Example: reddit.com/r/sub/comments/1tt4jt/post_title/ceb7czt
        p = (r'(i?)--recompile\s*(?P<url>[^\s*]+)?'
             r'(?P<id>\b\w+/\w+/\w+\b)')
        m = re.search(p, new.body)
        try:
            id = m.group('id')
        except AttributeError:
            new.reply(RECOMPILE_ERROR_TEXT)
            return
        # Fetch the comment that will be recompiled.
        sub = r.get_submission(submission_id=id, comment_sort='best')
        try:
            original = sub.comments[0]
        except IndexError:
            # In case the comment is deleted
            return
        log("Processing request to recompile {id} from {user}"
            "".format(id=original.id, user=new.author))
        # Ensure the author of the original comment matches the author
        # requesting the recompile to prevent one user sending a recompile
        # request on the behalf of another.
        if original.author == new.author:
            reply = create_reply(original)
        else:
            new.reply(RECOMPILE_AUTHOR_ERROR_TEXT)
            log("Attempt to reompile on behalf of another author "
                "detected. Request deined.")
            return
        # Ensure the recompiled reply resulted in a valid comment
        # reply and not an error message reply.
        if isinstance(reply, CompiledReply):
            # Search for an existing comment reply from the bot.
            # If one is found, edit the existing comment instead
            # of creating a new one.
            #
            # Note: the .replies property only returns a limited
            # number of comments. If the reply is buried, it will
            # not be retrieved and a new one will be created
            for rp in original.replies:
                if rp.author.name.lower() == R_USERNAME.lower():
                    footnote = ("\n\n**EDIT:** Recompile request "
                                "by {}".format(new.author))
                    reply.text += footnote
                    reply.make_edit(rp, original)
                    break
            else:
                # Reply to the original comment.
                reply.send(original)
        else:
            # Send a message reply.
            reply.send(new)
    if reply and isinstance(reply, CompiledReply):
        # Report any potential spam to the moderators.
        spam = reply.detect_spam()
        if spam and reply.parent_comment.subreddit.display_name not in IGNORE_SPAM:
            text = ("Potential spam detected on comment {c.permalink} "
                    "by {c.author}: ".format(c=reply.parent_comment))
            text += ', '.join(spam)
            send_modmail("Potential spam detected", text, r)
            log(text)
dataset/ETHPy150Open renfredxh/compilebot/compilebot/compilebot.py/process_unread/original