mirror of
https://github.com/xfgryujk/blivechat.git
synced 2025-03-26 12:05:55 +08:00
添加用户名高亮
This commit is contained in:
parent
efcecf2715
commit
3be0e192e9
29
chat.py
29
chat.py
@ -51,6 +51,7 @@ class Room(blivedm.BLiveClient):
|
||||
super().__init__(room_id, session=http_session)
|
||||
self.future = None
|
||||
self.clients: List['ChatHandler'] = []
|
||||
self.owner_id = None
|
||||
|
||||
def start(self):
|
||||
self.future = self.run()
|
||||
@ -60,16 +61,40 @@ class Room(blivedm.BLiveClient):
|
||||
self.future.cancel()
|
||||
asyncio.ensure_future(self.close())
|
||||
|
||||
async def _get_room_id(self):
|
||||
"""重载用来获取主播UID"""
|
||||
async with self._session.get(blivedm.ROOM_INIT_URL,
|
||||
params={'id': self._short_id},
|
||||
ssl=self._ssl) as res:
|
||||
if res.status == 200:
|
||||
data = await res.json()
|
||||
if data['code'] == 0:
|
||||
self._room_id = data['data']['room_id']
|
||||
self.owner_id = data['data']['uid']
|
||||
else:
|
||||
raise ConnectionAbortedError('获取房间ID失败:' + data['msg'])
|
||||
else:
|
||||
raise ConnectionAbortedError('获取房间ID失败:' + res.reason)
|
||||
|
||||
def send_message(self, cmd, data):
|
||||
body = json.dumps({'cmd': cmd, 'data': data})
|
||||
for client in self.clients:
|
||||
client.write_message(body)
|
||||
|
||||
async def __my_on_get_danmaku(self, command):
|
||||
if command['info'][2][0] == self.owner_id:
|
||||
author_type = 3 # 主播
|
||||
elif command['info'][2][2] != 0:
|
||||
author_type = 2 # 房管
|
||||
elif command['info'][7] != 0: # 1总督,2提督,3舰长
|
||||
author_type = 1 # 舰队
|
||||
else:
|
||||
author_type = 0
|
||||
self.send_message(Command.ADD_TEXT, {
|
||||
'avatarUrl': await get_avatar_url(command['info'][2][0]),
|
||||
'timestamp': command['info'][0][4],
|
||||
'authorName': command['info'][2][1],
|
||||
'authorType': author_type,
|
||||
'content': command['info'][1]
|
||||
})
|
||||
|
||||
@ -134,12 +159,14 @@ class RoomManager:
|
||||
'avatarUrl': 'https://i0.hdslb.com/bfs/face/29b6be8aa611e70a3d3ac219cdaf5e72b604f2de.jpg@24w_24h.webp',
|
||||
'timestamp': time.time(),
|
||||
'authorName': 'xfgryujk',
|
||||
'authorType': 0,
|
||||
'content': '我能吞下玻璃而不伤身体'
|
||||
})
|
||||
room.send_message(Command.ADD_TEXT, {
|
||||
'avatarUrl': 'https://i0.hdslb.com/bfs/face/29b6be8aa611e70a3d3ac219cdaf5e72b604f2de.jpg@24w_24h.webp',
|
||||
'timestamp': time.time(),
|
||||
'authorName': 'xfgryujk',
|
||||
'authorName': '主播',
|
||||
'authorType': 3,
|
||||
'content': "I can eat glass, it doesn't hurt me."
|
||||
})
|
||||
room.send_message(Command.ADD_VIP, {
|
||||
|
@ -17,7 +17,8 @@
|
||||
<yt-live-chat-item-list-renderer>
|
||||
<template v-for="message in messages">
|
||||
<text-message :key="message.id" v-if="message.type == 0"
|
||||
:avatarUrl="message.avatarUrl" :time="message.time" :authorName="message.authorName" :content="message.content"
|
||||
:avatarUrl="message.avatarUrl" :time="message.time" :authorName="message.authorName"
|
||||
:authorType="message.authorType" :content="message.content"
|
||||
></text-message>
|
||||
<legacy-paid-message :key="message.id" v-else-if="message.type == 1"
|
||||
:avatarUrl="message.avatarUrl" :title="message.title" :content="message.content"
|
||||
@ -73,6 +74,7 @@ export default {
|
||||
avatarUrl: body.data.avatarUrl,
|
||||
time: `${time.getHours()}:${time.getMinutes()}`,
|
||||
authorName: body.data.authorName,
|
||||
authorType: body.data.authorType,
|
||||
content: body.data.content
|
||||
}
|
||||
break;
|
||||
|
@ -1,22 +1,35 @@
|
||||
<template>
|
||||
<yt-live-chat-text-message-renderer>
|
||||
<yt-live-chat-text-message-renderer :author-type="authorTypeText">
|
||||
<div id="author-photo" :style="`background-image: url(${avatarUrl})`"></div>
|
||||
<div id="content">
|
||||
<span id="timestamp">{{time}}</span>
|
||||
<span id="author-name">{{authorName}}</span>
|
||||
<span id="author-name" :type="authorTypeText">{{authorName}}</span>
|
||||
<span id="message">{{content}}</span>
|
||||
</div>
|
||||
</yt-live-chat-text-message-renderer>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
let AUTHOR_TYPE_TO_TEXT = [
|
||||
'',
|
||||
'member', // 舰队
|
||||
'moderator', // 房管
|
||||
'owner' // 主播
|
||||
]
|
||||
|
||||
export default {
|
||||
name: 'TextMessage',
|
||||
props: {
|
||||
avatarUrl: String,
|
||||
time: String,
|
||||
authorName: String,
|
||||
authorType: Number,
|
||||
content: String
|
||||
},
|
||||
computed: {
|
||||
authorTypeText() {
|
||||
return AUTHOR_TYPE_TO_TEXT[this.authorType]
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user