Exemplo n.º 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
Exemplo n.º 2
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
Exemplo n.º 3
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
Exemplo n.º 4
0
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("|", "&#124;"))
            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