Skip to content

Commit

Permalink
fix: 修改get_message返回对象中多一层的message (#48)
Browse files Browse the repository at this point in the history
Co-authored-by: veehou <veehou@tencent.com>
  • Loading branch information
traveler-vee and veehou committed Apr 18, 2022
1 parent 01fb77c commit 3351b39
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 91 deletions.
25 changes: 18 additions & 7 deletions qqbot/api.py
Expand Up @@ -46,6 +46,7 @@
CreateDirectMessageRequest,
DirectMessageGuild,
MessagesPager,
MessageGet,
)
from qqbot.model.mute import MuteOption
from qqbot.model.pins_message import PinsMessage
Expand Down Expand Up @@ -421,7 +422,7 @@ def update_channel_role_permissions(
class MessageAPI(APIBase):
"""消息"""

def get_message(self, channel_id: str, message_id: str) -> Message:
def get_message(self, channel_id: str, message_id: str) -> MessageGet:
"""
获取指定消息
Expand All @@ -433,7 +434,7 @@ def get_message(self, channel_id: str, message_id: str) -> Message:
channel_id=channel_id, message_id=message_id
)
response = self.http.get(url)
return json.loads(response.content, object_hook=Message)
return json.loads(response.content, object_hook=MessageGet)

def get_messages(self, channel_id: str, pager: MessagesPager) -> List[Message]:
"""
Expand Down Expand Up @@ -694,7 +695,9 @@ def post_recommended_channels(
:param guild_id: 频道ID
:param request: RecommendChannelRequest 对象
"""
url = get_url(APIConstant.guildAnnounceURI, self.is_sandbox).format(guild_id=guild_id)
url = get_url(APIConstant.guildAnnounceURI, self.is_sandbox).format(
guild_id=guild_id
)
request_json = JsonUtil.obj2json_serialize(request)
response = self.http.post(url, request_json)
return json.loads(response.content, object_hook=Announce)
Expand Down Expand Up @@ -825,7 +828,9 @@ def delete_schedule(self, channel_id: str, schedule_id: str):
class ReactionAPI(APIBase):
"""表情表态接口"""

def put_reaction(self, channel_id: str, message_id: str, emo_type: int, emo_id: str):
def put_reaction(
self, channel_id: str, message_id: str, emo_type: int, emo_id: str
):
"""
对一条消息进行表情表态
Expand All @@ -840,7 +845,9 @@ def put_reaction(self, channel_id: str, message_id: str, emo_type: int, emo_id:
response = self.http.put(url)
return response.status_code == HttpStatus.NO_CONTENT

def delete_reaction(self, channel_id: str, message_id: str, emo_type: int, emo_id: str):
def delete_reaction(
self, channel_id: str, message_id: str, emo_type: int, emo_id: str
):
"""
删除自己对消息的进行表情表态
Expand Down Expand Up @@ -895,7 +902,9 @@ def get_pins(self, channel_id: str) -> PinsMessage:
:param channel_id: 子频道ID
"""
url = get_url(APIConstant.getPinsURI, self.is_sandbox).format(channel_id=channel_id)
url = get_url(APIConstant.getPinsURI, self.is_sandbox).format(
channel_id=channel_id
)
response = self.http.get(url)
return json.loads(response.content, object_hook=PinsMessage)

Expand All @@ -910,7 +919,9 @@ def put_interaction(self, interaction_id: str, interaction_data: InteractionData
:param interaction_id: 互动事件的ID
:param interaction_data: 互动事件数据体
"""
url = get_url(APIConstant.interactionURI, self.is_sandbox).format(interaction_id=interaction_id)
url = get_url(APIConstant.interactionURI, self.is_sandbox).format(
interaction_id=interaction_id
)
request_json = JsonUtil.obj2json_serialize(interaction_data)
response = self.http.put(url, request_json)
return response.status_code == HttpStatus.NO_CONTENT
35 changes: 25 additions & 10 deletions qqbot/async_api.py
Expand Up @@ -15,7 +15,7 @@
CreateAnnounceRequest,
Announce,
CreateChannelAnnounceRequest,
RecommendChannelRequest
RecommendChannelRequest,
)
from qqbot.model.api_permission import (
APIPermission,
Expand Down Expand Up @@ -51,6 +51,7 @@
CreateDirectMessageRequest,
DirectMessageGuild,
MessagesPager,
MessageGet,
)
from qqbot.model.mute import MuteOption
from qqbot.model.pins_message import PinsMessage
Expand Down Expand Up @@ -440,7 +441,7 @@ async def update_channel_role_permissions(
class AsyncMessageAPI(AsyncAPIBase):
"""消息"""

async def get_message(self, channel_id: str, message_id: str) -> Message:
async def get_message(self, channel_id: str, message_id: str) -> MessageGet:
"""
获取指定消息
Expand All @@ -452,7 +453,7 @@ async def get_message(self, channel_id: str, message_id: str) -> Message:
channel_id=channel_id, message_id=message_id
)
response = await self.http_async.get(url)
return json.loads(response, object_hook=Message)
return json.loads(response, object_hook=MessageGet)

async def get_messages(
self, channel_id: str, pager: MessagesPager
Expand Down Expand Up @@ -501,7 +502,9 @@ async def post_message(
response = await self.http_async.post(url, request_json)
return json.loads(response, object_hook=Message)

async def recall_message(self, channel_id: str, message_id: str, hide_tip: bool = False):
async def recall_message(
self, channel_id: str, message_id: str, hide_tip: bool = False
):
"""
撤回消息
Expand Down Expand Up @@ -714,7 +717,9 @@ async def post_recommended_channels(
:param guild_id: 频道ID
:param request: RecommendChannelRequest 对象
"""
url = get_url(APIConstant.guildAnnounceURI, self.is_sandbox).format(guild_id=guild_id)
url = get_url(APIConstant.guildAnnounceURI, self.is_sandbox).format(
guild_id=guild_id
)
request_json = JsonUtil.obj2json_serialize(request)
response = await self.http_async.post(url, request_json)
return json.loads(response, object_hook=Announce)
Expand Down Expand Up @@ -845,7 +850,9 @@ async def delete_schedule(self, channel_id: str, schedule_id: str):
class AsyncReactionAPI(AsyncAPIBase):
"""异步表情表态接口"""

async def put_reaction(self, channel_id: str, message_id: str, emo_type: int, emo_id: str):
async def put_reaction(
self, channel_id: str, message_id: str, emo_type: int, emo_id: str
):
"""
对一条消息进行表情表态
Expand All @@ -860,7 +867,9 @@ async def put_reaction(self, channel_id: str, message_id: str, emo_type: int, em
response = await self.http_async.put(url)
return response == ""

async def delete_reaction(self, channel_id: str, message_id: str, emo_type: int, emo_id: str):
async def delete_reaction(
self, channel_id: str, message_id: str, emo_type: int, emo_id: str
):
"""
删除自己对消息的进行表情表态
Expand Down Expand Up @@ -918,22 +927,28 @@ async def get_pins(self, channel_id: str) -> PinsMessage:
:param channel_id: 子频道ID
"""
url = get_url(APIConstant.getPinsURI, self.is_sandbox).format(channel_id=channel_id)
url = get_url(APIConstant.getPinsURI, self.is_sandbox).format(
channel_id=channel_id
)
response = await self.http_async.get(url)
return json.loads(response, object_hook=PinsMessage)


class AsyncInteractionAPI(AsyncAPIBase):
"""互动回调API"""

async def put_interaction(self, interaction_id: str, interaction_data: InteractionData):
async def put_interaction(
self, interaction_id: str, interaction_data: InteractionData
):
"""
对 interaction_id 进行互动回调数据异步回复更新
:param interaction_id: 互动事件的ID
:param interaction_data: 互动事件数据体
"""
url = get_url(APIConstant.interactionURI, self.is_sandbox).format(interaction_id=interaction_id)
url = get_url(APIConstant.interactionURI, self.is_sandbox).format(
interaction_id=interaction_id
)
request_json = JsonUtil.obj2json_serialize(interaction_data)
response = await self.http_async.put(url, request_json)
return response == ""

0 comments on commit 3351b39

Please sign in to comment.