From 62ecd227b061103c8f38702d47b5b8c33910ba43 Mon Sep 17 00:00:00 2001 From: Sevenyine <65720409+Sevenyine@users.noreply.github.com> Date: Thu, 31 Aug 2023 21:11:58 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=8C=87=E4=BB=A4=E5=90=8E=E4=B8=8D?= =?UTF-8?q?=E5=8A=A0=E5=8F=82=E6=95=B0=E6=97=B6=E7=AD=89=E5=BE=85=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=B8=8B=E4=B8=80=E6=9D=A1=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 能用但是依托的版本,, --- nonebot_plugin_bottle/__init__.py | 49 ++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/nonebot_plugin_bottle/__init__.py b/nonebot_plugin_bottle/__init__.py index 19777b1..b5ad460 100644 --- a/nonebot_plugin_bottle/__init__.py +++ b/nonebot_plugin_bottle/__init__.py @@ -172,22 +172,15 @@ async def _( await listb.finish(total_bottles_info + "\n".join(bottles_info[:10])) ba.add("cooldown", event.user_id) - -@throw.handle() -async def _( +async def handle_bottle( bot: Bot, matcher: Matcher, event: GroupMessageEvent, - args: Message = CommandArg(), - session: AsyncSession = Depends(get_session), + args: Message, + session: AsyncSession ): - await verify(matcher=matcher, event=event) - - if not args: - await throw.finish("想说些什么话呢?在指令后边写上吧!") - message_text = args.extract_plain_text().strip() - + print(message_text) audit = await text_audit(text=message_text) if not audit == "pass": if audit == "Error": @@ -218,12 +211,37 @@ async def _( # 添加个人冷却 ba.add("cooldown", event.user_id) await asyncio.sleep(2) - await throw.send( + await throw.finish( f"你将编号No.{add_index}的漂流瓶以时速{random.randint(0,2**16)}km/h的速度扔出去,谁会捡到这个瓶子呢..." ) else: await asyncio.sleep(2) - await throw.send("你的瓶子以奇怪的方式消失掉了!") + await throw.finish("你的瓶子以奇怪的方式消失掉了!") + +@throw.handle() +async def _( + bot: Bot, + matcher: Matcher, + event: GroupMessageEvent, + args: Message = CommandArg(), + session: AsyncSession = Depends(get_session), +): + await verify(matcher=matcher, event=event) + + if args: + await handle_bottle(bot, matcher, event, args, session) + +@throw.got("prompt", prompt="想说些什么话呢?在指令后边写上吧!") +async def _( + bot: Bot, + matcher: Matcher, + event: GroupMessageEvent, + args: Message = Arg("prompt"), + session: AsyncSession = Depends(get_session), +): + await verify(matcher=matcher, event=event) + if args: + await handle_bottle(bot, matcher, event, args, session) @get.handle() @@ -455,7 +473,10 @@ async def _( @clear.got("prompt", prompt="你确定要清空所有漂流瓶吗?(Y/N)所有的漂流瓶都将会永久失去。(真的很久!)") -async def _(conf: str = ArgStr("prompt"), session: AsyncSession = Depends(get_session)): +async def _( + conf: str = ArgStr("prompt"), + session: AsyncSession = Depends(get_session), +): if conf in proceed: await bottle_manager.clear(session) await session.commit() From ee24669a35a838138053fae8a544751f346e2bfc Mon Sep 17 00:00:00 2001 From: Cinte Date: Thu, 31 Aug 2023 21:31:33 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=A8=8D=E5=BE=AE=E6=94=B9=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonebot_plugin_bottle/__init__.py | 56 +++++++++++-------------------- pyproject.toml | 2 +- 2 files changed, 21 insertions(+), 37 deletions(-) diff --git a/nonebot_plugin_bottle/__init__.py b/nonebot_plugin_bottle/__init__.py index b5ad460..ca11c45 100644 --- a/nonebot_plugin_bottle/__init__.py +++ b/nonebot_plugin_bottle/__init__.py @@ -172,15 +172,27 @@ async def _( await listb.finish(total_bottles_info + "\n".join(bottles_info[:10])) ba.add("cooldown", event.user_id) -async def handle_bottle( - bot: Bot, + +@throw.handle() +async def _( matcher: Matcher, event: GroupMessageEvent, - args: Message, - session: AsyncSession + args: Message = CommandArg(), +): + await verify(matcher=matcher, event=event) + if args: + matcher.set_arg("content", args) + + +@throw.got("content", prompt="想说些什么话呢?") +async def _( + bot: Bot, + event: GroupMessageEvent, + args: Message = Arg("content"), + session: AsyncSession = Depends(get_session), ): message_text = args.extract_plain_text().strip() - print(message_text) + audit = await text_audit(text=message_text) if not audit == "pass": if audit == "Error": @@ -211,37 +223,12 @@ async def handle_bottle( # 添加个人冷却 ba.add("cooldown", event.user_id) await asyncio.sleep(2) - await throw.finish( + await throw.send( f"你将编号No.{add_index}的漂流瓶以时速{random.randint(0,2**16)}km/h的速度扔出去,谁会捡到这个瓶子呢..." ) else: await asyncio.sleep(2) - await throw.finish("你的瓶子以奇怪的方式消失掉了!") - -@throw.handle() -async def _( - bot: Bot, - matcher: Matcher, - event: GroupMessageEvent, - args: Message = CommandArg(), - session: AsyncSession = Depends(get_session), -): - await verify(matcher=matcher, event=event) - - if args: - await handle_bottle(bot, matcher, event, args, session) - -@throw.got("prompt", prompt="想说些什么话呢?在指令后边写上吧!") -async def _( - bot: Bot, - matcher: Matcher, - event: GroupMessageEvent, - args: Message = Arg("prompt"), - session: AsyncSession = Depends(get_session), -): - await verify(matcher=matcher, event=event) - if args: - await handle_bottle(bot, matcher, event, args, session) + await throw.send("你的瓶子以奇怪的方式消失掉了!") @get.handle() @@ -473,10 +460,7 @@ async def _( @clear.got("prompt", prompt="你确定要清空所有漂流瓶吗?(Y/N)所有的漂流瓶都将会永久失去。(真的很久!)") -async def _( - conf: str = ArgStr("prompt"), - session: AsyncSession = Depends(get_session), -): +async def _(conf: str = ArgStr("prompt"), session: AsyncSession = Depends(get_session)): if conf in proceed: await bottle_manager.clear(session) await session.commit() diff --git a/pyproject.toml b/pyproject.toml index 6ba3c32..61e8d90 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "nonebot_plugin_bottle" -version = "1.0.1.3" +version = "1.0.1.4" description = "Bottle post plugin in Nonebot" authors = ["Todysheep "] license = "GNU GPLv3"