def test_process_override_not_moderator(mock_clean_id, mock_process_done):
    # for use with anything that requires a reply object

    config = Dict({'no_gifs': ['asdf', 'qwer'], 'tor_mods': ["asdf"]})
    with patch('tor.helpers.reddit_ids.clean_id'):
        process_override(message(), reddit, tor, config)

    message.reply.assert_called_once()
    assert mock_process_done.call_count == 0
Exemple #2
0
def process_reply(reply, config):
    # noinspection PyUnresolvedReferences
    try:
        if any([regex.search(reply.body) for regex in MOD_SUPPORT_PHRASES]):
            process_mod_intervention(reply, config)
            reply.mark_read()
            return

        r_body = reply.body.lower()  # cache that thing

        if 'i accept' in r_body:
            process_coc(reply, config)
            reply.mark_read()
            return

        if 'claim' in r_body:
            process_claim(reply, config)
            reply.mark_read()
            return

        if ('done' in r_body or 'deno' in r_body  # we <3 u/Lornescri
            ):
            alt_text = True if 'done' not in r_body else False
            process_done(reply, config, alt_text_trigger=alt_text)
            reply.mark_read()
            return

        if 'thank' in r_body:  # trigger on "thanks" and "thank you"
            process_thanks(reply, config)
            reply.mark_read()
            return

        if '!override' in r_body:
            process_override(reply, config)
            reply.mark_read()
            return

        # If we made it this far, it's something we can't process automatically
        forward_to_slack(reply, config)
        reply.mark_read()  # no spamming the slack channel :)

    except (RedditClientException, AttributeError) as e:
        logging.warning(e)
        logging.warning(
            f"Unable to process comment {reply.submission.shortlink} "
            f"by {reply.author}")
        # the only way we should hit this is if somebody comments and then
        # deletes their comment before the bot finished processing. It's
        # uncommon, but common enough that this is necessary.
        pass
def test_process_override_not_moderator2(mock_process_done, asd):
    # for use with anything that requires a reply object

    config = Object()
    config.no_gifs = ['asdf', 'qwer']
    config.tor_mods = ['asdf']
    config.r = reddit
    config.tor = tor
    with patch('tor_core.helpers.clean_id'):
        # pytest.set_trace()
        process_override(message(), config)

    message.reply.assert_called_once()
    mock_process_done.assert_called_once()
Exemple #4
0
def process_reply(reply, config):
    # noinspection PyUnresolvedReferences
    try:
        if any([regex.search(reply.body) for regex in MOD_SUPPORT_PHRASES]):
            process_mod_intervention(reply, config)
            reply.mark_read()
            return

        if 'i accept' in reply.body.lower():
            process_coc(reply, config)
            reply.mark_read()
            return

        if 'claim' in reply.body.lower():
            process_claim(reply, config)
            reply.mark_read()
            return

        if 'done' in reply.body.lower():
            process_done(reply, config)
            reply.mark_read()
            return

        if 'thank' in reply.body.lower():  # trigger on "thanks" and "thank you"
            process_thanks(reply, config)
            reply.mark_read()
            return

        if '!override' in reply.body.lower():
            process_override(reply, config)
            reply.mark_read()
            return

        # If we made it this far, it's something we can't process automatically
        forward_to_slack(reply, config)
        reply.mark_read()  # no spamming the slack channel :)

    except (AttributeError, RedditClientException):
        # the only way we should hit this is if somebody comments and then
        # deletes their comment before the bot finished processing. It's
        # uncommon, but common enough that this is necessary.
        pass
Exemple #5
0
                                                 submission, cfg)
            elif check_for_phrase(r_body, CLAIM_PHRASES):
                message, flair = process_claim(username, blossom_submission,
                                               cfg)
            elif check_for_phrase(r_body, DONE_PHRASES):
                alt_text = "done" not in r_body
                message, flair = process_done(
                    reply.author,
                    blossom_submission,
                    reply,
                    cfg,
                    alt_text_trigger=alt_text,
                )
            elif "!override" in r_body:
                message, flair = process_override(reply.author,
                                                  blossom_submission,
                                                  reply.parent_id, cfg)
            elif "!debug" in r_body:
                message, flair = process_debug(reply.author,
                                               blossom_submission, cfg)
            else:
                # If we made it this far, it's something we can't process automatically
                forward_to_slack(reply, cfg)
        if message:
            send_reddit_reply(reply, message)
        if flair:
            flair_post(reply.submission, flair)

    except (ClientException, AttributeError) as e:
        # the only way we should hit this is if somebody comments and then
        # deletes their comment before the bot finished processing. It's
def check_inbox(config):
    """
    Goes through all the unread messages in the inbox. It has two
    loops within this section, each one dealing with a different type
    of mail. Also deliberately leaves mail which does not fit into
    either category so that it can be read manually at a later point.

    The first loop handles username mentions.
    The second loop sorts out and handles comments that include 'claim'
        and 'done'.
    :return: None.
    """
    # Sort inbox, then act on it
    mentions = []
    replies = []
    # grab all of our messages and filter
    for item in config.r.inbox.unread(limit=None):
        if item.author.name == 'transcribot':
            item.mark_read()
            continue
        if item.subject == 'username mention':
            mentions.append(item)
            item.mark_read()
        if item.subject == 'comment reply':
            replies.append(item)
            # we don't mark as read here so that any comments that are not
            # ones we're looking for will eventually get emailed to me as
            # things I need to look at
        if 'reload' in item.subject.lower():
            item.mark_read()
            reload_config(item, config)
            item.reply('Config reloaded!')
            continue
        if 'update' in item.subject.lower():
            item.mark_read()
            update_and_restart(item, config)
            # there's no reason to do anything else here because the process
            # will terminate and respawn

        # ARE YOU ALIVE?!
        if item.subject.lower() == 'ping':
            item.mark_read()
            item.reply('Pong!')

    # sort them and create posts where necessary
    for mention in mentions:
        logging.info('Received mention! ID {}'.format(mention))

        if not is_valid(mention.parent_id, config):
            # Do our check here to make sure we can actually work on this one and
            # that we haven't already posted about it. We use the full ID here
            # instead of the cleaned one, just in case.
            logging.info(id_already_handled_in_db.format(mention.parent_id))
            continue

        # noinspection PyUnresolvedReferences
        try:
            process_mention(mention, config)
        except (AttributeError, praw.exceptions.ClientException):
            # apparently this crashes with an AttributeError if someone calls
            # the bot and immediately deletes their comment. This should fix
            # that.
            continue

    # comment replies
    for reply in replies:
        # noinspection PyUnresolvedReferences
        try:
            if 'i accept' in reply.body.lower():
                process_coc(reply, config)
                reply.mark_read()
                return

            if 'claim' in reply.body.lower():
                process_claim(reply, config)
                reply.mark_read()
                return

            if 'done' in reply.body.lower():
                process_done(reply, config)
                reply.mark_read()
                return

            if '!override' in reply.body.lower():
                process_override(reply, config)
                reply.mark_read()
                return

        except (AttributeError, praw.exceptions.ClientException):
            # the only way we should hit this is if somebody comments and then
            # deletes their comment before the bot finished processing. It's
            # uncommon, but common enough that this is necessary.
            continue