This repository has been archived by the owner on Aug 28, 2024. It is now read-only.
forked from Ljzd-PRO/nonebot-plugin-mystool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
help.py
65 lines (55 loc) · 1.91 KB
/
help.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""
### 帮助相关
#### 参考了`nonebot-plugin-help`
"""
from nonebot import on_command
from nonebot.adapters.onebot.v11 import MessageEvent
from nonebot.adapters.onebot.v11.message import Message
from nonebot.matcher import Matcher
from nonebot.params import Arg, CommandArg
from .plugin_data import PluginDataManager
from .utils import PLUGIN, COMMAND_BEGIN
_conf = PluginDataManager.plugin_data_obj
helper = on_command(_conf.preference.command_start + "help",
priority=1,
aliases={_conf.preference.command_start + "帮助"},
block=True)
helper.name = '帮助'
helper.usage = '''\
🍺欢迎使用米游社小助手帮助系统!\
\n{HEAD}帮助 ➢ 查看米游社小助手使用说明\
\n{HEAD}帮助 <功能名> ➢ 查看目标功能详细说明\
'''.strip()
@helper.handle()
async def _(_: MessageEvent, matcher: Matcher, args: Message = CommandArg()):
"""
主命令触发
"""
# 二级命令
if args:
matcher.set_arg("content", args)
# 只有主命令“帮助”
else:
await matcher.finish(
PLUGIN.metadata.name +
PLUGIN.metadata.description +
"\n具体用法:\n" +
PLUGIN.metadata.usage.format(HEAD=COMMAND_BEGIN))
@helper.got('content')
async def _(_: MessageEvent, content: Message = Arg()):
"""
二级命令触发。功能详细说明查询
"""
arg = content.extract_plain_text().strip()
# 相似词
if arg == '登陆':
arg = '登录'
matchers = PLUGIN.matcher
for matcher in matchers:
try:
if arg.lower() == matcher.name:
await helper.finish(
f"『{COMMAND_BEGIN}{matcher.name}』- 使用说明\n{matcher.usage.format(HEAD=COMMAND_BEGIN)}")
except AttributeError:
continue
await helper.finish("⚠️未查询到相关功能,请重新尝试")