From ed0e759d8b3a152eaf7384e0987efc5b34e9560f Mon Sep 17 00:00:00 2001 From: CMHopeSunshine <277073121@qq.com> Date: Tue, 21 Jun 2022 16:44:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=B6=E4=BB=96=E9=80=82=E9=85=8D=E4=BA=86`b?= =?UTF-8?q?eta4`=E5=85=83=E6=95=B0=E6=8D=AE=E7=9A=84=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E4=B9=9F=E4=BC=9A=E6=98=BE=E7=A4=BA=E5=9C=A8`paimon=5Fhelp`?= =?UTF-8?q?=E5=B8=AE=E5=8A=A9=E9=9D=A2=E6=9D=BF=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Paimon_Plugins/paimon_help.py | 7 +++++++ utils/alias_handler.py | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/Paimon_Plugins/paimon_help.py b/Paimon_Plugins/paimon_help.py index c22c7e3..a9ee69a 100644 --- a/Paimon_Plugins/paimon_help.py +++ b/Paimon_Plugins/paimon_help.py @@ -120,14 +120,21 @@ async def get_all_plugin(event: MessageEvent) -> dict: if plugin_type not in help_info: help_info[plugin_type] = [] matchers = plugin.matcher + matcher_flag = False for matcher in matchers: try: matchers_info = matcher.__paimon_help__ if 'priority' not in matchers_info: matchers_info['priority'] = 99 help_info[plugin_type].append(matchers_info) + matcher_flag = True except AttributeError: pass + if not matcher_flag: + try: + help_info[plugin_type].append({'usage': plugin.metadata.name, 'introduce': plugin.metadata.description, 'priority': 99}) + except AttributeError: + continue help_info = {k: v for k, v in help_info.items() if v} if not help_info: await help_.finish('当前没有已加载的插件哦') diff --git a/utils/alias_handler.py b/utils/alias_handler.py index 4eaf242..6f21c87 100644 --- a/utils/alias_handler.py +++ b/utils/alias_handler.py @@ -5,11 +5,21 @@ import os def get_short_name(name: str): + """ + 获取角色或武器的短名(2个字) + :param name: 角色或武器名 + :return: 短名字符串 + """ short_name = load_json(path=os.path.join(os.path.dirname(__file__), 'short_name.json')) return name if name not in short_name.keys() else short_name[name] def get_id_by_name(name: str): + """ + 根据角色名字获取角色的id + :param name: 角色名 + :return: id字符串 + """ alias_file = load_json(path=os.path.join(os.path.dirname(__file__), 'alias.json')) name_list = alias_file['roles'] for role_id, alias in name_list.items(): @@ -18,6 +28,11 @@ def get_id_by_name(name: str): def get_name_by_id(role_id: str): + """ + 根据角色id获取角色名 + :param role_id: 角色id + :return: 角色名字符串 + """ alias_file = load_json(path=os.path.join(os.path.dirname(__file__), 'alias.json')) name_list = alias_file['roles'] if role_id in name_list: @@ -27,6 +42,13 @@ def get_name_by_id(role_id: str): def get_match_alias(msg: str, type: str = 'roles', single_to_dict: bool = False) -> Union[str, list, dict]: + """ + 根据字符串消息,获取与之相似或匹配的角色、武器、原魔名 + :param msg: 消息 + :param type: 匹配类型,有roles、weapons、monsters + :param single_to_dict: 是否将角色单结果也转换成{角色:id}字典 + :return: 匹配的字符串、列表或字典 + """ alias_file = load_json(path=os.path.join(os.path.dirname(__file__), 'alias.json')) alias_list = alias_file[type] if msg in ['风主', '岩主', '雷主']: