From e01c88c14e9dbbcbb417c7db2a40434a133f2532 Mon Sep 17 00:00:00 2001 From: Decrabbityyy <99632363+Decrabbityyy@users.noreply.github.com> Date: Fri, 9 Aug 2024 19:14:04 +0800 Subject: [PATCH 1/2] :sparkles: support qq adapter group and c2c recall (#66) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * support qq adapter group and c2c recall * :rotating_light: auto fix by pre-commit hooks * 判断是否为target * fix bug * 让类型好看点qw --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .../uniseg/adapters/qq/exporter.py | 33 +++++++++++++++++-- 1 file changed, 30 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 fccce8c..5811356 100644 --- a/src/nonebot_plugin_alconna/uniseg/adapters/qq/exporter.py +++ b/src/nonebot_plugin_alconna/uniseg/adapters/qq/exporter.py @@ -10,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, @@ -48,7 +49,6 @@ @dataclass class ButtonSegment(MessageSegment): - @override def __str__(self) -> str: return "<$qq.button>" @@ -56,7 +56,6 @@ def __str__(self) -> str: @dataclass class ButtonRowSegment(MessageSegment): - @override def __str__(self) -> str: return "<$qq.button_row>" @@ -378,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, # type: ignore + 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: @@ -420,6 +422,31 @@ async def recall(self, mid: Any, bot: Bot, context: Union[Target, Event]): channel_id=mid.channel_id, message_id=mid.id, ) + 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 + ) + elif isinstance(context, GroupAtMessageCreateEvent): + await bot.delete_group_message( + group_openid=context.group_openid, + message_id=mid.id, # type: ignore + ) + elif isinstance(mid, PostC2CMessagesReturn): + if isinstance(context, Target): + if context.private: + await bot.delete_c2c_message( + openid=context.id, + message_id=mid.id, # type: ignore + ) + elif isinstance(context, C2CMessageCreateEvent): + await bot.delete_c2c_message( + openid=context.author.id, + message_id=mid.id, # type: ignore + ) + return def get_reply(self, mid: Any): From 9d242398231e4d7f86bf5981a01c6b5cd6b4220c Mon Sep 17 00:00:00 2001 From: Decrabbityyy <99632363+Decrabbityyy@users.noreply.github.com> Date: Sat, 10 Aug 2024 21:26:20 +0800 Subject: [PATCH 2/2] :bug: change send message for InteractionCreateEvent of qq adapter(#68) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * support qq adapter group and c2c recall * :rotating_light: auto fix by pre-commit hooks * 判断是否为target * fix bug * 让类型好看点qw * Fix: InteractionCreateEvent send message * :rotating_light: auto fix by pre-commit hooks * ok,fix indentation * :rotating_light: auto fix by pre-commit hooks --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- src/nonebot_plugin_alconna/uniseg/adapters/qq/exporter.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/nonebot_plugin_alconna/uniseg/adapters/qq/exporter.py b/src/nonebot_plugin_alconna/uniseg/adapters/qq/exporter.py index 5811356..004af1b 100644 --- a/src/nonebot_plugin_alconna/uniseg/adapters/qq/exporter.py +++ b/src/nonebot_plugin_alconna/uniseg/adapters/qq/exporter.py @@ -171,6 +171,7 @@ def get_target(self, event: Event, bot: Union[Bot, None] = None) -> Target: adapter=self.get_adapter(), self_id=bot.self_id if bot else None, scope=SupportScope.qq_api, + extra={"qq.interaction": True}, ) elif event.channel_id: return Target( @@ -387,6 +388,9 @@ async def send_to(self, target: Union[Target, Event], bot: Bot, message: Message res = await bot.send_to_c2c( openid=target.id, message=message, msg_id=target.source, msg_seq=target.extra["qq.reply_seq"], **kwargs ) + elif target.extra.get("qq.interaction", False): + res = await bot.send_to_group(group_openid=target.id, message=message, event_id=target.source, **kwargs) + return res else: res = await bot.send_to_group( group_openid=target.id, @@ -395,6 +399,7 @@ async def send_to(self, target: Union[Target, Event], bot: Bot, message: Message msg_seq=target.extra["qq.reply_seq"], **kwargs, ) + target.extra["qq.reply_seq"] += 1 return res