mirror of
https://github.com/xfgryujk/blivechat.git
synced 2024-12-26 04:41:40 +08:00
支持同时显示房管和舰长图标
This commit is contained in:
parent
a68b50e885
commit
4c8cde0b3d
48
api/chat.py
48
api/chat.py
@ -47,14 +47,29 @@ def make_message_body(cmd, data):
|
||||
).encode('utf-8')
|
||||
|
||||
|
||||
def make_text_message_data(avatar_url, timestamp, author_name, author_type, content, privilege_type,
|
||||
is_gift_danmaku, author_level, is_newbie, is_mobile_verified, medal_level,
|
||||
id_, translation, content_type, content_type_params):
|
||||
def make_text_message_data(
|
||||
avatar_url: str = services.avatar.DEFAULT_AVATAR_URL,
|
||||
timestamp: int = None,
|
||||
author_name: str = '',
|
||||
author_type: int = 0,
|
||||
content: str = '',
|
||||
privilege_type: int = 0,
|
||||
is_gift_danmaku: bool = False,
|
||||
author_level: int = 1,
|
||||
is_newbie: bool = False,
|
||||
is_mobile_verified: bool = True,
|
||||
medal_level: int = 0,
|
||||
id_: str = None,
|
||||
translation: str = '',
|
||||
content_type: int = ContentType.TEXT,
|
||||
content_type_params: list = None,
|
||||
):
|
||||
# 为了节省带宽用list而不是dict
|
||||
return [
|
||||
# 0: avatarUrl
|
||||
avatar_url,
|
||||
# 1: timestamp
|
||||
timestamp,
|
||||
timestamp if timestamp is not None else int(time.time()),
|
||||
# 2: authorName
|
||||
author_name,
|
||||
# 3: authorType
|
||||
@ -74,7 +89,7 @@ def make_text_message_data(avatar_url, timestamp, author_name, author_type, cont
|
||||
# 10: medalLevel
|
||||
medal_level,
|
||||
# 11: id
|
||||
id_,
|
||||
id_ if id_ is not None else uuid.uuid4().hex,
|
||||
# 12: translation
|
||||
translation,
|
||||
# 13: contentType
|
||||
@ -210,21 +225,10 @@ class ChatHandler(tornado.websocket.WebSocketHandler): # noqa
|
||||
cfg = config.get_config()
|
||||
if cfg.allow_translate_rooms and self.room_id not in cfg.allow_translate_rooms:
|
||||
self.send_cmd_data(Command.ADD_TEXT, make_text_message_data(
|
||||
avatar_url=services.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,
|
||||
))
|
||||
|
||||
# 测试用
|
||||
@ -238,18 +242,8 @@ class ChatHandler(tornado.websocket.WebSocketHandler): # noqa
|
||||
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,
|
||||
author_level=60,
|
||||
)
|
||||
member_data = {
|
||||
**base_data,
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "blivechat",
|
||||
"version": "v1.6.0-beta",
|
||||
"version": "1.6.0-beta",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"serve": "vue-cli-service serve",
|
||||
|
@ -36,8 +36,10 @@ const AUTHOR_TYPES = [
|
||||
function randGuardInfo() {
|
||||
let authorType = randomChoose(AUTHOR_TYPES)
|
||||
let privilegeType
|
||||
if (authorType === constants.AUTHRO_TYPE_MEMBER || authorType === constants.AUTHRO_TYPE_ADMIN) {
|
||||
if (authorType === constants.AUTHRO_TYPE_MEMBER) {
|
||||
privilegeType = randInt(1, 3)
|
||||
} else if (authorType === constants.AUTHRO_TYPE_ADMIN) {
|
||||
privilegeType = randInt(0, 3)
|
||||
} else {
|
||||
privilegeType = 0
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<yt-live-chat-author-badge-renderer :type="authorTypeText" v-if="isAdmin || privilegeType > 0">
|
||||
<yt-live-chat-author-badge-renderer :type="authorTypeText">
|
||||
<el-tooltip :content="readableAuthorTypeText" placement="top">
|
||||
<div id="image" class="style-scope yt-live-chat-author-badge-renderer">
|
||||
<yt-icon v-if="isAdmin" class="style-scope yt-live-chat-author-badge-renderer">
|
||||
|
54
frontend/src/components/ChatRenderer/AuthorChip.vue
Normal file
54
frontend/src/components/ChatRenderer/AuthorChip.vue
Normal file
@ -0,0 +1,54 @@
|
||||
<template>
|
||||
<yt-live-chat-author-chip>
|
||||
<span id="author-name" dir="auto" class="style-scope yt-live-chat-author-chip" :class="{ member: isInMemberMessage }"
|
||||
:type="authorTypeText"
|
||||
>
|
||||
<template>{{ authorName }}</template>
|
||||
<!-- 这里是已验证勋章 -->
|
||||
<span id="chip-badges" class="style-scope yt-live-chat-author-chip"></span>
|
||||
</span>
|
||||
<span id="chat-badges" class="style-scope yt-live-chat-author-chip">
|
||||
<author-badge v-if="isInMemberMessage" class="style-scope yt-live-chat-author-chip"
|
||||
:isAdmin="false" :privilegeType="privilegeType"
|
||||
></author-badge>
|
||||
<template v-else>
|
||||
<author-badge v-if="authorType === AUTHRO_TYPE_ADMIN" class="style-scope yt-live-chat-author-chip"
|
||||
isAdmin :privilegeType="0"
|
||||
></author-badge>
|
||||
<author-badge v-if="privilegeType > 0" class="style-scope yt-live-chat-author-chip"
|
||||
:isAdmin="false" :privilegeType="privilegeType"
|
||||
></author-badge>
|
||||
</template>
|
||||
</span>
|
||||
</yt-live-chat-author-chip>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import AuthorBadge from './AuthorBadge'
|
||||
import * as constants from './constants'
|
||||
|
||||
export default {
|
||||
name: 'AuthorChip',
|
||||
components: {
|
||||
AuthorBadge
|
||||
},
|
||||
props: {
|
||||
isInMemberMessage: Boolean,
|
||||
authorName: String,
|
||||
authorType: Number,
|
||||
privilegeType: Number
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
AUTHRO_TYPE_ADMIN: constants.AUTHRO_TYPE_ADMIN
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
authorTypeText() {
|
||||
return constants.AUTHOR_TYPE_TO_TEXT[this.authorType]
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style src="@/assets/css/youtube/yt-live-chat-author-chip.css"></style>
|
@ -8,18 +8,9 @@
|
||||
<div id="header-content" class="style-scope yt-live-chat-membership-item-renderer">
|
||||
<div id="header-content-primary-column" class="style-scope yt-live-chat-membership-item-renderer">
|
||||
<div id="header-content-inner-column" class="style-scope yt-live-chat-membership-item-renderer">
|
||||
<yt-live-chat-author-chip class="style-scope yt-live-chat-membership-item-renderer">
|
||||
<span id="author-name" dir="auto" class="member style-scope yt-live-chat-author-chip">
|
||||
<template>{{ authorName }}</template>
|
||||
<!-- 这里是已验证勋章 -->
|
||||
<span id="chip-badges" class="style-scope yt-live-chat-author-chip"></span>
|
||||
</span>
|
||||
<span id="chat-badges" class="style-scope yt-live-chat-author-chip">
|
||||
<author-badge class="style-scope yt-live-chat-author-chip"
|
||||
:isAdmin="false" :privilegeType="privilegeType"
|
||||
></author-badge>
|
||||
</span>
|
||||
</yt-live-chat-author-chip>
|
||||
<author-chip class="style-scope yt-live-chat-membership-item-renderer"
|
||||
isInMemberMessage :authorName="authorName" :authorType="0" :privilegeType="privilegeType"
|
||||
></author-chip>
|
||||
</div>
|
||||
<div id="header-subtext" class="style-scope yt-live-chat-membership-item-renderer">{{ title }}</div>
|
||||
</div>
|
||||
@ -31,15 +22,15 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import ImgShadow from './ImgShadow.vue'
|
||||
import AuthorBadge from './AuthorBadge.vue'
|
||||
import ImgShadow from './ImgShadow'
|
||||
import AuthorChip from './AuthorChip'
|
||||
import * as utils from '@/utils'
|
||||
|
||||
export default {
|
||||
name: 'MembershipItem',
|
||||
components: {
|
||||
ImgShadow,
|
||||
AuthorBadge
|
||||
AuthorChip
|
||||
},
|
||||
props: {
|
||||
avatarUrl: String,
|
||||
|
@ -30,7 +30,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import ImgShadow from './ImgShadow.vue'
|
||||
import ImgShadow from './ImgShadow'
|
||||
import * as constants from './constants'
|
||||
import * as utils from '@/utils'
|
||||
|
||||
|
@ -5,18 +5,9 @@
|
||||
></img-shadow>
|
||||
<div id="content" class="style-scope yt-live-chat-text-message-renderer">
|
||||
<span id="timestamp" class="style-scope yt-live-chat-text-message-renderer">{{ timeText }}</span>
|
||||
<yt-live-chat-author-chip class="style-scope yt-live-chat-text-message-renderer">
|
||||
<span id="author-name" dir="auto" class="style-scope yt-live-chat-author-chip" :type="authorTypeText">
|
||||
<template>{{ authorName }}</template>
|
||||
<!-- 这里是已验证勋章 -->
|
||||
<span id="chip-badges" class="style-scope yt-live-chat-author-chip"></span>
|
||||
</span>
|
||||
<span id="chat-badges" class="style-scope yt-live-chat-author-chip">
|
||||
<author-badge class="style-scope yt-live-chat-author-chip"
|
||||
:isAdmin="authorType === 2" :privilegeType="privilegeType"
|
||||
></author-badge>
|
||||
</span>
|
||||
</yt-live-chat-author-chip>
|
||||
<author-chip class="style-scope yt-live-chat-text-message-renderer"
|
||||
:isInMemberMessage="false" :authorName="authorName" :authorType="authorType" :privilegeType="privilegeType"
|
||||
></author-chip>
|
||||
<span id="message" class="style-scope yt-live-chat-text-message-renderer">
|
||||
<template v-if="!emoticon">{{ content }}</template>
|
||||
<img v-else class="emoji yt-formatted-string style-scope yt-live-chat-text-message-renderer"
|
||||
@ -31,8 +22,8 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import ImgShadow from './ImgShadow.vue'
|
||||
import AuthorBadge from './AuthorBadge.vue'
|
||||
import ImgShadow from './ImgShadow'
|
||||
import AuthorChip from './AuthorChip'
|
||||
import * as constants from './constants'
|
||||
import * as utils from '@/utils'
|
||||
|
||||
@ -44,7 +35,7 @@ export default {
|
||||
name: 'TextMessage',
|
||||
components: {
|
||||
ImgShadow,
|
||||
AuthorBadge
|
||||
AuthorChip
|
||||
},
|
||||
props: {
|
||||
avatarUrl: String,
|
||||
@ -99,4 +90,3 @@ yt-live-chat-text-message-renderer>#content>#message>.el-badge .el-badge__conten
|
||||
</style>
|
||||
|
||||
<style src="@/assets/css/youtube/yt-live-chat-text-message-renderer.css"></style>
|
||||
<style src="@/assets/css/youtube/yt-live-chat-author-chip.css"></style>
|
||||
|
@ -41,9 +41,9 @@
|
||||
<script>
|
||||
import * as chatConfig from '@/api/chatConfig'
|
||||
import { formatCurrency } from '@/utils'
|
||||
import ImgShadow from './ImgShadow.vue'
|
||||
import MembershipItem from './MembershipItem.vue'
|
||||
import PaidMessage from './PaidMessage.vue'
|
||||
import ImgShadow from './ImgShadow'
|
||||
import MembershipItem from './MembershipItem'
|
||||
import PaidMessage from './PaidMessage'
|
||||
import * as constants from './constants'
|
||||
|
||||
export default {
|
||||
|
@ -41,10 +41,10 @@
|
||||
|
||||
<script>
|
||||
import * as chatConfig from '@/api/chatConfig'
|
||||
import Ticker from './Ticker.vue'
|
||||
import TextMessage from './TextMessage.vue'
|
||||
import MembershipItem from './MembershipItem.vue'
|
||||
import PaidMessage from './PaidMessage.vue'
|
||||
import Ticker from './Ticker'
|
||||
import TextMessage from './TextMessage'
|
||||
import MembershipItem from './MembershipItem'
|
||||
import PaidMessage from './PaidMessage'
|
||||
import * as constants from './constants'
|
||||
|
||||
// 只有要添加的消息需要平滑
|
||||
|
@ -1,6 +1,6 @@
|
||||
module.exports = {
|
||||
chainWebpack: config => {
|
||||
const APP_VERSION = process.env.npm_package_version
|
||||
const APP_VERSION = `v${process.env.npm_package_version}`
|
||||
|
||||
config.plugin('define')
|
||||
.tap(args => {
|
||||
|
@ -319,7 +319,6 @@ class LiveMsgHandler(blivedm.BaseHandler):
|
||||
translation = ''
|
||||
|
||||
msg_id = uuid.uuid4().hex
|
||||
# 为了节省带宽用list而不是dict
|
||||
room.send_cmd_data(api.chat.Command.ADD_TEXT, api.chat.make_text_message_data(
|
||||
avatar_url=avatar_url,
|
||||
timestamp=int(message.timestamp / 1000),
|
||||
@ -327,10 +326,10 @@ class LiveMsgHandler(blivedm.BaseHandler):
|
||||
author_type=author_type,
|
||||
content=message.msg,
|
||||
privilege_type=message.privilege_type,
|
||||
is_gift_danmaku=message.msg_type,
|
||||
is_gift_danmaku=bool(message.msg_type),
|
||||
author_level=message.user_level,
|
||||
is_newbie=message.urank < 10000,
|
||||
is_mobile_verified=message.mobile_verify,
|
||||
is_mobile_verified=bool(message.mobile_verify),
|
||||
medal_level=0 if message.medal_room_id != client.room_id else message.medal_level,
|
||||
id_=msg_id,
|
||||
translation=translation,
|
||||
|
Loading…
Reference in New Issue
Block a user