Esempio n. 1
0
    def _remove_memo_line(cls, message: Message,
                          name_executor: TextParamExecutor,
                          line_executor: FixedValueParamExecutor,
                          int_executor: IntParamExecutor,
                          delete_executor: FixedValueParamExecutor):

        # Just to display a better error message
        memo_name = DbMemo.get_memo_name(message.author.id,
                                         name_executor.get_text(), True)
        if not memo_name:
            cls._display_error(
                message,
                ("Aucun mémo trouvé avec le nom `{}`."
                 " Pour supprimer il faut taper le nom **exact** du mémo."
                 ).format(name_executor.get_text()))
            return

        line_count = DbMemo.count_memo_lines(message.author.id,
                                             name_executor.get_text(), True)

        if line_count < int_executor.get_int():
            cls._display_error(
                message, "Le mémo [**{}**] n'a que `{}` ligne(s).".format(
                    memo_name, line_count))
            return

        if cls._execute_db_bool_request(
                lambda: DbMemo.remove_memo_line(message.author.id,
                                                name_executor.get_text(),
                                                int_executor.get_int()),
                message):
            cls._reply(
                message,
                f"Ligne `{int_executor.get_int()}` supprimée du mémo [**{memo_name}**] !"
            )
Esempio n. 2
0
    def _add_reply(cls, message: Message, user_executor: UserParamExecutor,
                   text_executor: TextParamExecutor):
        reply_count = DbAutoReply.count_auto_replys(
            message.guild.id,
            user_executor.get_user().id, message.author.id)

        if reply_count >= cls._MAX_PER_USER:
            cls._reply(
                message,
                "Oups, il y a déjà {} message(s) enregistré(s) pour **{}**, il va falloir attendre ton tour !"
                .format(
                    reply_count,
                    Sanitizer.user_name(
                        user_executor.get_user().display_name)))
            return

        content = ParsingUtils.format_links(
            ParsingUtils.to_single_line(text_executor.get_text()))

        if cls._execute_db_bool_request(
                lambda: DbAutoReply.add_auto_reply(
                    message.guild.id, message.channel.id, message.author.id,
                    user_executor.get_user().id, content), message):
            cls._reply(
                message, "Message enregistré pour **%s** !" %
                Sanitizer.user_name(user_executor.get_user().display_name))
Esempio n. 3
0
    def _remove_memo(cls, message: Message, name_executor: TextParamExecutor,
                     delete_executor: FixedValueParamExecutor):
        # Just to display a better message
        memo_name = DbMemo.get_memo_name(message.author.id,
                                         name_executor.get_text(), True)
        if not memo_name:
            cls._display_error(
                message,
                ("Aucun mémo trouvé avec le nom `{}`."
                 " Pour supprimer il faut taper le nom **exact** du mémo."
                 ).format(name_executor.get_text()))
            return

        if cls._execute_db_bool_request(
                lambda: DbMemo.remove_memo(message.author.id,
                                           name_executor.get_text()), message):
            cls._reply(message, "Mémo [**{}**] supprimé !".format(memo_name))
Esempio n. 4
0
    def _get_memo(cls, message: Message, name_executor: TextParamExecutor):
        memo = DbMemo.get_memo(message.author.id, name_executor.get_text())

        if not memo:
            cls._display_error(
                message, "Aucun mémo trouvé commençant par `{}`.".format(
                    name_executor.get_text()))
            return

        content = "\n".join([
            f"`{line_count + 1}`\u00A0\u00A0\u00A0{line}"
            for line_count, line in enumerate(memo.lines)
        ])

        cls._reply(message,
                   AppMessages.get_memo_embed(f"Mémo [{memo.name}]", content),
                   cls._DELETE_DELAY)
Esempio n. 5
0
    def _edit_memo(cls, message: Message, name_executor: TextParamExecutor,
                   edit_executor: FixedValueParamExecutor,
                   content_executor: TextParamExecutor):

        memo = DbMemo.get_memo(message.author.id, name_executor.get_text())
        if not memo:
            cls._display_error(
                message, "Aucun mémo trouvé commençant par `{}`.".format(
                    name_executor.get_text()))
            return

        line_count = len(memo.lines)
        if line_count >= cls._MAX_LINES:
            cls._display_error(
                message,
                "Le mémo [**{}**] fait déjà {} lignes, tu ne peux plus rien rajouter."
                .format(name_executor.get_text(), cls._MAX_LINES))
            return

        total_char_count = len("".join(memo.lines)) + len(
            content_executor.get_text())
        if total_char_count > cls._MAX_CHARS:
            cls._display_error(
                message,
                "Le mémo [**{}**] va dépasser les {} caractères, il faut en créer un autre."
                .format(name_executor.get_text(), cls._MAX_CHARS))
            return

        if cls._execute_db_bool_request(
                lambda: DbMemo.edit_memo(message.author.id,
                                         name_executor.get_text(),
                                         content_executor.get_text()),
                message):
            cls._reply(message, "Mémo [**{}**] édité !".format(memo.name))
Esempio n. 6
0
    def _add_memo(cls, message: Message, name_executor: TextParamExecutor,
                  content_executor: TextParamExecutor):
        memo_count = DbMemo.count_user_memos(message.author.id)

        if memo_count >= cls._MAX_PER_USER:
            cls._reply(
                message,
                ("Tu as déjà enregistré {} mémos, dis-donc tu ne crois pas "
                 "qu'il serait temps de faire un peu de ménage ? :smirk:"
                 ).format(cls._MAX_PER_USER))
            return

        name = ParsingUtils.to_single_line(name_executor.get_text().replace(
            "`", ""))
        content = ParsingUtils.to_single_line(content_executor.get_text())

        if DbMemo.add_memo(message.author.id, name, content):
            cls._reply(message, "Mémo [**{}**] ajouté !".format(name))
        else:
            cls._display_error(
                message,
                "Le mémo [**{}**] existe déjà, veux-tu l'éditer ?".format(
                    name))
Esempio n. 7
0
    def _get_memo_line(cls, message: Message, name_executor: TextParamExecutor,
                       line_executor: FixedValueParamExecutor,
                       int_executor: IntParamExecutor):
        # memo_name and line_count : just to display a better error message
        memo_name = DbMemo.get_memo_name(message.author.id,
                                         name_executor.get_text())
        if not memo_name:
            cls._display_error(
                message, "Aucun mémo trouvé commençant par `{}`.".format(
                    name_executor.get_text()))
            return

        line_count = DbMemo.count_memo_lines(message.author.id,
                                             name_executor.get_text())

        if line_count < int_executor.get_int():
            cls._reply(
                message, "Le mémo [**{}**] n'a que `{}` ligne(s).".format(
                    memo_name, line_count))
            return

        memo_line = DbMemo.get_memo_line(message.author.id,
                                         name_executor.get_text(),
                                         int_executor.get_int())

        if not memo_line:
            cls._display_error(message, "Je n'ai rien trouvé.")
            return

        # Put text in bold if not containing *
        if "*" not in memo_line:
            memo_line = f"**{memo_line}**"

        cls._async(
            message.channel.send(embed=AppMessages.get_memo_line_embed(
                memo_line, f"Mémo de {message.author.display_name}")))
        cls._async(message.delete(delay=cls._delete_delay))