Skip to content

Commit

Permalink
fix: 增加机器人上下麦的接口
Browse files Browse the repository at this point in the history
  • Loading branch information
veehou committed Jun 6, 2022
1 parent 3026b1c commit c32926d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
32 changes: 32 additions & 0 deletions botpy/api.py
Expand Up @@ -640,6 +640,38 @@ async def update_audio(self, channel_id: str, audio_control: audio.AudioControl)
route = Route("POST", "/channels/{channel_id}/audio", channel_id=channel_id)
return await self._http.request(route, json=payload)

async def on_microphone(self, channel_id) -> str:
"""
机器人在 channel_id 对应的语音子频道上麦。
注意:
音频接口:仅限音频类机器人才能使用,后续会根据机器人类型自动开通接口权限,现如需调用,需联系平台申请权限。
Args:
channel_id: 子频道 ID。
Returns:
返回值是一个字符串。成功执行返回空字符串
"""
route = Route("PUT", "/channels/{channel_id}/mic", channel_id=channel_id)
return await self._http.request(route)

async def off_microphone(self, channel_id) -> str:
"""
机器人在 channel_id 对应的语音子频道下麦。
注意:
音频接口:仅限音频类机器人才能使用,后续会根据机器人类型自动开通接口权限,现如需调用,需联系平台申请权限。
Args:
channel_id: 子频道 ID。
Returns:
返回值是一个字符串。成功执行返回空字符串
"""
route = Route("DELETE", "/channels/{channel_id}/mic", channel_id=channel_id)
return await self._http.request(route)

# 用户相关接口
async def me(self) -> user.User:
"""
Expand Down
7 changes: 3 additions & 4 deletions botpy/http.py
Expand Up @@ -16,7 +16,6 @@

_log = logging.getLogger()


# 请求成功的返回码
HTTP_OK_STATUS = [200, 202, 204]

Expand Down Expand Up @@ -104,9 +103,9 @@ async def request(self, route: Route, **kwargs: Any):
}
# some checking if it's a JSON request
if "json" in kwargs:
# TODO 上传本地文件 @GLGDLY
if "file_image" in kwargs["json"] and kwargs["json"]["file_image"] is not None \
and isinstance(kwargs["json"]["file_image"], bytes):
json_ = kwargs["json"]
json__get = json_.get("file_image")
if json__get and isinstance(json__get, bytes):
kwargs["data"] = FormData()
for k, v in kwargs.pop("json").items():
kwargs["data"].add_field(k, v)
Expand Down

0 comments on commit c32926d

Please sign in to comment.