From f5cbfd6e8a6167dfd318e764f856699c0d26a424 Mon Sep 17 00:00:00 2001 From: baby20162016 <2185823427@qq.com> Date: Fri, 9 Jan 2026 22:08:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0thpic=E6=8F=92=E4=BB=B6=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=B8=80=E6=AC=A1=E8=BF=94=E5=9B=9E=E5=A4=9A?= =?UTF-8?q?=E5=BC=A0=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/thpic.py | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/plugins/thpic.py b/plugins/thpic.py index 2112cf6..0512118 100644 --- a/plugins/thpic.py +++ b/plugins/thpic.py @@ -12,7 +12,7 @@ from models.events.message import MessageEvent, MessageSegment __plugin_meta__ = { "name": "thpic", "description": "来看看东方Project的图片吧!", - "usage": "/thpic", + "usage": "/thpic [nums](1~10)", } @@ -25,7 +25,38 @@ async def handle_echo(bot: Bot, event: MessageEvent, args: list[str]): :param event: 消息事件对象。 :param args: 指令参数列表(未使用)。 """ - try: - await event.reply(str(MessageSegment.image("https://img.paulzzh.com/touhou/random"))) - except Exception as e: - await event.reply(f"报错了。。。{e}") + parts = args + print(parts) + if not parts: + try: + await event.reply( + str(MessageSegment.image("https://img.paulzzh.com/touhou/random")) + ) + except Exception as e: + await event.reply(f"报错了。。。{e}") + else: + if parts[0].isdigit(): + nums = int(parts[0]) + if nums <= 0: + await event.reply("请输入一个大于0的整数。") + return + elif nums > 10: + await event.reply("请输入一个不大于10的整数。") + return + try: + nodes = [] + for _ in range(nums): + nodes.append( + bot.build_forward_node( + user_id=event.self_id, + nickname="机器人", + message=MessageSegment.image( + "https://img.paulzzh.com/touhou/random" + ), + ) + ) + await bot.send_forwarded_messages(event, nodes) + except Exception as e: + await event.reply(f"报错了。。。{e}") + else: + await event.reply(f"用法不正确。\n\n{__plugin_meta__['usage']}")