Skip to content

Commit

Permalink
♻️ change qq user id and group id field name
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyongyu authored Nov 23, 2023
1 parent 0642c3e commit 552dc18
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions nonebot/adapters/qq/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ async def send_to_channel(

async def send_to_c2c(
self,
user_id: str,
openid: str,
message: Union[str, Message, MessageSegment],
msg_id: Optional[str] = None,
msg_seq: Optional[int] = None,
Expand Down Expand Up @@ -401,15 +401,15 @@ async def send_to_c2c(
media: Optional[Media] = None
if msg_type == 7:
media_info = await self.post_c2c_files(
user_id=user_id, srv_send_msg=False, **self._extract_qq_media(message)
openid=openid, srv_send_msg=False, **self._extract_qq_media(message)
)
media = (
Media(file_info=media_info.file_info) if media_info.file_info else None
)
kwargs["media"] = media

return await self.post_c2c_messages(
user_id=user_id,
openid=openid,
msg_type=msg_type,
msg_id=msg_id,
msg_seq=msg_seq,
Expand All @@ -419,7 +419,7 @@ async def send_to_c2c(

async def send_to_group(
self,
group_id: str,
group_openid: str,
message: Union[str, Message, MessageSegment],
msg_id: Optional[str] = None,
msg_seq: Optional[int] = None,
Expand Down Expand Up @@ -450,15 +450,17 @@ async def send_to_group(
media: Optional[Media] = None
if msg_type == 7:
media_info = await self.post_group_files(
group_id=group_id, srv_send_msg=False, **self._extract_qq_media(message)
group_openid=group_openid,
srv_send_msg=False,
**self._extract_qq_media(message),
)
media = (
Media(file_info=media_info.file_info) if media_info.file_info else None
)
kwargs["media"] = media

return await self.post_group_messages(
group_id=group_id,
group_openid=group_openid,
msg_type=msg_type,
msg_id=msg_id,
msg_seq=msg_seq,
Expand Down Expand Up @@ -490,15 +492,15 @@ async def send(
elif isinstance(event, C2CMessageCreateEvent):
event._reply_seq += 1
return await self.send_to_c2c(
user_id=event.author.id,
openid=event.author.id,
message=message,
msg_id=event.id,
msg_seq=event._reply_seq,
)
elif isinstance(event, GroupAtMessageCreateEvent):
event._reply_seq += 1
return await self.send_to_group(
group_id=event.group_id,
group_openid=event.group_openid,
message=message,
msg_id=event.id,
msg_seq=event._reply_seq,
Expand Down Expand Up @@ -1606,7 +1608,7 @@ async def put_interaction(
async def post_c2c_messages(
self,
*,
user_id: str,
openid: str,
msg_type: Literal[0, 1, 2, 3, 4, 7],
content: Optional[str] = None,
markdown: Optional[MessageMarkdown] = None,
Expand All @@ -1632,7 +1634,7 @@ async def post_c2c_messages(

request = Request(
"POST",
self.adapter.get_api_base().joinpath("v2", "users", user_id, "messages"),
self.adapter.get_api_base().joinpath("v2", "users", openid, "messages"),
json=exclude_none(
{
"msg_type": msg_type,
Expand Down Expand Up @@ -1669,15 +1671,15 @@ async def post_c2c_messages(
async def post_c2c_files(
self,
*,
user_id: str,
openid: str,
file_type: Literal[1, 2, 3, 4],
url: str,
srv_send_msg: bool = True,
file_data: None = None,
) -> PostC2CFilesReturn:
request = Request(
"POST",
self.adapter.get_api_base().joinpath("v2", "users", user_id, "files"),
self.adapter.get_api_base().joinpath("v2", "users", openid, "files"),
json=exclude_none(
{
"file_type": file_type,
Expand All @@ -1694,7 +1696,7 @@ async def post_c2c_files(
async def post_group_messages(
self,
*,
group_id: str,
group_openid: str,
msg_type: Literal[0, 1, 2, 3, 4, 7],
content: Optional[str] = None,
markdown: Optional[MessageMarkdown] = None,
Expand All @@ -1720,7 +1722,9 @@ async def post_group_messages(

request = Request(
"POST",
self.adapter.get_api_base().joinpath("v2", "groups", group_id, "messages"),
self.adapter.get_api_base().joinpath(
"v2", "groups", group_openid, "messages"
),
json=exclude_none(
{
"msg_type": msg_type,
Expand Down Expand Up @@ -1757,15 +1761,15 @@ async def post_group_messages(
async def post_group_files(
self,
*,
group_id: str,
group_openid: str,
file_type: Literal[1, 2, 3, 4],
url: str,
srv_send_msg: bool = True,
file_data: None = None,
) -> PostGroupFilesReturn:
request = Request(
"POST",
self.adapter.get_api_base().joinpath("v2", "groups", group_id, "files"),
self.adapter.get_api_base().joinpath("v2", "groups", group_openid, "files"),
json=exclude_none(
{
"file_type": file_type,
Expand Down

0 comments on commit 552dc18

Please sign in to comment.