Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support qq adapter group and c2c recall #66

Merged
merged 5 commits into from
Aug 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 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 @@ -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:
Expand Down Expand Up @@ -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):
Expand Down