Skip to content

Commit

Permalink
feat: 为条目查询增加更便捷的语法
Browse files Browse the repository at this point in the history
  • Loading branch information
KoishiMoe committed Apr 23, 2022
1 parent 0a1d4a3 commit 69e511b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions nonebot_plugin_mediawiki/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from nonebot import on_regex
from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent
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 . import config_manager
Expand All @@ -10,6 +10,7 @@

# 接入帮助系统
__usage__ = '使用:\n' \
'快速使用:wiki 前缀:条目名\n' \
'[[前缀:条目名]] {{前缀:模板名}} ((前缀:条目名))\n' \
'其中中括号、大括号匹配后会调用api搜索条目/模板名,如果有误,可以使用小括号方式绕过api直接生成链接\n' \
'前缀由群管和bot超管配置,没有指定前缀或前缀无效时,会回落到默认前缀\n' \
Expand All @@ -36,6 +37,7 @@
wiki = on_regex(ARTICLE_RAW, permission=GROUP)
wiki_template = on_regex(TEMPLATE, permission=GROUP)
wiki_raw = on_regex(RAW, permission=GROUP)
wiki_quick = on_command("wiki", permission=GROUP, priority=2) # 设个更低的优先级,省着和设置管理器抢(虽然似乎不设也不会抢2333


@wiki.handle()
Expand All @@ -53,3 +55,10 @@ async def _wiki_raw(bot: Bot, event: GroupMessageEvent):
special, result = await wiki_parse(RAW, False, True, bot, event)
await bot.send(event, result)


@wiki_quick.handle()
async def _wiki_quick(bot: Bot, event: GroupMessageEvent):
message = str(event.message).strip().removeprefix("wiki").strip()
event2 = event.copy() # 浅拷贝一下,省着篡改消息后把其他插件弄懵了~
event2.message = Message("[[" + message + "]]")
await wiki_process(bot, event2, wiki_quick, is_template=False)
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.5"
version = "0.1.6"
description = "nonebot2 mediawiki 查询插件"
authors = ["KoishiMoe <[email protected]>"]
license = "AGPL-3.0-or-later"
Expand Down

0 comments on commit 69e511b

Please sign in to comment.