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 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
message = i18n["responses"]["general"]["getting_help"] elif "thank" in r_body: # trigger on "thanks" and "thank you" thumbs_up_gifs = i18n["urls"]["thumbs_up_gifs"] youre_welcome = i18n["responses"]["general"]["youre_welcome"] message = youre_welcome.format(random.choice(thumbs_up_gifs)) else: submission = reply.submission username = reply.author.name if submission.author.name not in __BOT_NAMES__: log.debug( "Received 'command' on post we do not own. Ignoring.") return blossom_submission = get_blossom_submission(submission, cfg) if "i accept" in r_body: message, flair = process_coc(username, reply.context, blossom_submission, cfg) elif check_for_phrase(r_body, UNCLAIM_PHRASES): message, flair = process_unclaim(username, blossom_submission, 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, )
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