-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhandler.py
More file actions
59 lines (44 loc) · 1.42 KB
/
handler.py
File metadata and controls
59 lines (44 loc) · 1.42 KB
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
from nonebot.rule import to_me
from nonebot.plugin import on_command
from nonebot.params import CommandArg
from nonebot.adapters import Message
from nonebot.adapters.onebot.v11 import MessageSegment
from nonebot.permission import SUPERUSER
from nonebot.log import logger
from nonebot_plugin_htmlrender import html_to_pic
from .services import PanelService
from .config import config
from .utils.shell import ShellSync
def get_shell():
host_dict = {
"hostname": config.qqshell_host,
"port": config.qqshell_port,
"username": config.qqshell_host_user,
"password": config.qqshell_host_password,
}
print(host_dict)
_shell = ShellSync(**host_dict)
return _shell
shell = get_shell()
qq_shell = on_command(
"shell",
aliases={">shell", },
rule=to_me,
priority=config.qqshell_priority,
block=True,
permission=SUPERUSER,
)
@qq_shell.handle()
async def shell_handler(args: Message = CommandArg()):
command = "" if not args else args.extract_plain_text()
# 命令执行并获取结果
if shell.is_connect():
shell.exec_command(command)
else:
logger.error("Shell 连接失败,请确认连接配置")
return
res = shell.get_output()
# 输出结果
pic = await html_to_pic(PanelService.render_text_xterm(text=res, theme=config.qqshell_theme))
message = MessageSegment.image(file=pic)
await qq_shell.finish(message)