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}**] !" )
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))
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))
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))
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))
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)
def _get_memo_list(cls, message: Message, info_executor: FixedValueParamExecutor): memos = DbMemo.get_memo_list(message.author.id) if not memos: cls._reply(message, "Tu n'as aucun mémo enregistré.") else: memo_list_str = [] for memo in memos: memo_list_str.append("`{}`".format( memo.name.replace(" ", "\u00A0"))) cls._reply( message, AppMessages.get_memo_embed( "Mes mémos", "\u00A0\u0020\u00A0".join(memo_list_str), "{} / {}".format(len(memos), cls._MAX_PER_USER)), cls._DELETE_DELAY)