Skip to content

Commit

Permalink
fix: 修复非空前缀下识别失效的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
KoishiMoe committed Apr 27, 2022
1 parent 2767a00 commit 5c8932f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
7 changes: 4 additions & 3 deletions nonebot_plugin_mediawiki/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 9 additions & 8 deletions nonebot_plugin_mediawiki/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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)

Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nonebot-plugin-mediawiki"
version = "0.1.7"
version = "0.1.8"
description = "nonebot2 mediawiki 查询插件"
authors = ["KoishiMoe <[email protected]>"]
license = "AGPL-3.0-or-later"
Expand Down

0 comments on commit 5c8932f

Please sign in to comment.