Пример #1
0
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
Пример #2
0
    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
Пример #3
0
    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
Пример #4
0
    def render_message_confirmation(self,
                                    result_message,
                                    comment_return=None,
                                    pushshift_minutes=0):
        bldr = utils.str_bldr()
        if pushshift_minutes > 15 and comment_return is not None:
            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(int(pushshift_minutes)))
                bldr.append(" minute")
            bldr.append(" delay fetching comments.")
            bldr.append("\n\n")

        if result_message is not None:
            bldr.append(result_message)
            bldr.append("\n\n")

        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:
            if 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(utils.datetime_now(),
                                           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(self.recurrence)
                bldr.append("`")
            bldr.append(" to remind you")
            if self.message is None:
                bldr.append(" of [**this link**](")
                bldr.append(utils.check_append_context_to_link(self.source))
                bldr.append(")")
            else:
                bldr.append(": ")
                bldr.append(self.message)

        if comment_return is not None and comment_return in (
                ReturnType.FORBIDDEN, ReturnType.THREAD_LOCKED,
                ReturnType.DELETED_COMMENT, ReturnType.RATELIMIT,
                ReturnType.THREAD_REPLIED):
            bldr.append("\n\n")
            bldr.append(
                "I'm sending this to you as a message instead of replying to your comment because "
            )
            if comment_return == ReturnType.FORBIDDEN:
                bldr.append("I'm not allowed to reply in this subreddit.")
            elif comment_return == ReturnType.THREAD_LOCKED:
                bldr.append("the thread is locked.")
            elif comment_return == ReturnType.DELETED_COMMENT:
                bldr.append("it was deleted before I could get to it.")
            elif comment_return == ReturnType.RATELIMIT:
                bldr.append(
                    "I'm new to this subreddit and have already replied to another thread here recently."
                )
            elif comment_return == ReturnType.THREAD_REPLIED:
                bldr.append(
                    "I've already replied to another comment in this thread.")

        return bldr