From 405dfa5a4168f439460cca9322b56919e545bd84 Mon Sep 17 00:00:00 2001 From: Kyomotoi Date: Thu, 3 Feb 2022 23:31:34 +0800 Subject: =?UTF-8?q?=F0=9F=9A=91=EF=B8=8F=20=E4=BF=AE=E5=A4=8D=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=A4=84=E7=90=86=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ATRI/plugins/broadcast.py | 2 +- ATRI/plugins/code_runner/__init__.py | 28 ++++++++++++++++++++-------- ATRI/plugins/help/__init__.py | 7 ++++--- 3 files changed, 25 insertions(+), 12 deletions(-) (limited to 'ATRI') diff --git a/ATRI/plugins/broadcast.py b/ATRI/plugins/broadcast.py index b12c050..07315f2 100644 --- a/ATRI/plugins/broadcast.py +++ b/ATRI/plugins/broadcast.py @@ -55,7 +55,7 @@ class BroadCast(Service): caster = BroadCast().on_command( - "广播", "向bot所在的所有群发送信息,有防寄延迟", aliases={"/bc", "bc"}, permission=SUPERUSER + "广播", "向bot所在的所有群发送信息,有防寄延迟", aliases={"bc"}, permission=SUPERUSER ) diff --git a/ATRI/plugins/code_runner/__init__.py b/ATRI/plugins/code_runner/__init__.py index 334c09a..90d4942 100644 --- a/ATRI/plugins/code_runner/__init__.py +++ b/ATRI/plugins/code_runner/__init__.py @@ -1,5 +1,7 @@ from random import choice +from nonebot.matcher import Matcher +from nonebot.params import CommandArg, ArgPlainText from nonebot.adapters.onebot.v11 import MessageEvent, Message, MessageSegment, unescape from ATRI.utils.limit import FreqLimiter @@ -14,22 +16,32 @@ code_runner = CodeRunner().on_command("/code", "在线运行一段代码,帮 @code_runner.handle() -async def _code_runner(event: MessageEvent): +async def _code_runner(matcher: Matcher, event: MessageEvent, args: Message = CommandArg()): user_id = event.get_user_id() if not _flmt.check(user_id): await code_runner.finish(_flmt_notice) + + msg = args.extract_plain_text() + print(msg, args, type(msg), type(args)) + if msg: + matcher.set_arg("opt", args) + else: + content = f"> {MessageSegment.at(user_id)}\n" + "请键入 /code help 以获取帮助~!" + await code_runner.finish(Message(content)) - msg = str(event.get_message()) - args = msg.split("\n") - if not args[0]: +@code_runner.got("opt") +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 args[0] == "help": - content = f"> {MessageSegment.at(user_id)}\n" + CodeRunner().help() - elif args[0] == "list": + 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(msg)) + content = MessageSegment.at(user_id) + await CodeRunner().runner(unescape(opt)) _flmt.start_cd(user_id) await code_runner.finish(Message(content)) diff --git a/ATRI/plugins/help/__init__.py b/ATRI/plugins/help/__init__.py index a8465bc..c50d7f2 100644 --- a/ATRI/plugins/help/__init__.py +++ b/ATRI/plugins/help/__init__.py @@ -36,10 +36,11 @@ service_info = Helper().on_command("帮助", "获取服务详细帮助", aliases @service_info.handle() async def _ready_service_info(event: MessageEvent): - msg = str(event.message).split(" ") - service = msg[0] + msg = str(event.get_message()).split(" ") + + service = msg[1] try: - cmd = msg[1] + cmd = msg[2] except BaseException: cmd = str() -- cgit v1.2.3