mirror of
https://github.com/xfgryujk/blivechat.git
synced 2025-04-03 16:10:35 +08:00
完善插件消息
This commit is contained in:
parent
be5b49fae4
commit
263bf80546
@ -68,7 +68,8 @@ def make_text_message_data(
|
|||||||
translation: str = '',
|
translation: str = '',
|
||||||
content_type: int = ContentType.TEXT,
|
content_type: int = ContentType.TEXT,
|
||||||
content_type_params: list = None,
|
content_type_params: list = None,
|
||||||
uid: int = 0
|
uid: int = 0,
|
||||||
|
medal_name: str = '',
|
||||||
):
|
):
|
||||||
# 为了节省带宽用list而不是dict
|
# 为了节省带宽用list而不是dict
|
||||||
return [
|
return [
|
||||||
@ -105,7 +106,9 @@ def make_text_message_data(
|
|||||||
# 15: textEmoticons
|
# 15: textEmoticons
|
||||||
[], # 已废弃,保留
|
[], # 已废弃,保留
|
||||||
# 16: uid
|
# 16: uid
|
||||||
uid
|
uid,
|
||||||
|
# 17: medalName
|
||||||
|
medal_name,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -217,6 +217,10 @@ class AddTextMsg:
|
|||||||
"""内容类型,见ContentType"""
|
"""内容类型,见ContentType"""
|
||||||
content_type_params: Union[dict, list] = dataclasses.field(default_factory=dict)
|
content_type_params: Union[dict, list] = dataclasses.field(default_factory=dict)
|
||||||
"""跟内容类型相关的参数"""
|
"""跟内容类型相关的参数"""
|
||||||
|
uid: int = 0
|
||||||
|
"""用户ID"""
|
||||||
|
medal_name: str = ''
|
||||||
|
"""勋章名"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_command(cls, data: list):
|
def from_command(cls, data: list):
|
||||||
@ -241,6 +245,8 @@ class AddTextMsg:
|
|||||||
translation=data[12],
|
translation=data[12],
|
||||||
content_type=content_type,
|
content_type=content_type,
|
||||||
content_type_params=content_type_params,
|
content_type_params=content_type_params,
|
||||||
|
uid=data[16],
|
||||||
|
medal_name=data[17],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -257,11 +263,25 @@ class AddGiftMsg:
|
|||||||
author_name: str = ''
|
author_name: str = ''
|
||||||
"""用户名"""
|
"""用户名"""
|
||||||
total_coin: int = 0
|
total_coin: int = 0
|
||||||
"""总价瓜子数,1000金瓜子 = 1元"""
|
"""总价付费瓜子数,1000金瓜子 = 1元"""
|
||||||
|
total_free_coin: int = 0
|
||||||
|
"""总价免费瓜子数"""
|
||||||
gift_name: str = ''
|
gift_name: str = ''
|
||||||
"""礼物名"""
|
"""礼物名"""
|
||||||
num: int = 0
|
num: int = 0
|
||||||
"""数量"""
|
"""数量"""
|
||||||
|
gift_id: int = 0
|
||||||
|
"""礼物ID"""
|
||||||
|
gift_icon_url: str = ''
|
||||||
|
"""礼物图标URL"""
|
||||||
|
uid: int = 0
|
||||||
|
"""用户ID"""
|
||||||
|
privilege_type: int = GuardLevel.NONE.value
|
||||||
|
"""舰队等级,见GuardLevel"""
|
||||||
|
medal_level: int = 0
|
||||||
|
"""勋章等级,如果没戴当前房间勋章则为0"""
|
||||||
|
medal_name: str = ''
|
||||||
|
"""勋章名"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_command(cls, data: dict):
|
def from_command(cls, data: dict):
|
||||||
@ -271,8 +291,15 @@ class AddGiftMsg:
|
|||||||
timestamp=data['timestamp'],
|
timestamp=data['timestamp'],
|
||||||
author_name=data['authorName'],
|
author_name=data['authorName'],
|
||||||
total_coin=data['totalCoin'],
|
total_coin=data['totalCoin'],
|
||||||
|
total_free_coin=data['totalFreeCoin'],
|
||||||
gift_name=data['giftName'],
|
gift_name=data['giftName'],
|
||||||
num=data['num'],
|
num=data['num'],
|
||||||
|
gift_id=data['giftId'],
|
||||||
|
gift_icon_url=data['giftIconUrl'],
|
||||||
|
uid=data['uid'],
|
||||||
|
privilege_type=data['privilegeType'],
|
||||||
|
medal_level=data['medalLevel'],
|
||||||
|
medal_name=data['medalName'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -290,6 +317,16 @@ class AddMemberMsg:
|
|||||||
"""用户名"""
|
"""用户名"""
|
||||||
privilege_type: int = GuardLevel.NONE.value
|
privilege_type: int = GuardLevel.NONE.value
|
||||||
"""舰队等级,见GuardLevel"""
|
"""舰队等级,见GuardLevel"""
|
||||||
|
num: int = 0
|
||||||
|
"""数量"""
|
||||||
|
unit: str = ''
|
||||||
|
"""单位(月)"""
|
||||||
|
uid: int = 0
|
||||||
|
"""用户ID"""
|
||||||
|
medal_level: int = 0
|
||||||
|
"""勋章等级,如果没戴当前房间勋章则为0"""
|
||||||
|
medal_name: str = ''
|
||||||
|
"""勋章名"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_command(cls, data: dict):
|
def from_command(cls, data: dict):
|
||||||
@ -299,6 +336,11 @@ class AddMemberMsg:
|
|||||||
timestamp=data['timestamp'],
|
timestamp=data['timestamp'],
|
||||||
author_name=data['authorName'],
|
author_name=data['authorName'],
|
||||||
privilege_type=data['privilegeType'],
|
privilege_type=data['privilegeType'],
|
||||||
|
num=data['num'],
|
||||||
|
unit=data['unit'],
|
||||||
|
uid=data['uid'],
|
||||||
|
medal_level=data['medalLevel'],
|
||||||
|
medal_name=data['medalName'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -320,6 +362,14 @@ class AddSuperChatMsg:
|
|||||||
"""内容"""
|
"""内容"""
|
||||||
translation: str = ''
|
translation: str = ''
|
||||||
"""内容翻译"""
|
"""内容翻译"""
|
||||||
|
uid: int = 0
|
||||||
|
"""用户ID"""
|
||||||
|
privilege_type: int = GuardLevel.NONE.value
|
||||||
|
"""舰队等级,见GuardLevel"""
|
||||||
|
medal_level: int = 0
|
||||||
|
"""勋章等级,如果没戴当前房间勋章则为0"""
|
||||||
|
medal_name: str = ''
|
||||||
|
"""勋章名"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_command(cls, data: dict):
|
def from_command(cls, data: dict):
|
||||||
@ -331,6 +381,10 @@ class AddSuperChatMsg:
|
|||||||
price=data['price'],
|
price=data['price'],
|
||||||
content=data['content'],
|
content=data['content'],
|
||||||
translation=data['translation'],
|
translation=data['translation'],
|
||||||
|
uid=data['uid'],
|
||||||
|
privilege_type=data['privilegeType'],
|
||||||
|
medal_level=data['medalLevel'],
|
||||||
|
medal_name=data['medalName'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -144,6 +144,10 @@ export default class ChatClientRelay {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
case COMMAND_ADD_GIFT: {
|
case COMMAND_ADD_GIFT: {
|
||||||
|
// TODO 显示免费礼物
|
||||||
|
if (data.totalCoin === 0) { // 丢人
|
||||||
|
return
|
||||||
|
}
|
||||||
data = new chatModels.AddGiftMsg(data)
|
data = new chatModels.AddGiftMsg(data)
|
||||||
this.msgHandler.onAddGift(data)
|
this.msgHandler.onAddGift(data)
|
||||||
break
|
break
|
||||||
|
@ -75,10 +75,17 @@ class MsgHandler(blcsdk.BaseHandler):
|
|||||||
if extra.is_from_plugin:
|
if extra.is_from_plugin:
|
||||||
return
|
return
|
||||||
room = _get_or_add_room(extra.room_id)
|
room = _get_or_add_room(extra.room_id)
|
||||||
room.log(
|
if message.total_coin != 0:
|
||||||
f'[gift] {message.author_name} 赠送了 {message.gift_name} x {message.num},'
|
content = (
|
||||||
f'总价 {message.total_coin / 1000} 元'
|
f'[paid_gift] {message.author_name} 赠送了 {message.gift_name} x {message.num},'
|
||||||
)
|
f'总价 {message.total_coin / 1000} 元'
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
content = (
|
||||||
|
f'[free_gift] {message.author_name} 赠送了 {message.gift_name} x {message.num},'
|
||||||
|
f'总价 {message.total_free_coin} 银瓜子'
|
||||||
|
)
|
||||||
|
room.log(content)
|
||||||
|
|
||||||
def _on_add_member(
|
def _on_add_member(
|
||||||
self, client: blcsdk.BlcPluginClient, message: sdk_models.AddMemberMsg, extra: sdk_models.ExtraData
|
self, client: blcsdk.BlcPluginClient, message: sdk_models.AddMemberMsg, extra: sdk_models.ExtraData
|
||||||
@ -94,8 +101,7 @@ class MsgHandler(blcsdk.BaseHandler):
|
|||||||
guard_name = '总督'
|
guard_name = '总督'
|
||||||
else:
|
else:
|
||||||
guard_name = '未知舰队等级'
|
guard_name = '未知舰队等级'
|
||||||
# TODO 可以加上时长
|
room.log(f'[guard] {message.author_name} 购买了 {message.num}{message.unit} {guard_name}')
|
||||||
room.log(f'[guard] {message.author_name} 购买了 {guard_name}')
|
|
||||||
|
|
||||||
def _on_add_super_chat(
|
def _on_add_super_chat(
|
||||||
self, client: blcsdk.BlcPluginClient, message: sdk_models.AddSuperChatMsg, extra: sdk_models.ExtraData
|
self, client: blcsdk.BlcPluginClient, message: sdk_models.AddSuperChatMsg, extra: sdk_models.ExtraData
|
||||||
|
@ -525,7 +525,9 @@ class LiveMsgHandler(blivedm.BaseHandler):
|
|||||||
translation=translation,
|
translation=translation,
|
||||||
content_type=content_type,
|
content_type=content_type,
|
||||||
content_type_params=content_type_params,
|
content_type_params=content_type_params,
|
||||||
uid=message.uid
|
# 给插件用的字段
|
||||||
|
uid=message.uid,
|
||||||
|
medal_name='' if message.medal_room_id != client.room_id else message.medal_name,
|
||||||
)
|
)
|
||||||
room.send_cmd_data(api.chat.Command.ADD_TEXT, data)
|
room.send_cmd_data(api.chat.Command.ADD_TEXT, data)
|
||||||
services.plugin.broadcast_cmd_data(
|
services.plugin.broadcast_cmd_data(
|
||||||
@ -539,23 +541,27 @@ class LiveMsgHandler(blivedm.BaseHandler):
|
|||||||
avatar_url = services.avatar.process_avatar_url(message.face)
|
avatar_url = services.avatar.process_avatar_url(message.face)
|
||||||
services.avatar.update_avatar_cache_if_expired(message.uid, avatar_url)
|
services.avatar.update_avatar_cache_if_expired(message.uid, avatar_url)
|
||||||
|
|
||||||
# 丢人
|
|
||||||
if message.coin_type != 'gold':
|
|
||||||
return
|
|
||||||
|
|
||||||
room = client_room_manager.get_room(client.room_key)
|
room = client_room_manager.get_room(client.room_key)
|
||||||
if room is None:
|
if room is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
is_paid_gift = message.coin_type == 'gold'
|
||||||
data = {
|
data = {
|
||||||
'id': uuid.uuid4().hex,
|
'id': uuid.uuid4().hex,
|
||||||
'avatarUrl': avatar_url,
|
'avatarUrl': avatar_url,
|
||||||
'timestamp': message.timestamp,
|
'timestamp': message.timestamp,
|
||||||
'authorName': message.uname,
|
'authorName': message.uname,
|
||||||
'totalCoin': message.total_coin,
|
'totalCoin': 0 if not is_paid_gift else message.total_coin,
|
||||||
|
'totalFreeCoin': 0 if is_paid_gift else message.total_coin,
|
||||||
'giftName': message.gift_name,
|
'giftName': message.gift_name,
|
||||||
'num': message.num,
|
'num': message.num,
|
||||||
'uid': message.uid
|
# 给插件用的字段
|
||||||
|
'giftId': message.gift_id,
|
||||||
|
'giftIconUrl': '',
|
||||||
|
'uid': message.uid,
|
||||||
|
'privilegeType': message.guard_level,
|
||||||
|
'medalLevel': 0,
|
||||||
|
'medalName': '',
|
||||||
}
|
}
|
||||||
room.send_cmd_data(api.chat.Command.ADD_GIFT, data)
|
room.send_cmd_data(api.chat.Command.ADD_GIFT, data)
|
||||||
services.plugin.broadcast_cmd_data(
|
services.plugin.broadcast_cmd_data(
|
||||||
@ -580,7 +586,12 @@ class LiveMsgHandler(blivedm.BaseHandler):
|
|||||||
'timestamp': message.start_time,
|
'timestamp': message.start_time,
|
||||||
'authorName': message.username,
|
'authorName': message.username,
|
||||||
'privilegeType': message.guard_level,
|
'privilegeType': message.guard_level,
|
||||||
'uid': message.uid
|
# 给插件用的字段
|
||||||
|
'num': message.num,
|
||||||
|
'unit': '月', # 单位在USER_TOAST_MSG消息里,不想改消息。现在没有别的单位,web接口也很少有人用了,先写死吧
|
||||||
|
'uid': message.uid,
|
||||||
|
'medalLevel': 0,
|
||||||
|
'medalName': '',
|
||||||
}
|
}
|
||||||
room.send_cmd_data(api.chat.Command.ADD_MEMBER, data)
|
room.send_cmd_data(api.chat.Command.ADD_MEMBER, data)
|
||||||
services.plugin.broadcast_cmd_data(
|
services.plugin.broadcast_cmd_data(
|
||||||
@ -615,7 +626,11 @@ class LiveMsgHandler(blivedm.BaseHandler):
|
|||||||
'price': message.price,
|
'price': message.price,
|
||||||
'content': message.message,
|
'content': message.message,
|
||||||
'translation': translation,
|
'translation': translation,
|
||||||
'uid': message.uid
|
# 给插件用的字段
|
||||||
|
'uid': message.uid,
|
||||||
|
'privilegeType': message.guard_level,
|
||||||
|
'medalLevel': 0,
|
||||||
|
'medalName': '',
|
||||||
}
|
}
|
||||||
room.send_cmd_data(api.chat.Command.ADD_SUPER_CHAT, data)
|
room.send_cmd_data(api.chat.Command.ADD_SUPER_CHAT, data)
|
||||||
services.plugin.broadcast_cmd_data(
|
services.plugin.broadcast_cmd_data(
|
||||||
@ -722,7 +737,9 @@ class LiveMsgHandler(blivedm.BaseHandler):
|
|||||||
translation=translation,
|
translation=translation,
|
||||||
content_type=content_type,
|
content_type=content_type,
|
||||||
content_type_params=content_type_params,
|
content_type_params=content_type_params,
|
||||||
uid=message.uid
|
# 给插件用的字段
|
||||||
|
uid=message.uid,
|
||||||
|
medal_name='' if not message.fans_medal_wearing_status else message.fans_medal_name,
|
||||||
)
|
)
|
||||||
room.send_cmd_data(api.chat.Command.ADD_TEXT, data)
|
room.send_cmd_data(api.chat.Command.ADD_TEXT, data)
|
||||||
services.plugin.broadcast_cmd_data(
|
services.plugin.broadcast_cmd_data(
|
||||||
@ -736,23 +753,27 @@ class LiveMsgHandler(blivedm.BaseHandler):
|
|||||||
avatar_url = services.avatar.process_avatar_url(message.uface)
|
avatar_url = services.avatar.process_avatar_url(message.uface)
|
||||||
services.avatar.update_avatar_cache_if_expired(message.uid, avatar_url)
|
services.avatar.update_avatar_cache_if_expired(message.uid, avatar_url)
|
||||||
|
|
||||||
# 丢人
|
|
||||||
if not message.paid:
|
|
||||||
return
|
|
||||||
|
|
||||||
room = client_room_manager.get_room(client.room_key)
|
room = client_room_manager.get_room(client.room_key)
|
||||||
if room is None:
|
if room is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
total_coin = message.price * message.gift_num
|
||||||
data = {
|
data = {
|
||||||
'id': message.msg_id,
|
'id': message.msg_id,
|
||||||
'avatarUrl': avatar_url,
|
'avatarUrl': avatar_url,
|
||||||
'timestamp': message.timestamp,
|
'timestamp': message.timestamp,
|
||||||
'authorName': message.uname,
|
'authorName': message.uname,
|
||||||
'totalCoin': message.price * message.gift_num,
|
'totalCoin': 0 if not message.paid else total_coin,
|
||||||
|
'totalFreeCoin': 0 if message.paid else total_coin,
|
||||||
'giftName': message.gift_name,
|
'giftName': message.gift_name,
|
||||||
'num': message.gift_num,
|
'num': message.gift_num,
|
||||||
'uid': message.uid
|
# 给插件用的字段
|
||||||
|
'giftId': message.gift_id,
|
||||||
|
'giftIconUrl': message.gift_icon,
|
||||||
|
'uid': message.uid,
|
||||||
|
'privilegeType': message.guard_level,
|
||||||
|
'medalLevel': 0 if not message.fans_medal_wearing_status else message.fans_medal_level,
|
||||||
|
'medalName': '' if not message.fans_medal_wearing_status else message.fans_medal_name,
|
||||||
}
|
}
|
||||||
room.send_cmd_data(api.chat.Command.ADD_GIFT, data)
|
room.send_cmd_data(api.chat.Command.ADD_GIFT, data)
|
||||||
services.plugin.broadcast_cmd_data(
|
services.plugin.broadcast_cmd_data(
|
||||||
@ -773,7 +794,12 @@ class LiveMsgHandler(blivedm.BaseHandler):
|
|||||||
'timestamp': message.timestamp,
|
'timestamp': message.timestamp,
|
||||||
'authorName': message.user_info.uname,
|
'authorName': message.user_info.uname,
|
||||||
'privilegeType': message.guard_level,
|
'privilegeType': message.guard_level,
|
||||||
'uid': message.user_info.uid
|
# 给插件用的字段
|
||||||
|
'num': message.guard_num,
|
||||||
|
'unit': message.guard_unit,
|
||||||
|
'uid': message.user_info.uid,
|
||||||
|
'medalLevel': 0 if not message.fans_medal_wearing_status else message.fans_medal_level,
|
||||||
|
'medalName': '' if not message.fans_medal_wearing_status else message.fans_medal_name,
|
||||||
}
|
}
|
||||||
room.send_cmd_data(api.chat.Command.ADD_MEMBER, data)
|
room.send_cmd_data(api.chat.Command.ADD_MEMBER, data)
|
||||||
services.plugin.broadcast_cmd_data(
|
services.plugin.broadcast_cmd_data(
|
||||||
@ -808,7 +834,11 @@ class LiveMsgHandler(blivedm.BaseHandler):
|
|||||||
'price': message.rmb,
|
'price': message.rmb,
|
||||||
'content': message.message,
|
'content': message.message,
|
||||||
'translation': translation,
|
'translation': translation,
|
||||||
'uid': message.uid
|
# 给插件用的字段
|
||||||
|
'uid': message.uid,
|
||||||
|
'privilegeType': message.guard_level,
|
||||||
|
'medalLevel': 0 if not message.fans_medal_wearing_status else message.fans_medal_level,
|
||||||
|
'medalName': '' if not message.fans_medal_wearing_status else message.fans_medal_name,
|
||||||
}
|
}
|
||||||
room.send_cmd_data(api.chat.Command.ADD_SUPER_CHAT, data)
|
room.send_cmd_data(api.chat.Command.ADD_SUPER_CHAT, data)
|
||||||
services.plugin.broadcast_cmd_data(
|
services.plugin.broadcast_cmd_data(
|
||||||
|
Loading…
Reference in New Issue
Block a user