Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Aug 12, 2024
2 parents 770e6e9 + 9d24239 commit 5823422
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions src/nonebot_plugin_alconna/uniseg/adapters/qq/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -48,15 +49,13 @@

@dataclass
class ButtonSegment(MessageSegment):

@override
def __str__(self) -> str:
return "<$qq.button>"


@dataclass
class ButtonRowSegment(MessageSegment):

@override
def __str__(self) -> str:
return "<$qq.button_row>"
Expand Down Expand Up @@ -172,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(
Expand Down Expand Up @@ -378,13 +378,19 @@ 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:
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,
Expand All @@ -393,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

Expand Down Expand Up @@ -420,6 +427,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):
Expand Down

0 comments on commit 5823422

Please sign in to comment.