Example #1
0
def process_cakeday_message(message, reddit, database):
    log.info("Processing cakeday")

    if database.user_has_cakeday_reminder(message.author.name):
        log.info("Cakeday already exists")
        return ["It looks like you already have a cakeday reminder set."
                ], False

    next_anniversary = utils.get_next_anniversary(message.author.created_utc)

    reminder = Reminder(source=utils.message_link(message.id),
                        message=static.CAKEDAY_MESSAGE,
                        user=database.get_or_add_user(message.author.name),
                        requested_date=utils.datetime_from_timestamp(
                            message.created_utc),
                        target_date=next_anniversary,
                        recurrence="1 year",
                        defaulted=False)

    database.add_reminder(reminder)
    database.commit()

    log.info(
        f"Cakeday reminder created: {reminder.id} : {utils.get_datetime_string(reminder.target_date)}"
    )

    bldr = reminder.render_message_confirmation(
        None, pushshift_minutes=reddit.get_effective_pushshift_lag())
    return [''.join(bldr)], True
Example #2
0
def process_remind_me(message, database):
    log.info("Processing RemindMe message")
    time = utils.find_reminder_time(message.body)

    message_text = utils.find_reminder_message(message.body)

    reminder = Reminder(
        source=utils.message_link(message.id),
        message=message_text,
        user=message.author.name,
        requested_date=utils.datetime_from_timestamp(message.created_utc),
        time_string=time,
        timezone=database.get_settings(message.author.name).timezone)
    if not reminder.valid:
        log.debug("Reminder not valid, returning")
        return [reminder.result_message]

    if not database.save_reminder(reminder):
        log.info("Something went wrong saving the reminder")
        return ["Something went wrong saving the reminder"]

    log.info(
        f"Reminder created: {reminder.db_id} : {utils.get_datetime_string(reminder.target_date)}"
    )

    return reminder.render_message_confirmation()