diff --git a/bilibili_api/data/api/live.json b/bilibili_api/data/api/live.json index 042b0a66..4e296379 100644 --- a/bilibili_api/data/api/live.json +++ b/bilibili_api/data/api/live.json @@ -32,6 +32,16 @@ }, "comment": "获取房间信息(真实房间号,封禁情况等)" }, + "emoticons": { + "url": "https://api.live.bilibili.com/xlive/web-ucenter/v2/emoticon/GetEmoticons", + "method": "GET", + "verify": true, + "params": { + "platform": "const str: pc", + "room_id": "int: 房间号" + }, + "comment": "获取当前用户在本房间可用的表情包" + }, "danmu_info": { "url": "https://api.live.bilibili.com/xlive/web-room/v1/index/getDanmuInfo", "method": "GET", @@ -301,6 +311,24 @@ "csrf,csrf_token": "str: 要给两个" }, "comment": "发送直播间弹幕,有的参数不确定因为自己不搞这块没权限发一些样式的弹幕" + }, + "send_emoticon": { + "url": "https://api.live.bilibili.com/msg/send", + "method": "POST", + "verify": true, + "params": { + "roomid": "int: 真实房间号", + "color": "int: 十进制颜色,有权限限制", + "fontsize": "int: 字体大小,默认 25", + "mode": "int: 弹幕模式,1 飞行 5 顶部 4 底部", + "msg": "str: 表情包代号", + "rnd": "int: 当前时间戳", + "bubble": "int: 默认 0,功能不知", + "dm_type": "int: 默认 1,功能不知", + "emoticonOptions": " 默认 [object Object] 功能不知", + "csrf,csrf_token": "str: 要给两个" + }, + "comment": "发送直播间弹幕,有的参数不确定因为自己不搞这块没权限发一些样式的弹幕" }, "send_popular_ticket": { "url": "https://api.live.bilibili.com/xlive/general-interface/v1/rank/popularRankFreeScoreIncr", diff --git a/bilibili_api/live.py b/bilibili_api/live.py index fc6cd74e..2d168323 100644 --- a/bilibili_api/live.py +++ b/bilibili_api/live.py @@ -182,6 +182,23 @@ async def get_room_play_info(self) -> dict: self.__ruid = resp["uid"] return resp + async def get_emoticons(self) -> dict: + """ + 获取本房间可用表情包 + + Returns: + dict: 调用 API 返回的结果 + """ + api = API["info"]["emoticons"] + params = { + "platform": "pc", + "room_id": self.room_display_id, + } + resp = ( + await Api(**api, credential=self.credential).update_params(**params).result + ) + return resp + async def get_room_id(self) -> int: """ 获取直播间 id @@ -542,6 +559,35 @@ async def send_danmaku(self, danmaku: Danmaku, room_id: int = None, reply_mid: i if reply_mid: data["reply_mid"] = reply_mid return await Api(**api, credential=self.credential).update_data(**data).result + async def send_emoticon(self, emoticon: Danmaku, room_id: int = None) -> dict: + """ + 直播间发送表情包 + + Args: + emoticon (Danmaku): text为表情包代号 + + Returns: + dict: 调用 API 返回的结果 + """ + self.credential.raise_for_no_sessdata() + + api = API["operate"]["send_emoticon"] + if not room_id: + room_id = (await self.get_room_play_info())["room_id"] + + data = { + "mode": emoticon.mode, + "msg": emoticon.text, + "roomid": room_id, + "bubble": 0, + "dm_type": 1, + "rnd": int(time.time()), + "color": int(emoticon.color, 16), + "fontsize": emoticon.font_size, + "emoticonOptions": '[object Object]' + } + return await Api(**api, credential=self.credential).update_data(**data).result + async def sign_up_dahanghai(self, task_id: int = 1447) -> dict: """ 大航海签到 diff --git a/docs/modules/live.md b/docs/modules/live.md index 1c710eb4..c06c020e 100644 --- a/docs/modules/live.md +++ b/docs/modules/live.md @@ -331,6 +331,17 @@ Events: +### async def get_emoticons() + +获取本房间可用表情包 + + + +**Returns:** dict: 调用 API 返回的结果 + + + + ### async def get_room_play_info() 获取房间信息(真实房间号,封禁情况等) @@ -434,6 +445,18 @@ Events: +### async def send_emoticon() + +直播间发送表情包 + + +| name | type | description | +| - | - | - | +| emoticon | Danmaku | 弹幕类, text为表情包代号 | + +**Returns:** dict: 调用 API 返回的结果 + + ### async def send_gift_from_bag() diff --git a/tests/test_live.py b/tests/test_live.py index 8bfe126f..a225fd8d 100644 --- a/tests/test_live.py +++ b/tests/test_live.py @@ -188,3 +188,10 @@ async def test_zf_get_get_popular_ticket_num(): async def test_zg_popular_rank_free_score_incr(): return await l.send_popular_ticket() + +async def test_zh_get_emoticons(): + return await l.get_emoticons() + + +async def test_zi_send_emoticon(): + return await l.send_danmaku(Danmaku("official_147"))