diff --git a/nonebot_plugin_mediawiki/__init__.py b/nonebot_plugin_mediawiki/__init__.py index de5b6cc..4a60f59 100644 --- a/nonebot_plugin_mediawiki/__init__.py +++ b/nonebot_plugin_mediawiki/__init__.py @@ -1,6 +1,7 @@ from nonebot import on_regex, on_command from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent, Message from nonebot.adapters.onebot.v11.permission import GROUP +from nonebot.params import RawCommand from . import config_manager from .config import Config @@ -57,9 +58,9 @@ async def _wiki_raw(bot: Bot, event: GroupMessageEvent): @wiki_quick.handle() -async def _wiki_quick(bot: Bot, event: GroupMessageEvent): - if str(event.message).strip().startswith("wiki"): # 防止选择式的消息及无关消息被误加括号 - message = str(event.message).strip().removeprefix("wiki").strip() +async def _wiki_quick(bot: Bot, event: GroupMessageEvent, raw_command: str | None = RawCommand()): + if raw_command and raw_command.endswith("wiki"): # 防止选择式的消息及无关消息被误加括号 + message = str(event.message).strip().removeprefix(raw_command).strip() event2 = event.copy() # 浅拷贝一下,省着篡改消息后把其他插件弄懵了~ event2.message = Message("[[" + message + "]]") await wiki_process(bot, event2, wiki_quick, is_template=False) diff --git a/nonebot_plugin_mediawiki/config_manager.py b/nonebot_plugin_mediawiki/config_manager.py index b606777..924b006 100644 --- a/nonebot_plugin_mediawiki/config_manager.py +++ b/nonebot_plugin_mediawiki/config_manager.py @@ -7,6 +7,7 @@ from nonebot.permission import SUPERUSER from nonebot.typing import T_State from nonebot.internal.matcher import Matcher +from nonebot.params import RawCommand from .config import Config from .mwapi import Mwapi @@ -18,8 +19,8 @@ @add_wiki.handle() -async def _add_wiki(bot: Bot, event: MessageEvent, state: T_State): - msg = str(event.message).strip().removeprefix("wiki.add") +async def _add_wiki(bot: Bot, event: MessageEvent, state: T_State, raw_command: str = RawCommand()): + msg = str(event.message).strip().removeprefix(raw_command).strip() state["global"] = msg == ".global" if state["global"] and str(event.user_id) not in BotConfig.superusers: @@ -85,8 +86,8 @@ async def _add_wiki_url(bot: Bot, event: MessageEvent, state: T_State): @list_wiki.handle() -async def _list_wiki(bot: Bot, event: MessageEvent, state: T_State): - msg = str(event.message).strip().removeprefix("wiki.list") +async def _list_wiki(bot: Bot, event: MessageEvent, state: T_State, raw_command: str = RawCommand()): + msg = str(event.message).strip().removeprefix(raw_command).strip() is_global = msg == ".global" if is_global: @@ -101,8 +102,8 @@ async def _list_wiki(bot: Bot, event: MessageEvent, state: T_State): @del_wiki.handle() -async def _del_wiki(bot: Bot, event: MessageEvent, state: T_State): - msg = str(event.message).strip().removeprefix("wiki.delete") +async def _del_wiki(bot: Bot, event: MessageEvent, state: T_State, raw_command: str = RawCommand()): + msg = str(event.message).strip().removeprefix(raw_command).strip() await __check_params(msg=msg, event=event, state=state, matcher=del_wiki) @@ -121,8 +122,8 @@ async def _del_wiki_prefix(bot: Bot, event: MessageEvent, state: T_State): @set_default.handle() -async def _set_default(bot: Bot, event: MessageEvent, state: T_State): - msg = str(event.message).strip().removeprefix("wiki.default") +async def _set_default(bot: Bot, event: MessageEvent, state: T_State, raw_command: str = RawCommand()): + msg = str(event.message).strip().removeprefix(raw_command).strip() await __check_params(msg=msg, event=event, state=state, matcher=set_default) diff --git a/pyproject.toml b/pyproject.toml index 8c783e8..180b2ae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "nonebot-plugin-mediawiki" -version = "0.1.7" +version = "0.1.8" description = "nonebot2 mediawiki 查询插件" authors = ["KoishiMoe <68314080+KoishiMoe@users.noreply.github.com>"] license = "AGPL-3.0-or-later"