开放平台接口修正礼物价格,web接口支持显示头像、修正上舰消息的单位

This commit is contained in:
John Smith 2024-12-23 21:21:52 +08:00
parent 7f77fdd889
commit 3273fb4d34
4 changed files with 34 additions and 14 deletions

@ -1 +1 @@
Subproject commit f9b6dc2f353f574dc7ae757be63ccacf6c93d06f
Subproject commit 68eae6b6aa1ddde660d317fbccf82cd7edbecd98

View File

@ -261,7 +261,7 @@ export default class ChatClientDirectOpenLive extends ChatClientOfficialBase {
sendGiftCallback(command) {
let data = command.data
let totalCoin = data.price * data.gift_num
let totalCoin = data.r_price * data.gift_num
data = new chatModels.AddGiftMsg({
id: data.msg_id,
avatarUrl: chat.processAvatarUrl(data.uface),

View File

@ -70,6 +70,12 @@ export default class ChatClientDirectWeb extends ChatClientOfficialBase {
async danmuMsgCallback(command) {
let info = command.info
let modeInfo = info[0][15]
let avatarUrl = modeInfo?.user?.base?.face ?? ''
if (!avatarUrl) {
avatarUrl = await chat.getAvatarUrl(uid, authorName)
}
let roomId, medalLevel
if (info[3]) {
roomId = info[3][3]
@ -95,7 +101,7 @@ export default class ChatClientDirectWeb extends ChatClientOfficialBase {
let authorName = info[2][1]
let content = info[1]
let data = new chatModels.AddTextMsg({
avatarUrl: await chat.getAvatarUrl(uid, authorName),
avatarUrl: avatarUrl,
timestamp: info[0][4] / 1000,
authorName: authorName,
authorType: authorType,
@ -126,13 +132,25 @@ export default class ChatClientDirectWeb extends ChatClientOfficialBase {
this.msgHandler.onAddGift(data)
}
async guardBuyCallback(command) {
async userToastV2Callback(command) {
let data = command.data
let {
sender_uinfo: {
uid,
base: {
name: username,
},
},
guard_info: {
start_time: timestamp,
guard_level: guardLevel,
},
} = data
data = new chatModels.AddMemberMsg({
avatarUrl: await chat.getAvatarUrl(data.uid, data.username),
timestamp: data.start_time,
authorName: data.username,
privilegeType: data.guard_level
avatarUrl: await chat.getAvatarUrl(uid, username),
timestamp: timestamp,
authorName: username,
privilegeType: guardLevel,
})
this.msgHandler.onAddMember(data)
}
@ -163,7 +181,7 @@ export default class ChatClientDirectWeb extends ChatClientOfficialBase {
const CMD_CALLBACK_MAP = {
DANMU_MSG: ChatClientDirectWeb.prototype.danmuMsgCallback,
SEND_GIFT: ChatClientDirectWeb.prototype.sendGiftCallback,
GUARD_BUY: ChatClientDirectWeb.prototype.guardBuyCallback,
USER_TOAST_MSG_V2: ChatClientDirectWeb.prototype.userToastV2Callback,
SUPER_CHAT_MESSAGE: ChatClientDirectWeb.prototype.superChatMessageCallback,
SUPER_CHAT_MESSAGE_DELETE: ChatClientDirectWeb.prototype.superChatMessageDeleteCallback
}

View File

@ -508,7 +508,9 @@ class LiveMsgHandler(blivedm.BaseHandler):
async def __on_danmaku(self, client: WebLiveClient, message: dm_web_models.DanmakuMessage):
# 先异步调用再获取房间,因为返回时房间可能已经不存在了
avatar_url = await services.avatar.get_avatar_url(message.uid, message.uname)
avatar_url = message.face
if avatar_url == '':
avatar_url = await services.avatar.get_avatar_url(message.uid, message.uname)
room = client_room_manager.get_room(client.room_key)
if room is None:
@ -605,11 +607,11 @@ class LiveMsgHandler(blivedm.BaseHandler):
sdk_models.Command.ADD_GIFT, data, make_plugin_msg_extra_from_live_client(client)
)
def _on_buy_guard(self, client: WebLiveClient, message: dm_web_models.GuardBuyMessage):
def _on_user_toast_v2(self, client: WebLiveClient, message: dm_web_models.UserToastV2Message):
utils.async_io.create_task_with_ref(self.__on_buy_guard(client, message))
@staticmethod
async def __on_buy_guard(client: WebLiveClient, message: dm_web_models.GuardBuyMessage):
async def __on_buy_guard(client: WebLiveClient, message: dm_web_models.UserToastV2Message):
# 先异步调用再获取房间,因为返回时房间可能已经不存在了
avatar_url = await services.avatar.get_avatar_url(message.uid, message.username)
@ -625,7 +627,7 @@ class LiveMsgHandler(blivedm.BaseHandler):
'privilegeType': message.guard_level,
# 给插件用的字段
'num': message.num,
'unit': '', # 单位在USER_TOAST_MSG消息里不想改消息。现在没有别的单位web接口也很少有人用了先写死吧
'unit': message.unit,
'total_coin': message.price * message.num,
'uid': str(message.uid) if message.uid != 0 else message.username,
'medalLevel': 0,
@ -791,7 +793,7 @@ class LiveMsgHandler(blivedm.BaseHandler):
if room is None:
return
total_coin = message.price * message.gift_num
total_coin = message.r_price * message.gift_num
data = {
'id': message.msg_id,
'avatarUrl': services.avatar.process_avatar_url(message.uface),