From 2826a5fc09d5862d07e194261984568994411e9d Mon Sep 17 00:00:00 2001 From: Decrabbit Date: Fri, 9 Aug 2024 16:56:56 +0800 Subject: [PATCH 1/5] support qq adapter group and c2c recall --- .../uniseg/adapters/qq/exporter.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/nonebot_plugin_alconna/uniseg/adapters/qq/exporter.py b/src/nonebot_plugin_alconna/uniseg/adapters/qq/exporter.py index fccce8c..55e364a 100644 --- a/src/nonebot_plugin_alconna/uniseg/adapters/qq/exporter.py +++ b/src/nonebot_plugin_alconna/uniseg/adapters/qq/exporter.py @@ -1,5 +1,6 @@ from pathlib import Path from dataclasses import dataclass +from nonebot.adapters.qq.models import PostC2CMessagesReturn, PostGroupMessagesReturn, QQMessage from typing_extensions import override from typing import TYPE_CHECKING, Any, Union @@ -420,6 +421,21 @@ async def recall(self, mid: Any, bot: Bot, context: Union[Target, Event]): channel_id=mid.channel_id, message_id=mid.id, ) + elif isinstance(context, GroupAtMessageCreateEvent): + if isinstance(mid,PostGroupMessagesReturn): + + await bot.delete_group_message( + group_openid=context.group_openid, + message_id=mid.id,#type: ignore + ) + elif isinstance(context, C2CMessageCreateEvent): + if isinstance(mid, PostC2CMessagesReturn): + await bot.delete_c2c_message( + openid=context.author.id, + message_id=mid.id,#type: ignore + ) + + return def get_reply(self, mid: Any): From a22356b6284d4ae5b44da5d49000f8f0c4af56ba Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 9 Aug 2024 08:58:36 +0000 Subject: [PATCH 2/5] :rotating_light: auto fix by pre-commit hooks --- .../uniseg/adapters/qq/exporter.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/nonebot_plugin_alconna/uniseg/adapters/qq/exporter.py b/src/nonebot_plugin_alconna/uniseg/adapters/qq/exporter.py index 55e364a..41e6f11 100644 --- a/src/nonebot_plugin_alconna/uniseg/adapters/qq/exporter.py +++ b/src/nonebot_plugin_alconna/uniseg/adapters/qq/exporter.py @@ -1,6 +1,5 @@ from pathlib import Path from dataclasses import dataclass -from nonebot.adapters.qq.models import PostC2CMessagesReturn, PostGroupMessagesReturn, QQMessage from typing_extensions import override from typing import TYPE_CHECKING, Any, Union @@ -11,6 +10,7 @@ from nonebot.adapters.qq.message import Message, MessageSegment from nonebot.adapters.qq.models.common import Button as ButtonModel from nonebot.adapters.qq.models.guild import Message as GuildMessage +from nonebot.adapters.qq.models import PostC2CMessagesReturn, PostGroupMessagesReturn from nonebot.adapters.qq.models.common import Permission, RenderData, InlineKeyboard, MessageKeyboard, InlineKeyboardRow from nonebot.adapters.qq.event import ( ForumEvent, @@ -422,20 +422,19 @@ async def recall(self, mid: Any, bot: Bot, context: Union[Target, Event]): message_id=mid.id, ) elif isinstance(context, GroupAtMessageCreateEvent): - if isinstance(mid,PostGroupMessagesReturn): - + if isinstance(mid, PostGroupMessagesReturn): + await bot.delete_group_message( group_openid=context.group_openid, - message_id=mid.id,#type: ignore + message_id=mid.id, # type: ignore ) elif isinstance(context, C2CMessageCreateEvent): if isinstance(mid, PostC2CMessagesReturn): await bot.delete_c2c_message( openid=context.author.id, - message_id=mid.id,#type: ignore + message_id=mid.id, # type: ignore ) - - + return def get_reply(self, mid: Any): From 02503fe4069e666efd09fc8c9325b02241bbdc05 Mon Sep 17 00:00:00 2001 From: Decrabbit Date: Fri, 9 Aug 2024 17:50:35 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=88=A4=E6=96=AD=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E4=B8=BAtarget?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../uniseg/adapters/qq/exporter.py | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/nonebot_plugin_alconna/uniseg/adapters/qq/exporter.py b/src/nonebot_plugin_alconna/uniseg/adapters/qq/exporter.py index 41e6f11..6897a10 100644 --- a/src/nonebot_plugin_alconna/uniseg/adapters/qq/exporter.py +++ b/src/nonebot_plugin_alconna/uniseg/adapters/qq/exporter.py @@ -49,7 +49,6 @@ @dataclass class ButtonSegment(MessageSegment): - @override def __str__(self) -> str: return "<$qq.button>" @@ -57,7 +56,6 @@ def __str__(self) -> str: @dataclass class ButtonRowSegment(MessageSegment): - @override def __str__(self) -> str: return "<$qq.button_row>" @@ -379,7 +377,10 @@ async def send_to(self, target: Union[Target, Event], bot: Bot, message: Message # 私信需要使用 post_dms_messages # https://bot.q.qq.com/wiki/develop/api/openapi/dms/post_dms_messages.html#%E5%8F%91%E9%80%81%E7%A7%81%E4%BF%A1 return await bot.send_to_dms( - guild_id=dms.guild_id, message=message, msg_id=target.source, **kwargs # type: ignore + guild_id=dms.guild_id, + message=message, + msg_id=target.source, + **kwargs, # type: ignore ) return await bot.send_to_channel(channel_id=target.id, message=message, msg_id=target.source, **kwargs) if target.private: @@ -421,15 +422,26 @@ async def recall(self, mid: Any, bot: Bot, context: Union[Target, Event]): channel_id=mid.channel_id, message_id=mid.id, ) - elif isinstance(context, GroupAtMessageCreateEvent): - if isinstance(mid, PostGroupMessagesReturn): - + elif isinstance(mid, PostGroupMessagesReturn): + if isinstance(context, Target): + if not context.private: + await bot.delete_group_message( + group_openid=context.id, + message_id=mid.id, # type: ignore + ) + else: await bot.delete_group_message( group_openid=context.group_openid, message_id=mid.id, # type: ignore ) - elif isinstance(context, C2CMessageCreateEvent): - if isinstance(mid, PostC2CMessagesReturn): + elif isinstance(mid, PostC2CMessagesReturn): + if isinstance(context, Target): + if context.private: + await bot.delete_group_message( + group_openid=context.id, + message_id=mid.id, # type: ignore + ) + else: await bot.delete_c2c_message( openid=context.author.id, message_id=mid.id, # type: ignore From 6d3ba11ffc7550a7f985f3afc8f40a59c25778e1 Mon Sep 17 00:00:00 2001 From: Decrabbit Date: Fri, 9 Aug 2024 17:54:27 +0800 Subject: [PATCH 4/5] fix bug --- src/nonebot_plugin_alconna/uniseg/adapters/qq/exporter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nonebot_plugin_alconna/uniseg/adapters/qq/exporter.py b/src/nonebot_plugin_alconna/uniseg/adapters/qq/exporter.py index 6897a10..afcdc60 100644 --- a/src/nonebot_plugin_alconna/uniseg/adapters/qq/exporter.py +++ b/src/nonebot_plugin_alconna/uniseg/adapters/qq/exporter.py @@ -437,8 +437,8 @@ async def recall(self, mid: Any, bot: Bot, context: Union[Target, Event]): elif isinstance(mid, PostC2CMessagesReturn): if isinstance(context, Target): if context.private: - await bot.delete_group_message( - group_openid=context.id, + await bot.delete_c2c_message( + openid=context.id, message_id=mid.id, # type: ignore ) else: From 8e564f5f57f9f0114ca6dd1763728b1fb797295c Mon Sep 17 00:00:00 2001 From: Decrabbit Date: Fri, 9 Aug 2024 19:06:31 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E8=AE=A9=E7=B1=BB=E5=9E=8B=E5=A5=BD?= =?UTF-8?q?=E7=9C=8B=E7=82=B9qw?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/nonebot_plugin_alconna/uniseg/adapters/qq/exporter.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/nonebot_plugin_alconna/uniseg/adapters/qq/exporter.py b/src/nonebot_plugin_alconna/uniseg/adapters/qq/exporter.py index afcdc60..5811356 100644 --- a/src/nonebot_plugin_alconna/uniseg/adapters/qq/exporter.py +++ b/src/nonebot_plugin_alconna/uniseg/adapters/qq/exporter.py @@ -377,7 +377,7 @@ async def send_to(self, target: Union[Target, Event], bot: Bot, message: Message # 私信需要使用 post_dms_messages # https://bot.q.qq.com/wiki/develop/api/openapi/dms/post_dms_messages.html#%E5%8F%91%E9%80%81%E7%A7%81%E4%BF%A1 return await bot.send_to_dms( - guild_id=dms.guild_id, + guild_id=dms.guild_id, # type: ignore message=message, msg_id=target.source, **kwargs, # type: ignore @@ -429,7 +429,7 @@ async def recall(self, mid: Any, bot: Bot, context: Union[Target, Event]): group_openid=context.id, message_id=mid.id, # type: ignore ) - else: + elif isinstance(context, GroupAtMessageCreateEvent): await bot.delete_group_message( group_openid=context.group_openid, message_id=mid.id, # type: ignore @@ -441,7 +441,7 @@ async def recall(self, mid: Any, bot: Bot, context: Union[Target, Event]): openid=context.id, message_id=mid.id, # type: ignore ) - else: + elif isinstance(context, C2CMessageCreateEvent): await bot.delete_c2c_message( openid=context.author.id, message_id=mid.id, # type: ignore