summaryrefslogtreecommitdiff
path: root/ATRI/plugins/code_runner/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'ATRI/plugins/code_runner/__init__.py')
-rw-r--r--ATRI/plugins/code_runner/__init__.py38
1 files changed, 24 insertions, 14 deletions
diff --git a/ATRI/plugins/code_runner/__init__.py b/ATRI/plugins/code_runner/__init__.py
index adf6407..77240ec 100644
--- a/ATRI/plugins/code_runner/__init__.py
+++ b/ATRI/plugins/code_runner/__init__.py
@@ -11,33 +11,43 @@ from .data_source import CodeRunner
_flmt_notice = choice(["慢...慢一..点❤", "冷静1下", "歇会歇会~~"])
-code_runner = CodeRunner().on_command("/code", "在线运行一段代码,帮助:/code help")
+code_runner = CodeRunner().on_command("/code", "在线运行一段代码,获取帮助:/code.help")
@code_runner.handle([Cooldown(5, prompt=_flmt_notice)])
-async def _code_runner(
- matcher: Matcher, event: MessageEvent, args: Message = CommandArg()
-):
- user_id = event.get_user_id()
+async def _code_runner(matcher: Matcher, args: Message = CommandArg()):
msg = args.extract_plain_text()
if msg:
matcher.set_arg("opt", args)
else:
- content = f"> {MessageSegment.at(user_id)}\n" + "请键入 /code help 以获取帮助~!"
+ content = "请键入 /code.help 以获取帮助~!"
await code_runner.finish(Message(content))
-@code_runner.got("opt")
+@code_runner.got("opt", prompt="需要运行的语言及代码?\n获取帮助:/code.help")
async def _(event: MessageEvent, opt: str = ArgPlainText("opt")):
user_id = event.get_user_id()
- msg = opt.split("\n")
- if msg[0] == "help":
- content = f"> {MessageSegment.at(user_id)}\n" + "请键入 /code help 以获取帮助~!"
- elif msg[0] == "list":
- content = f"> {MessageSegment.at(user_id)}\n" + CodeRunner().list_supp_lang()
- else:
- content = MessageSegment.at(user_id) + await CodeRunner().runner(unescape(opt))
+ # 拯救傻瓜用户
+ if opt == "/code.help":
+ await code_runner.finish(CodeRunner().help())
+ content = MessageSegment.at(user_id) + str(await CodeRunner().runner(unescape(opt)))
await code_runner.finish(Message(content))
+
+
+code_runner_helper = CodeRunner().cmd_as_group("help", "使用说明")
+
+
+@code_runner_helper.handle()
+async def _():
+ await code_runner_helper.finish(CodeRunner().help())
+
+
+code_supp_list = CodeRunner().cmd_as_group("list", "查看支持的语言")
+
+
+@code_supp_list.handle()
+async def _():
+ await code_supp_list.finish(CodeRunner().list_supp_lang())