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

🚧 添加 QQ 频道私信支持 #3

Merged
merged 2 commits into from
Feb 16, 2023
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
26 changes: 18 additions & 8 deletions nonebot_plugin_all4one/middlewares/qqguild.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def to_onebot_event(self, event: Event) -> List[OneBotEvent]:
if isinstance(event, DirectMessageCreateEvent):
event_dict["detail_type"] = "private"
event_dict["user_id"] = event.get_user_id()
# 发送私信还需要临时频道 id
event_dict["guild_id"] = event.guild_id
elif isinstance(event, MessageCreateEvent):
event_dict["detail_type"] = "channel"
event_dict["guild_id"] = event.guild_id
Expand Down Expand Up @@ -110,8 +112,8 @@ async def send_message(
message: OneBotMessage,
**kwargs: Any,
) -> Dict[Union[Literal["message_id", "time"], str], Any]:
if detail_type != "channel":
raise NotImplementedError
if detail_type not in ["private", "channel"]:
raise ob_exception.UnsupportedParam("failed", 10004, "不支持的类型", None)

message_list = []
message = parse_obj_as(OneBotMessage, message)
Expand All @@ -130,12 +132,20 @@ async def send_message(
file_image = f.read()

try:
result = await self.bot.post_messages(
channel_id=int(channel_id), # type: ignore
content=content,
msg_id=kwargs.get("event_id"),
file_image=file_image, # type: ignore
)
if detail_type == "private":
result = await self.bot.post_dms_messages(
guild_id=int(guild_id), # type: ignore
content=content,
msg_id=kwargs.get("event_id"),
file_image=file_image, # type: ignore
)
else:
result = await self.bot.post_messages(
channel_id=int(channel_id), # type: ignore
content=content,
msg_id=kwargs.get("event_id"),
file_image=file_image, # type: ignore
)
except Exception as e:
raise e
# FIXME: 如果是主动消息,返回的时间会是 None
Expand Down