def render_notification(self): bldr = utils.str_bldr() bldr.append("RemindMeBot reminder here!") bldr.append("\n\n") if self.message is not None: bldr.append("I'm here to remind you:\n\n> ") bldr.append(self.message) bldr.append("\n\n") bldr.append("The source comment or message:\n\n>") bldr.append(self.source) bldr.append("\n\n") if self.requested_date is None: bldr.append("This reminder was created before I started saving the creation date of reminders.") else: bldr.append("You requested this reminder on: ") bldr.append(utils.render_time(self.requested_date, self.timezone)) bldr.append("\n\n") bldr.append("[Click here](") bldr.append(utils.build_message_link( static.ACCOUNT_NAME, "Reminder", f"[{self.message}]\n\n{static.TRIGGER}! " )) bldr.append(") and set the time after the ") bldr.append(static.TRIGGER) bldr.append(" command to be reminded of the original comment again.") return bldr
def render_comment_confirmation(self): bldr = utils.str_bldr() if self.defaulted: bldr.append("**Defaulted to one day.**\n\n") if self.timezone is not None: bldr.append(f"Your default time zone is set to `{self.timezone}`. ") bldr.append("I will be messaging you on ") bldr.append(utils.render_time(self.target_date, self.timezone)) bldr.append(" to remind you of [**this link**](") bldr.append(utils.replace_np(self.source)) bldr.append(")") bldr.append("\n\n") bldr.append("[**") if self.count_duplicates > 0: bldr.append(str(self.count_duplicates)) bldr.append(" OTHERS CLICKED") else: bldr.append("CLICK") bldr.append(" THIS LINK**](") bldr.append(utils.build_message_link( static.ACCOUNT_NAME, "Reminder", f"[{self.source}]\n\n{static.TRIGGER}! " f"{utils.get_datetime_string(self.target_date, format_string='%Y-%m-%d %H:%M:%S %Z')}" )) bldr.append(") to send a PM to also be reminded and to reduce spam.") if self.thread_id is not None: bldr.append("\n\n") bldr.append("^(Parent commenter can ) [^(delete this message to hide from others.)](") bldr.append(utils.build_message_link( static.ACCOUNT_NAME, "Delete Comment", f"Delete! {self.thread_id}" )) bldr.append(")") return bldr
def render_confirmation(self, timezone): bldr = utils.str_bldr() bldr.append("I will message you every year at ") bldr.append( utils.render_time(self.date_time, timezone, "%m-%d %H:%M:%S %Z")) bldr.append(" to remind you of your cakeday.") bldr.append("\n\n") bldr.append("[Click here](") bldr.append( utils.build_message_link(static.ACCOUNT_NAME, "Delete Cakeday Reminder", "Delete! cakeday")) bldr.append(") to delete this reminder.") return bldr
def get_reminders_string(user_name, database, previous=False, include_all=False): result_messages = [] bldr = utils.str_bldr() regular_reminders, recurring_reminders = database.get_user_reminders( user_name) if len(regular_reminders) or len(recurring_reminders): if previous: bldr.append("Your previous reminders:") else: bldr.append("Your current reminders:") bldr.append("\n\n") if len(regular_reminders) + len(recurring_reminders) > 1: bldr.append("[Click here to delete all your reminders](") bldr.append( utils.build_message_link(static.ACCOUNT_NAME, "Remove All", "RemoveAll!")) bldr.append(")\n\n") user = database.get_or_add_user(user_name) if user.timezone is not None: bldr.append("Your timezone is currently set to: `") bldr.append(user.timezone) bldr.append("`\n\n") for reminders in [recurring_reminders, regular_reminders]: if len(reminders): log.debug(f"Building list with {len(reminders)} reminders") add_list_header(bldr, reminders[0].recurrence is not None) for reminder in reminders: bldr.append("|") if "reddit.com" in reminder.source: bldr.append("[Source](") bldr.append( utils.check_append_context_to_link( reminder.source)) bldr.append(")") else: bldr.append(reminder.source) bldr.append("|") if reminder.message is not None: bldr.append(reminder.message.replace("|", "|")) bldr.append("|") bldr.append( utils.render_time(reminder.target_date, reminder.user)) bldr.append("|") bldr.append( utils.render_time_diff(utils.datetime_now(), reminder.target_date)) if reminder.recurrence is not None: bldr.append("|") bldr.append(reminder.recurrence) bldr.append("|") bldr.append("[Remove](") bldr.append( utils.build_message_link(static.ACCOUNT_NAME, "Remove", f"Remove! {reminder.id}")) bldr.append(")") bldr.append("|\n") if utils.bldr_length(bldr) > 9000: if include_all: result_messages.append(''.join(bldr)) bldr = [] add_list_header( bldr, reminders[0].recurrence is not None) else: bldr.append("\nToo many reminders to display.") break bldr.append("\n") else: bldr.append("You don't have any reminders.") result_messages.append(''.join(bldr)) return result_messages
def render_notification(self): bldr = utils.str_bldr() bldr.append("RemindMeBot reminder here!") bldr.append("\n\n") if self.message is not None: bldr.append("I'm here to remind you:\n\n> ") bldr.append(self.message) bldr.append("\n\n") bldr.append("The source comment or message:\n\n>") bldr.append(utils.check_append_context_to_link(self.source)) bldr.append("\n\n") if self.requested_date is None: bldr.append( "This reminder was created before I started saving the creation date of reminders." ) else: bldr.append("You requested this reminder on: ") bldr.append(utils.render_time(self.requested_date, self.user)) bldr.append("\n\n") if self.recurrence is not None: if self.user.recurring_sent > static.RECURRING_LIMIT: bldr.append("I've sent you at least ") bldr.append(str(static.RECURRING_LIMIT)) bldr.append( " recurring reminders since I last heard from you, so I'm automatically canceling this reminder. " ) bldr.append("[Click here](") bldr.append( utils.build_message_link( static.ACCOUNT_NAME, "ReminderRepeat", f"[{(self.message[:500] if self.message is not None else self.source)}]\n\n{static.TRIGGER_RECURRING}! {self.recurrence}" )) bldr.append(") to recreate it.") else: if self.is_cakeday(): bldr.append("I will message you every year at ") bldr.append( utils.render_time(self.target_date, self.user, "%m-%d %H:%M:%S %Z")) bldr.append(" to remind you of your cakeday.") else: bldr.append( "This is a repeating reminder. I'll message you again in `" ) bldr.append(self.recurrence) bldr.append("`, which is ") bldr.append( utils.render_time( utils.parse_time(self.recurrence, self.target_date, self.user.timezone), self.user)) bldr.append(".") bldr.append("\n\n") bldr.append("[Click here](") bldr.append( utils.build_message_link(static.ACCOUNT_NAME, "Remove", f"Remove! {self.id}")) bldr.append(") to delete this reminder.") else: bldr.append("[Click here](") bldr.append( utils.build_message_link( static.ACCOUNT_NAME, "Reminder", f"[{(self.message[:500] if self.message is not None else self.source)}]\n\n{static.TRIGGER}! " )) bldr.append(") and set the time after the ") bldr.append(static.TRIGGER) bldr.append( " command to be reminded of the original comment again.") return bldr
def render_comment_confirmation(self, thread_id, count_duplicates=0, pushshift_minutes=0): bldr = utils.str_bldr() if pushshift_minutes > 15: bldr.append("There is a ") if pushshift_minutes > 60: bldr.append(str(int(round(pushshift_minutes / 60, 1)))) bldr.append(" hour") else: bldr.append(str(pushshift_minutes)) bldr.append(" minute") bldr.append(" delay fetching comments.") bldr.append("\n\n") if self.defaulted: bldr.append("**Defaulted to one day.**\n\n") if self.user.timezone is not None: bldr.append("Your [default time zone](") bldr.append(static.INFO_POST_SETTINGS) bldr.append(") is set to `") bldr.append(self.user.timezone) bldr.append("`. ") if self.is_cakeday(): bldr.append("I will [message you every year](") bldr.append(static.INFO_POST_CAKEDAY) bldr.append(") at ") bldr.append( utils.render_time(self.target_date, self.user, "%m-%d %H:%M:%S %Z")) bldr.append(" to remind you of your cakeday.") else: if self.defaulted or self.target_date < utils.datetime_now(): bldr.append("I will be messaging you on ") else: bldr.append("I will be messaging you in ") bldr.append( utils.render_time_diff(self.requested_date, self.target_date)) bldr.append(" on ") bldr.append(utils.render_time(self.target_date, self.user)) if self.recurrence is not None: bldr.append(" [and then every](") bldr.append(static.INFO_POST_REPEAT) bldr.append(") `") bldr.append(self.recurrence) bldr.append("`") bldr.append(" to remind you of [**this link**](") bldr.append(utils.check_append_context_to_link(self.source)) bldr.append(")") bldr.append("\n\n") bldr.append("[**") if count_duplicates > 0: bldr.append(str(count_duplicates)) bldr.append(" OTHERS CLICKED") else: bldr.append("CLICK") bldr.append(" THIS LINK**](") bldr.append( utils.build_message_link( static.ACCOUNT_NAME, "Reminder", f"[{self.source}]\n\n{static.TRIGGER}! " f"{utils.get_datetime_string(self.target_date, format_string='%Y-%m-%d %H:%M:%S %Z')}" )) bldr.append(") to send a PM to also be reminded and to reduce spam.") if thread_id is not None: bldr.append("\n\n") bldr.append( "^(Parent commenter can ) [^(delete this message to hide from others.)](" ) bldr.append( utils.build_message_link(static.ACCOUNT_NAME, "Delete Comment", f"Delete! {thread_id}")) bldr.append(")") return bldr
def get_reminders_string(user, database, previous=False): bldr = utils.str_bldr() reminders = database.get_user_reminders(user) cakeday = database.get_cakeday(user) if len(reminders) or cakeday is not None: if previous: bldr.append("Your previous reminders:") else: bldr.append("Your current reminders:") bldr.append("\n\n") if len(reminders) > 1: bldr.append("[Click here to delete all your reminders](") bldr.append( utils.build_message_link(static.ACCOUNT_NAME, "Remove All", "RemoveAll!")) bldr.append(")\n\n") user_settings = database.get_settings(user) if user_settings.timezone is not None: bldr.append("Your timezone is currently set to: `") bldr.append(user_settings.timezone) bldr.append("`\n\n") log.debug( f"Building list with {len(reminders)} reminders and {(0 if cakeday is None else 1)} cakeday" ) bldr.append("|Source|Message|Date|In|Remove|\n") bldr.append("|-|-|-|-|:-:|\n") if cakeday is not None: bldr.append("||") bldr.append("Happy cakeday!") bldr.append("|") bldr.append("Yearly on ") bldr.append( utils.render_time(cakeday.date_time, user_settings.timezone, "%m-%d %H:%M:%S %Z")) bldr.append("|") bldr.append( utils.render_time_diff(utils.datetime_now(), cakeday.date_time)) bldr.append("|") bldr.append("[Remove](") bldr.append( utils.build_message_link(static.ACCOUNT_NAME, "Remove Cakeday Reminder", "Remove! cakeday")) bldr.append(")") bldr.append("|\n") for reminder in reminders: bldr.append("|") if "reddit.com" in reminder.source: bldr.append("[Source](") bldr.append(reminder.source) bldr.append(")") else: bldr.append(reminder.source) bldr.append("|") if reminder.message is not None: bldr.append(reminder.message.replace("|", "|")) bldr.append("|") bldr.append( utils.render_time(reminder.target_date, reminder.timezone)) bldr.append("|") bldr.append( utils.render_time_diff(utils.datetime_now(), reminder.target_date)) bldr.append("|") bldr.append("[Remove](") bldr.append( utils.build_message_link(static.ACCOUNT_NAME, "Remove", f"Remove! {reminder.db_id}")) bldr.append(")") bldr.append("|\n") if utils.bldr_length(bldr) > 9000: log.debug("Message length too long, returning early") bldr.append("\nToo many reminders to display.") break else: bldr.append("You don't have any reminders.") return bldr