mirror of
https://github.com/xfgryujk/blivechat.git
synced 2024-12-26 04:41:40 +08:00
通过服务器转发支持表情
This commit is contained in:
parent
3118a7de98
commit
dedae6f083
118
api/chat.py
118
api/chat.py
@ -33,6 +33,11 @@ class Command(enum.IntEnum):
|
||||
UPDATE_TRANSLATION = 7
|
||||
|
||||
|
||||
class ContentType(enum.IntEnum):
|
||||
TEXT = 0
|
||||
EMOTICON = 1
|
||||
|
||||
|
||||
_http_session = aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=10))
|
||||
|
||||
room_manager: Optional['RoomManager'] = None
|
||||
@ -56,10 +61,11 @@ class Room(blivedm.BLiveClient, blivedm.BaseHandler):
|
||||
medal_level = 0
|
||||
medal_room_id = 0
|
||||
|
||||
# TODO 带表情信息
|
||||
message = blivedm.DanmakuMessage(
|
||||
timestamp=info[0][4],
|
||||
msg_type=info[0][9],
|
||||
dm_type=info[0][12],
|
||||
emoticon_options=info[0][13],
|
||||
|
||||
msg=info[1],
|
||||
|
||||
@ -159,6 +165,15 @@ class Room(blivedm.BLiveClient, blivedm.BaseHandler):
|
||||
else:
|
||||
author_type = 0
|
||||
|
||||
if message.dm_type == 1:
|
||||
content_type = ContentType.EMOTICON
|
||||
content_type_params = make_emoticon_params(
|
||||
message.emoticon_options_dict['url'],
|
||||
)
|
||||
else:
|
||||
content_type = ContentType.TEXT
|
||||
content_type_params = None
|
||||
|
||||
need_translate = self._need_translate(message.msg)
|
||||
if need_translate:
|
||||
translation = models.translate.get_translation_from_cache(message.msg)
|
||||
@ -173,19 +188,21 @@ class Room(blivedm.BLiveClient, blivedm.BaseHandler):
|
||||
id_ = uuid.uuid4().hex
|
||||
# 为了节省带宽用list而不是dict
|
||||
self.send_message(Command.ADD_TEXT, make_text_message(
|
||||
await models.avatar.get_avatar_url(message.uid),
|
||||
int(message.timestamp / 1000),
|
||||
message.uname,
|
||||
author_type,
|
||||
message.msg,
|
||||
message.privilege_type,
|
||||
message.msg_type,
|
||||
message.user_level,
|
||||
message.urank < 10000,
|
||||
message.mobile_verify,
|
||||
0 if message.medal_room_id != self.room_id else message.medal_level,
|
||||
id_,
|
||||
translation
|
||||
avatar_url=await models.avatar.get_avatar_url(message.uid),
|
||||
timestamp=int(message.timestamp / 1000),
|
||||
author_name=message.uname,
|
||||
author_type=author_type,
|
||||
content=message.msg,
|
||||
privilege_type=message.privilege_type,
|
||||
is_gift_danmaku=message.msg_type,
|
||||
author_level=message.user_level,
|
||||
is_newbie=message.urank < 10000,
|
||||
is_mobile_verified=message.mobile_verify,
|
||||
medal_level=0 if message.medal_room_id != self.room_id else message.medal_level,
|
||||
id_=id_,
|
||||
translation=translation,
|
||||
content_type=content_type,
|
||||
content_type_params=content_type_params,
|
||||
))
|
||||
|
||||
if need_translate:
|
||||
@ -278,7 +295,7 @@ class Room(blivedm.BLiveClient, blivedm.BaseHandler):
|
||||
|
||||
def make_text_message(avatar_url, timestamp, author_name, author_type, content, privilege_type,
|
||||
is_gift_danmaku, author_level, is_newbie, is_mobile_verified, medal_level,
|
||||
id_, translation):
|
||||
id_, translation, content_type, content_type_params):
|
||||
return [
|
||||
# 0: avatarUrl
|
||||
avatar_url,
|
||||
@ -305,7 +322,18 @@ def make_text_message(avatar_url, timestamp, author_name, author_type, content,
|
||||
# 11: id
|
||||
id_,
|
||||
# 12: translation
|
||||
translation
|
||||
translation,
|
||||
# 13: contentType
|
||||
content_type,
|
||||
# 14: contentTypeParams
|
||||
content_type_params if content_type_params is not None else [],
|
||||
]
|
||||
|
||||
|
||||
def make_emoticon_params(url):
|
||||
return [
|
||||
# 0: url
|
||||
url,
|
||||
]
|
||||
|
||||
|
||||
@ -314,7 +342,7 @@ def make_translation_message(msg_id, translation):
|
||||
# 0: id
|
||||
msg_id,
|
||||
# 1: translation
|
||||
translation
|
||||
translation,
|
||||
]
|
||||
|
||||
|
||||
@ -485,19 +513,21 @@ class ChatHandler(tornado.websocket.WebSocketHandler):
|
||||
cfg = config.get_config()
|
||||
if cfg.allow_translate_rooms and self.room_id not in cfg.allow_translate_rooms:
|
||||
self.send_message(Command.ADD_TEXT, make_text_message(
|
||||
models.avatar.DEFAULT_AVATAR_URL,
|
||||
int(time.time()),
|
||||
'blivechat',
|
||||
2,
|
||||
'Translation is not allowed in this room. Please download to use translation',
|
||||
0,
|
||||
False,
|
||||
60,
|
||||
False,
|
||||
True,
|
||||
0,
|
||||
uuid.uuid4().hex,
|
||||
''
|
||||
avatar_url=models.avatar.DEFAULT_AVATAR_URL,
|
||||
timestamp=int(time.time()),
|
||||
author_name='blivechat',
|
||||
author_type=2,
|
||||
content='Translation is not allowed in this room. Please download to use translation',
|
||||
privilege_type=0,
|
||||
is_gift_danmaku=False,
|
||||
author_level=60,
|
||||
is_newbie=False,
|
||||
is_mobile_verified=True,
|
||||
medal_level=0,
|
||||
id_=uuid.uuid4().hex,
|
||||
translation='',
|
||||
content_type=ContentType.TEXT,
|
||||
content_type_params=None,
|
||||
))
|
||||
|
||||
# 测试用
|
||||
@ -508,19 +538,21 @@ class ChatHandler(tornado.websocket.WebSocketHandler):
|
||||
'authorName': 'xfgryujk',
|
||||
}
|
||||
text_data = make_text_message(
|
||||
base_data['avatarUrl'],
|
||||
base_data['timestamp'],
|
||||
base_data['authorName'],
|
||||
0,
|
||||
'我能吞下玻璃而不伤身体',
|
||||
0,
|
||||
False,
|
||||
20,
|
||||
False,
|
||||
True,
|
||||
0,
|
||||
uuid.uuid4().hex,
|
||||
''
|
||||
avatar_url=base_data['avatarUrl'],
|
||||
timestamp=base_data['timestamp'],
|
||||
author_name=base_data['authorName'],
|
||||
author_type=0,
|
||||
content='我能吞下玻璃而不伤身体',
|
||||
privilege_type=0,
|
||||
is_gift_danmaku=False,
|
||||
author_level=20,
|
||||
is_newbie=False,
|
||||
is_mobile_verified=True,
|
||||
medal_level=0,
|
||||
id_=uuid.uuid4().hex,
|
||||
translation='',
|
||||
content_type=ContentType.TEXT,
|
||||
content_type_params=None,
|
||||
)
|
||||
member_data = {
|
||||
**base_data,
|
||||
|
@ -7,6 +7,9 @@ const COMMAND_ADD_SUPER_CHAT = 5
|
||||
const COMMAND_DEL_SUPER_CHAT = 6
|
||||
const COMMAND_UPDATE_TRANSLATION = 7
|
||||
|
||||
// const CONTENT_TYPE_TEXT = 0
|
||||
const CONTENT_TYPE_EMOTICON = 1
|
||||
|
||||
const HEARTBEAT_INTERVAL = 10 * 1000
|
||||
const RECEIVE_TIMEOUT = HEARTBEAT_INTERVAL + 5 * 1000
|
||||
|
||||
@ -122,6 +125,14 @@ export default class ChatClientRelay {
|
||||
if (!this.onAddText) {
|
||||
break
|
||||
}
|
||||
|
||||
let emoticon = null
|
||||
let contentType = data[13]
|
||||
let contentTypeParams = data[14]
|
||||
if (contentType === CONTENT_TYPE_EMOTICON) {
|
||||
emoticon = contentTypeParams[0] // TODO 改成对象?
|
||||
}
|
||||
|
||||
data = {
|
||||
avatarUrl: data[0],
|
||||
timestamp: data[1],
|
||||
@ -136,7 +147,7 @@ export default class ChatClientRelay {
|
||||
medalLevel: data[10],
|
||||
id: data[11],
|
||||
translation: data[12],
|
||||
emoticon: null // TODO 支持表情
|
||||
emoticon: emoticon
|
||||
}
|
||||
this.onAddText(data)
|
||||
break
|
||||
|
@ -19,6 +19,7 @@ const CONTENTS = [
|
||||
'有一说一,这件事大家懂的都懂,不懂的,说了你也不明白,不如不说', '让我看看', '我柜子动了,我不玩了'
|
||||
]
|
||||
|
||||
// TODO 改成对象?
|
||||
const EMOTICONS = [
|
||||
'/static/img/emoticons/233.png',
|
||||
'/static/img/emoticons/miaoa.png',
|
||||
|
@ -19,7 +19,7 @@
|
||||
</yt-live-chat-author-chip>
|
||||
<span id="message" class="style-scope yt-live-chat-text-message-renderer">
|
||||
<template v-if="!emoticon">{{ content }}</template>
|
||||
<img v-else class="small-emoji emoji yt-formatted-string style-scope yt-live-chat-text-message-renderer"
|
||||
<img v-else class="emoji yt-formatted-string style-scope yt-live-chat-text-message-renderer"
|
||||
:src="emoticon" :alt="content" shared-tooltip-text="" id="emoji"
|
||||
>
|
||||
<el-badge :value="repeated" :max="99" v-show="repeated > 1" class="style-scope yt-live-chat-text-message-renderer"
|
||||
|
@ -9,7 +9,7 @@
|
||||
</router-link>
|
||||
</div>
|
||||
<div class="version">
|
||||
v1.5.3
|
||||
v1.6.0-beta
|
||||
</div>
|
||||
<sidebar></sidebar>
|
||||
</el-aside>
|
||||
|
@ -551,7 +551,7 @@ ${!this.form.messageOnNewLine ? '' : `yt-live-chat-text-message-renderer #messag
|
||||
overflow: visible !important;
|
||||
}`}
|
||||
|
||||
yt-live-chat-text-message-renderer #message img {
|
||||
yt-live-chat-text-message-renderer #message .emoji {
|
||||
width: auto !important;
|
||||
height: ${this.form.emoticonSize}px !important;
|
||||
}`
|
||||
|
@ -467,7 +467,7 @@ yt-live-chat-text-message-renderer #message {
|
||||
border-radius: 30px;
|
||||
}
|
||||
|
||||
yt-live-chat-text-message-renderer #message img {
|
||||
yt-live-chat-text-message-renderer #message .emoji {
|
||||
width: auto !important;
|
||||
height: ${this.form.emoticonSize}px !important;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user