Skip to content

Commit

Permalink
chore: Merge pull request #864 from TZFC/emoticon
Browse files Browse the repository at this point in the history
新增获取直播间可用表情包,与直播间发送表情包功能
  • Loading branch information
Nemo2011 authored Dec 7, 2024
2 parents eeb67e8 + 7192974 commit 2617a06
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 0 deletions.
28 changes: 28 additions & 0 deletions bilibili_api/data/api/live.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
46 changes: 46 additions & 0 deletions bilibili_api/live.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
"""
大航海签到
Expand Down
23 changes: 23 additions & 0 deletions docs/modules/live.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,17 @@ Events:



### async def get_emoticons()

获取本房间可用表情包



**Returns:** dict: 调用 API 返回的结果




### async def get_room_play_info()

获取房间信息(真实房间号,封禁情况等)
Expand Down Expand Up @@ -434,6 +445,18 @@ Events:



### async def send_emoticon()

直播间发送表情包


| name | type | description |
| - | - | - |
| emoticon | Danmaku | 弹幕类, text为表情包代号 |

**Returns:** dict: 调用 API 返回的结果



### async def send_gift_from_bag()

Expand Down
7 changes: 7 additions & 0 deletions tests/test_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

0 comments on commit 2617a06

Please sign in to comment.