mirror of
https://github.com/xfgryujk/blivechat.git
synced 2025-03-13 03:10:47 +08:00
前端初始化房间时从后端接口获取文本表情
This commit is contained in:
parent
3fb1c41845
commit
cad573312b
@ -378,13 +378,13 @@ class AvatarHandler(api.base.ApiHandler):
|
||||
else:
|
||||
# 缓存1天
|
||||
self.set_header('Cache-Control', 'private, max-age=86400')
|
||||
self.write({
|
||||
'avatarUrl': avatar_url
|
||||
})
|
||||
self.write({'avatarUrl': avatar_url})
|
||||
|
||||
|
||||
class TextEmoticonMappingsHandler(api.base.ApiHandler):
|
||||
async def get(self):
|
||||
# 缓存1天
|
||||
self.set_header('Cache-Control', 'private, max-age=86400')
|
||||
cfg = config.get_config()
|
||||
self.write({'textEmoticons': cfg.text_emoticons})
|
||||
|
||||
|
@ -68,9 +68,7 @@ class UploadEmoticonHandler(api.base.ApiHandler):
|
||||
url = await asyncio.get_running_loop().run_in_executor(
|
||||
None, self._save_file, file.body, self.request.remote_ip
|
||||
)
|
||||
self.write({
|
||||
'url': url
|
||||
})
|
||||
self.write({'url': url})
|
||||
|
||||
@staticmethod
|
||||
def _save_file(body, client):
|
||||
|
@ -2,7 +2,7 @@ import axios from 'axios'
|
||||
|
||||
import { BrotliDecode } from './brotli_decode'
|
||||
import { getUuid4Hex } from '@/utils'
|
||||
import * as avatar from '../avatar'
|
||||
import * as chat from '..'
|
||||
|
||||
const HEADER_SIZE = 16
|
||||
|
||||
@ -326,7 +326,7 @@ export default class ChatClientDirect {
|
||||
let textEmoticons = this.parseTextEmoticons(info)
|
||||
|
||||
let data = {
|
||||
avatarUrl: await avatar.getAvatarUrl(uid),
|
||||
avatarUrl: await chat.getAvatarUrl(uid),
|
||||
timestamp: info[0][4] / 1000,
|
||||
authorName: info[2][1],
|
||||
authorType: authorType,
|
||||
@ -370,7 +370,7 @@ export default class ChatClientDirect {
|
||||
|
||||
data = {
|
||||
id: getUuid4Hex(),
|
||||
avatarUrl: avatar.processAvatarUrl(data.face),
|
||||
avatarUrl: chat.processAvatarUrl(data.face),
|
||||
timestamp: data.timestamp,
|
||||
authorName: data.uname,
|
||||
totalCoin: data.total_coin,
|
||||
@ -388,7 +388,7 @@ export default class ChatClientDirect {
|
||||
let data = command.data
|
||||
data = {
|
||||
id: getUuid4Hex(),
|
||||
avatarUrl: await avatar.getAvatarUrl(data.uid),
|
||||
avatarUrl: await chat.getAvatarUrl(data.uid),
|
||||
timestamp: data.start_time,
|
||||
authorName: data.username,
|
||||
privilegeType: data.guard_level
|
||||
@ -404,7 +404,7 @@ export default class ChatClientDirect {
|
||||
let data = command.data
|
||||
data = {
|
||||
id: data.id.toString(),
|
||||
avatarUrl: avatar.processAvatarUrl(data.user_info.face),
|
||||
avatarUrl: chat.processAvatarUrl(data.user_info.face),
|
||||
timestamp: data.start_time,
|
||||
authorName: data.user_info.uname,
|
||||
price: data.price,
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { getUuid4Hex } from '@/utils'
|
||||
import * as constants from '@/components/ChatRenderer/constants'
|
||||
import * as avatar from './avatar'
|
||||
import * as chat from '.'
|
||||
|
||||
const NAMES = [
|
||||
'光羊',
|
||||
@ -104,7 +104,7 @@ const MESSAGE_GENERATORS = [
|
||||
type: constants.MESSAGE_TYPE_TEXT,
|
||||
message: {
|
||||
...randGuardInfo(),
|
||||
avatarUrl: avatar.DEFAULT_AVATAR_URL,
|
||||
avatarUrl: chat.DEFAULT_AVATAR_URL,
|
||||
timestamp: new Date().getTime() / 1000,
|
||||
authorName: randomChoose(NAMES),
|
||||
content: randomChoose(CONTENTS),
|
||||
@ -129,7 +129,7 @@ const MESSAGE_GENERATORS = [
|
||||
type: constants.MESSAGE_TYPE_TEXT,
|
||||
message: {
|
||||
...randGuardInfo(),
|
||||
avatarUrl: avatar.DEFAULT_AVATAR_URL,
|
||||
avatarUrl: chat.DEFAULT_AVATAR_URL,
|
||||
timestamp: new Date().getTime() / 1000,
|
||||
authorName: randomChoose(NAMES),
|
||||
content: '',
|
||||
@ -155,7 +155,7 @@ const MESSAGE_GENERATORS = [
|
||||
message: {
|
||||
...randomChoose(GIFT_INFO_LIST),
|
||||
id: getUuid4Hex(),
|
||||
avatarUrl: avatar.DEFAULT_AVATAR_URL,
|
||||
avatarUrl: chat.DEFAULT_AVATAR_URL,
|
||||
timestamp: new Date().getTime() / 1000,
|
||||
authorName: randomChoose(NAMES),
|
||||
num: 1
|
||||
@ -171,7 +171,7 @@ const MESSAGE_GENERATORS = [
|
||||
type: constants.MESSAGE_TYPE_SUPER_CHAT,
|
||||
message: {
|
||||
id: getUuid4Hex(),
|
||||
avatarUrl: avatar.DEFAULT_AVATAR_URL,
|
||||
avatarUrl: chat.DEFAULT_AVATAR_URL,
|
||||
timestamp: new Date().getTime() / 1000,
|
||||
authorName: randomChoose(NAMES),
|
||||
price: randomChoose(SC_PRICES),
|
||||
@ -189,7 +189,7 @@ const MESSAGE_GENERATORS = [
|
||||
type: constants.MESSAGE_TYPE_MEMBER,
|
||||
message: {
|
||||
id: getUuid4Hex(),
|
||||
avatarUrl: avatar.DEFAULT_AVATAR_URL,
|
||||
avatarUrl: chat.DEFAULT_AVATAR_URL,
|
||||
timestamp: new Date().getTime() / 1000,
|
||||
authorName: randomChoose(NAMES),
|
||||
privilegeType: randInt(1, 3)
|
||||
|
@ -26,3 +26,13 @@ export async function getAvatarUrl(uid) {
|
||||
}
|
||||
return res.avatarUrl
|
||||
}
|
||||
|
||||
export async function getTextEmoticons() {
|
||||
let res
|
||||
try {
|
||||
res = (await axios.get('/api/text_emoticon_mappings')).data
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
return res.textEmoticons
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import * as avatar from '@/api/chat/avatar'
|
||||
import * as chat from '@/api/chat'
|
||||
|
||||
export default {
|
||||
name: 'ImgShadow',
|
||||
@ -26,8 +26,8 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
onLoadError() {
|
||||
if (this.showImgUrl !== avatar.DEFAULT_AVATAR_URL) {
|
||||
this.showImgUrl = avatar.DEFAULT_AVATAR_URL
|
||||
if (this.showImgUrl !== chat.DEFAULT_AVATAR_URL) {
|
||||
this.showImgUrl = chat.DEFAULT_AVATAR_URL
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import { mergeConfig, toBool, toInt } from '@/utils'
|
||||
import * as trie from '@/utils/trie'
|
||||
import * as pronunciation from '@/utils/pronunciation'
|
||||
import * as chatConfig from '@/api/chatConfig'
|
||||
import * as chat from '@/api/chat'
|
||||
import ChatClientTest from '@/api/chat/ChatClientTest'
|
||||
import ChatClientDirect from '@/api/chat/ChatClientDirect'
|
||||
import ChatClientRelay from '@/api/chat/ChatClientRelay'
|
||||
@ -34,7 +35,7 @@ export default {
|
||||
config: chatConfig.deepCloneDefaultConfig(),
|
||||
chatClient: null,
|
||||
pronunciationConverter: null,
|
||||
textEmoticons: {}, // 官方的文本表情,运行时从弹幕消息收集
|
||||
textEmoticons: [], // 官方的文本表情
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@ -60,20 +61,20 @@ export default {
|
||||
},
|
||||
emoticonsTrie() {
|
||||
let res = new trie.Trie()
|
||||
for (let emoticon of this.config.emoticons) {
|
||||
if (emoticon.keyword !== '' && emoticon.url !== '') {
|
||||
res.set(emoticon.keyword, emoticon)
|
||||
for (let emoticons of [this.config.emoticons, this.textEmoticons]) {
|
||||
for (let emoticon of emoticons) {
|
||||
if (emoticon.keyword !== '' && emoticon.url !== '') {
|
||||
res.set(emoticon.keyword, emoticon)
|
||||
}
|
||||
}
|
||||
}
|
||||
for (let emoticon of Object.values(this.textEmoticons)) {
|
||||
res.set(emoticon.keyword, emoticon)
|
||||
}
|
||||
return res
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.initConfig()
|
||||
this.initChatClient()
|
||||
this.initTextEmoticons()
|
||||
if (this.config.giftUsernamePronunciation !== '') {
|
||||
this.pronunciationConverter = new pronunciation.PronunciationConverter()
|
||||
this.pronunciationConverter.loadDict(this.config.giftUsernamePronunciation)
|
||||
@ -155,6 +156,9 @@ export default {
|
||||
this.chatClient.onUpdateTranslation = this.onUpdateTranslation
|
||||
this.chatClient.start()
|
||||
},
|
||||
async initTextEmoticons() {
|
||||
this.textEmoticons = await chat.getTextEmoticons()
|
||||
},
|
||||
|
||||
start() {
|
||||
this.chatClient.start()
|
||||
@ -167,15 +171,6 @@ export default {
|
||||
if (!this.config.showDanmaku || !this.filterTextMessage(data) || this.mergeSimilarText(data.content)) {
|
||||
return
|
||||
}
|
||||
|
||||
// 更新官方文本表情
|
||||
for (let [keyword, url] of data.textEmoticons) {
|
||||
if (!(keyword in this.textEmoticons)) {
|
||||
let emoticon = { keyword, url }
|
||||
this.$set(this.textEmoticons, keyword, emoticon)
|
||||
}
|
||||
}
|
||||
|
||||
let message = {
|
||||
id: data.id,
|
||||
type: constants.MESSAGE_TYPE_TEXT,
|
||||
@ -326,7 +321,7 @@ export default {
|
||||
}
|
||||
|
||||
// 没有文本表情,只能是纯文本
|
||||
if (this.config.emoticons.length === 0 && Object.keys(this.textEmoticons).length === 0) {
|
||||
if (this.config.emoticons.length === 0 && this.textEmoticons.length === 0) {
|
||||
richContent.push({
|
||||
type: constants.CONTENT_TYPE_TEXT,
|
||||
text: data.content
|
||||
|
@ -666,3 +666,5 @@ class LiveMsgHandler(blivedm.BaseHandler):
|
||||
translation
|
||||
)
|
||||
)
|
||||
|
||||
# TODO 开放平台消息处理
|
||||
|
Loading…
Reference in New Issue
Block a user