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

fix some bug (maybe #152

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 最近更新

* No changes

## v0.6.0

### 破坏性变更
Expand Down
85 changes: 53 additions & 32 deletions nonebot_plugin_saa/adapters/qq.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
try:
from nonebot.adapters.qq.event import GuildMessageEvent
from nonebot.adapters.qq.models import Message as ApiMessage
from nonebot.adapters.qq.exception import AuditException, QQAdapterException
from nonebot.adapters.qq.models import (
PostC2CFilesReturn,
PostGroupFilesReturn,
Expand All @@ -52,6 +53,9 @@

MessageFactory.register_adapter_message(adapter, Message)

class QQAuditRejectException(QQAdapterException):
...

class QQMessageId(MessageId):
adapter_name: Literal[adapter] = adapter
message_id: str
Expand Down Expand Up @@ -164,6 +168,12 @@ async def send(
),
)

if isinstance(event, (C2CMessageCreateEvent, GroupAtMessageCreateEvent)):
reply = False
at_sender = (
False # qq doesnt support reply or at user in group or c2c at this time
)

full_msg = msg
if event:
assert isinstance(
Expand All @@ -184,39 +194,50 @@ async def send(
message = await full_msg._build(bot)
assert isinstance(message, Message)

if event: # reply to user
msg_return = await bot.send(event, message)
else:
msg_id = (
plugin_config.qqguild_magic_msg_id
if plugin_config.use_qqguild_magic_msg_id
else None
)
if isinstance(target, TargetQQGuildDirect):
guild_id = await QQGuildDMSManager.aget_guild_id(target, bot)
msg_return = await bot.send_to_dms(
guild_id=str(guild_id),
message=message,
msg_id=msg_id,
)
elif isinstance(target, TargetQQGuildChannel):
msg_return = await bot.send_to_channel(
channel_id=str(target.channel_id),
message=message,
msg_id=msg_id,
)
elif isinstance(target, TargetQQPrivateOpenId):
msg_return = await bot.send_to_c2c(
openid=target.user_openid,
message=message,
)
elif isinstance(target, TargetQQGroupOpenId):
msg_return = await bot.send_to_group(
group_openid=target.group_openid,
message=message,
)
try:
if event: # reply to user
msg_return = await bot.send(event, message)
else:
raise ValueError(f"{type(event)} not supported")
msg_id = (
plugin_config.qqguild_magic_msg_id
if plugin_config.use_qqguild_magic_msg_id
else None
)
if isinstance(target, TargetQQGuildDirect):
guild_id = await QQGuildDMSManager.aget_guild_id(target, bot)
msg_return = await bot.send_to_dms(
guild_id=str(guild_id),
message=message,
msg_id=msg_id,
)
elif isinstance(target, TargetQQGuildChannel):
msg_return = await bot.send_to_channel(
channel_id=str(target.channel_id),
message=message,
msg_id=msg_id,
)
elif isinstance(target, TargetQQPrivateOpenId):
msg_return = await bot.send_to_c2c(
openid=target.user_openid,
message=message,
)
elif isinstance(target, TargetQQGroupOpenId):
msg_return = await bot.send_to_group(
group_openid=target.group_openid,
message=message,
)
else:
raise ValueError(f"{type(event)} not supported")
except AuditException as e:
audit = await e.get_audit_result()
if type(audit) == "MESSAGE_AUDIT_REJECT":
raise QQAuditRejectException()
msg_return = ApiMessage(
id=audit.message_id or "",
channel_id=audit.channel_id,
guild_id=audit.guild_id,
author=bot.self_info,
)

return QQReceipt(bot_id=bot.self_id, msg_return=msg_return)

Expand Down