forked from nonepkg/plugin-mcstatus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
51 lines (43 loc) · 1.82 KB
/
__init__.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
from nonebot.plugin import on_shell_command
from nonebot.params import ShellCommandArgs
from nonebot.adapters.onebot.v11 import (
MessageEvent,
PrivateMessageEvent,
GroupMessageEvent,
)
from .parser import mc_parser, ArgNamespace
from .handle import Admin_Handle, Anyone_Handle
# 注册 shell_like 事件响应器
mcs = on_shell_command("mcs", parser=mc_parser, priority=5)
@mcs.handle()
async def _(event: MessageEvent, args: ArgNamespace = ShellCommandArgs()):
args.user_id = event.user_id if isinstance(event, PrivateMessageEvent) else None
args.group_id = event.group_id if isinstance(event, GroupMessageEvent) else None
args.is_admin = (
event.sender.role in ["admin", "owner"]
if isinstance(event, GroupMessageEvent)
else False
)
if hasattr(args, "handle"):
try:
#优先尝试执行Anyone权限命令
result = await getattr(Anyone_Handle, args.handle)(args)
if result:
await mcs.finish(result)
except AttributeError:
if args.is_admin:
#尝试执行Admin权限命令
result = await getattr(Admin_Handle, args.handle)(args)
if result:
await mcs.finish(result)
await mcs.finish('不存在对应命令,请检查命令是否存在,或者是否具有相应执行权限')
# nonebot_help
__usage__ = '''Minecraft Server Checker
/mcs add <name> <address> #为本群记录一个服务器,将自动判断服务器类型(形如/mcs add demo example.org)
/mcs list # 展示本群已记录服务器列表
/mcs remove <name> # 删除对应服务器
/mcs ping <name> # 检查对应服务器的状态
/mcs p # 检查列表第一个服务器的状态
'''
__version__ = '0.1.0'
__plugin_name__ = "Minecraft Server Checker"