From 801f06b34c0997570b4569c5b91632c1b64b0a51 Mon Sep 17 00:00:00 2001 From: CMHopeSunshine <277073121@qq.com> Date: Mon, 28 Nov 2022 17:50:33 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20`Wiki`=E6=96=B0=E5=A2=9E`=E4=B8=83?= =?UTF-8?q?=E5=9C=A3=E5=8F=AC=E5=94=A4=E5=9B=BE=E9=89=B4`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LittlePaimon/plugins/Paimon_Wiki/__init__.py | 4 ++-- LittlePaimon/plugins/Paimon_Wiki/card.py | 4 +++- LittlePaimon/plugins/plugin_manager/__init__.py | 9 ++------- LittlePaimon/utils/message.py | 7 +++++++ 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/LittlePaimon/plugins/Paimon_Wiki/__init__.py b/LittlePaimon/plugins/Paimon_Wiki/__init__.py index 10953ad..243f7f8 100644 --- a/LittlePaimon/plugins/Paimon_Wiki/__init__.py +++ b/LittlePaimon/plugins/Paimon_Wiki/__init__.py @@ -12,7 +12,7 @@ from nonebot.typing import T_State from LittlePaimon.database import PlayerAlias from LittlePaimon.utils import NICKNAME from LittlePaimon.utils.alias import get_match_alias -from LittlePaimon.utils.message import MessageBuild +from LittlePaimon.utils.message import MessageBuild, fullmatch_rule from LittlePaimon.utils.path import RESOURCE_BASE_PATH from LittlePaimon.utils.tool import freq_limiter from .draw_daily_material import draw_material @@ -84,7 +84,7 @@ card_wiki = on_command('七圣召唤图鉴', aliases={'原牌图鉴', '原石传 'pm_priority': 13 }) card_wiki_list = on_command('七圣召唤列表', aliases={'七圣召唤卡牌列表', '原牌列表', '原石传说列表'}, priority=11, - block=True, state={ + rule=fullmatch_rule, block=True, state={ 'pm_name': '七圣召唤图鉴列表', 'pm_description': '查看七圣召唤卡牌图鉴列表', 'pm_usage': '原牌列表', diff --git a/LittlePaimon/plugins/Paimon_Wiki/card.py b/LittlePaimon/plugins/Paimon_Wiki/card.py index a4bf659..d7c8d4a 100644 --- a/LittlePaimon/plugins/Paimon_Wiki/card.py +++ b/LittlePaimon/plugins/Paimon_Wiki/card.py @@ -12,7 +12,9 @@ async def update_card_list(): with contextlib.suppress(Exception): resp = await aiorequests.get(CARD_RESOURCES_API) if resp.status_code == 200: - card_list.extend([card['name'].split('.')[0] for card in resp.json()]) + for card in resp.json(): + if (name := card['name'].replace('.png', '')) not in card_list: + card_list.append(name) return None diff --git a/LittlePaimon/plugins/plugin_manager/__init__.py b/LittlePaimon/plugins/plugin_manager/__init__.py index 84c42bc..3388802 100644 --- a/LittlePaimon/plugins/plugin_manager/__init__.py +++ b/LittlePaimon/plugins/plugin_manager/__init__.py @@ -3,14 +3,13 @@ from nonebot.adapters.onebot.v11 import Message, GroupMessageEvent, PrivateMessa from nonebot.params import RegexDict, CommandArg from nonebot.permission import SUPERUSER from nonebot.plugin import PluginMetadata -from nonebot.rule import Rule from nonebot.typing import T_State from LittlePaimon import SUPERUSERS from LittlePaimon.config import ConfigManager, PluginManager from LittlePaimon.database import PluginDisable from LittlePaimon.utils import logger -from LittlePaimon.utils.message import CommandObjectID +from LittlePaimon.utils.message import CommandObjectID, fullmatch_rule from .draw_help import draw_help __plugin_meta__ = PluginMetadata( @@ -24,10 +23,6 @@ __plugin_meta__ = PluginMetadata( ) -def fullmatch(msg: Message = CommandArg()) -> bool: - return not bool(msg) - - manage_cmd = on_regex( r'^pm (?Pban|unban) (?P([\w ]*)|all|全部) ?(-g (?P[\d ]*) ?)?(-u (?P[\d ]*) ?)?', priority=1, block=True, state={ @@ -36,7 +31,7 @@ manage_cmd = on_regex( 'pm_usage': 'pm ban|unban <插件名>', 'pm_priority': 1 }) -help_cmd = on_command('help', aliases={'帮助', '菜单', 'pm help'}, priority=1, rule=Rule(fullmatch), block=True, state={ +help_cmd = on_command('help', aliases={'帮助', '菜单', 'pm help'}, priority=1, rule=fullmatch_rule, block=True, state={ 'pm_name': 'pm-help', 'pm_description': '查看本帮助', 'pm_usage': 'help', diff --git a/LittlePaimon/utils/message.py b/LittlePaimon/utils/message.py index 6cab339..0b21a6a 100644 --- a/LittlePaimon/utils/message.py +++ b/LittlePaimon/utils/message.py @@ -8,6 +8,7 @@ from typing import Union, Optional, Tuple, List from PIL import Image from nonebot import get_bot from nonebot.adapters.onebot.v11 import MessageEvent, Message, MessageSegment, GroupMessageEvent +from nonebot.rule import Rule from nonebot.matcher import Matcher from nonebot.params import CommandArg, Depends from nonebot.typing import T_State @@ -95,6 +96,12 @@ class MessageBuild: return MessageSegment.video(path) +def fullmatch(msg: Message = CommandArg()) -> bool: + return not bool(msg) + +fullmatch_rule = Rule(fullmatch) + + def CommandPlayer(limit: int = 3, only_cn: bool = True) -> List[Player]: """ 获取查询操作中的user_id、uid和图片,并将过滤uid后的msg存放到T_State中