def process_remind_me(message, reddit, database, recurring): log.info("Processing RemindMe message") trigger = static.TRIGGER_RECURRING_LOWER if recurring else static.TRIGGER_LOWER time = utils.find_reminder_time(message.body, trigger) message_text = utils.find_reminder_message(message.body, trigger) reminder, result_message = Reminder.build_reminder( source=utils.message_link(message.id), message=message_text, user=database.get_or_add_user(message.author.name), requested_date=utils.datetime_from_timestamp(message.created_utc), time_string=time, recurring=recurring) if reminder is None: log.debug("Reminder not valid, returning") return [result_message], False database.add_reminder(reminder) database.commit() log.info( f"Reminder created: {reminder.id} : {utils.get_datetime_string(reminder.target_date)}" ) bldr = reminder.render_message_confirmation( result_message, pushshift_minutes=reddit.get_effective_pushshift_lag()) return [''.join(bldr)], True
def parse_comment(comment, database, count_string, reddit): if comment['author'] == static.ACCOUNT_NAME: log.debug("Comment is from remindmebot") return None, None if comment['author'] in static.BLACKLISTED_ACCOUNTS: log.debug("Comment is from a blacklisted account") return None, None log.info( f"{count_string}: Processing comment {comment['id']} from u/{comment['author']}" ) body = comment['body'].lower().strip() recurring = False cakeday = False allow_default = True if trigger_in_text(body, static.TRIGGER_RECURRING_LOWER): log.debug("Recurring reminder comment") recurring = True trigger = static.TRIGGER_RECURRING_LOWER elif trigger_in_text(body, static.TRIGGER_LOWER): log.debug("Regular comment") trigger = static.TRIGGER_LOWER elif trigger_start_of_line(body, static.TRIGGER_CAKEDAY_LOWER): log.debug("Cakeday comment") cakeday = True recurring = True trigger = static.TRIGGER_CAKEDAY_LOWER elif trigger_start_of_line(body, static.TRIGGER_SPLIT_LOWER): log.debug("Regular split comment") trigger = static.TRIGGER_SPLIT_LOWER allow_default = False else: log.debug("Command not in comment") return None, None target_date = None if cakeday: if database.user_has_cakeday_reminder(comment['author']): log.info("Cakeday already exists") return None, None target_date = utils.get_next_anniversary( reddit.get_user_creation_date(comment['author'])) message_text = static.CAKEDAY_MESSAGE time = "1 year" else: time = utils.find_reminder_time(comment['body'], trigger) message_text = utils.find_reminder_message(comment['body'], trigger) reminder, result_message = Reminder.build_reminder( source=utils.reddit_link(comment['permalink']), message=message_text, user=database.get_or_add_user(comment['author']), requested_date=utils.datetime_from_timestamp(comment['created_utc']), time_string=time, recurring=recurring, target_date=target_date, allow_default=allow_default) if reminder is None: return None, None if cakeday: counters.replies.labels(source='comment', type='cake').inc() elif recurring: counters.replies.labels(source='comment', type='repeat').inc() elif not allow_default: counters.replies.labels(source='comment', type='split').inc() else: counters.replies.labels(source='comment', type='single').inc() database.add_reminder(reminder) reminder.user.recurring_sent = 0 return reminder, result_message