这是indexloc提供的服务,不要输入任何密码
Skip to content

Commit a9efcfe

Browse files
committed
feat: danmuMsg in live-mini
1 parent 85b90e1 commit a9efcfe

File tree

13 files changed

+65
-35
lines changed

13 files changed

+65
-35
lines changed

packages/bilicli/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"bin": {
1515
"bilicli": "bin/bilicli.js"
1616
},
17+
"type": "module",
1718
"main": "dist/main.js",
19+
"exports": "./dist/main.js",
1820
"files": [
1921
"bin",
2022
"dist"

packages/bilicli/tsup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defineConfig } from 'tsup'
22

33
export default defineConfig({
4-
format: ['cjs', 'esm'],
4+
format: ['esm'],
55
entry: [
66
'src/index.ts',
77
],

packages/live-full/package.json

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,14 @@
66
"dev": "temir src/index.ts",
77
"build": "temir build src/index.ts"
88
},
9-
"main": "dist/main.js",
10-
"module": "dist/index.mjs",
9+
"type": "module",
10+
"main": "dist/index.js",
11+
"exports": "./dist/index.js",
1112
"types": "dist/index.d.ts",
1213
"files": [
1314
"bin",
1415
"dist"
1516
],
16-
"exports": {
17-
".": {
18-
"require": "./dist/index.js",
19-
"import": "./dist/index.mjs"
20-
}
21-
},
2217
"keywords": [
2318
"bilibili",
2419
"bilibili-live",

packages/live-full/tsup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export default {
2-
format: ['cjs', 'esm'],
2+
format: ['esm'],
33
entry: [
44
'src/index.ts',
55
],

packages/live-mini/package.json

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,14 @@
22
"name": "@bilicli/live-mini",
33
"version": "0.0.1",
44
"description": "Bili-Live danmu client, lite version",
5+
"type": "module",
56
"main": "dist/index.js",
6-
"module": "dist/index.mjs",
7+
"exports": "./dist/index.js",
78
"types": "dist/index.d.ts",
89
"scripts": {
910
"dev": "tsup --watch",
1011
"build": "tsup"
1112
},
12-
"exports": {
13-
".": {
14-
"require": "./dist/index.js",
15-
"import": "./dist/index.mjs"
16-
}
17-
},
1813
"files": [
1914
"dist"
2015
],
@@ -31,7 +26,7 @@
3126
"license": "MIT",
3227
"dependencies": {
3328
"blive-message-listener": "^0.3.1",
34-
"colorette": "^2.0.19",
29+
"chalk": "^5.1.2",
3530
"ohmyfetch": "^0.4.20"
3631
}
3732
}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { DanmuMsg } from 'blive-message-listener'
2-
import { username } from '../username'
2+
import { usernameCom } from '../username'
33

4-
export const danmuMsg = (msg: DanmuMsg) => {
5-
const userCom = username(msg.user)
6-
return `${userCom}: ${msg.content}`
4+
export const danmuMsgCom = (msg: DanmuMsg) => {
5+
return `${usernameCom(msg.user)}: ${msg.content}`
76
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import chalk from 'chalk'
2+
import type { RoomInfo } from '../utils/getInfo'
3+
4+
export const roomInfoCom = (roomInfo: RoomInfo) => {
5+
const components = [
6+
chalk.bold(chalk.green(roomInfo.room_id)),
7+
chalk.green(`(${roomInfo.parent_area_name}·${roomInfo.area_name})`),
8+
roomInfo.title
9+
]
10+
return components.join(' ')
11+
}
Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
1-
import { blue } from 'colorette'
1+
import chalk from 'chalk'
22
import type { User } from 'blive-message-listener'
3+
import { getGuardColor } from '../utils/parse'
34

4-
export const username = (user: User) => {
5-
return blue(user.uname)
5+
export const usernameCom = (user: User) => {
6+
let badge, rank, admin
7+
if (user.badge) {
8+
const badgeColor = user.badge.anchor.is_same_room ? user.badge.color : '#999999'
9+
badge = chalk.bgHex(badgeColor)(` ${user.badge.name} `) + chalk.bgHex('#ffffff').hex(badgeColor)(` ${user.badge.level} `)
10+
}
11+
if (user.identity?.rank) {
12+
rank = chalk.bgBlue(` 榜${user.identity.rank} `)
13+
}
14+
if (user.identity?.room_admin) {
15+
admin = chalk.bgRed(` 房 `)
16+
}
17+
const uname = chalk.hex(getGuardColor(user.identity?.guard_level))(user.uname)
18+
const components = [
19+
badge,
20+
rank,
21+
admin,
22+
uname,
23+
].filter(Boolean)
24+
return components.join(' ')
625
}

packages/live-mini/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { startInstance } from './instance'
22
import { getRoomInfo } from './utils/getInfo'
3+
import { roomInfoCom } from './component/roomInfo'
34

45
const startApp = async (roomId: number, options: AppOptions) => {
56
const roomInfo = await getRoomInfo(roomId)
67
if (!roomInfo) {
78
console.log('房间不存在')
89
return process.exit(1)
910
}
10-
console.log(roomId, `(${roomInfo.parent_area_name}·${roomInfo.area_name})`, roomInfo.title)
11+
// Room Info
12+
console.log(roomInfoCom(roomInfo))
1113
startInstance(roomInfo.room_id, options)
1214
}
1315

packages/live-mini/src/instance.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import type {
33
MsgHandler, Message,
44
DanmuMsg, SuperChatMsg, GiftMsg, GuardBuyMsg, UserActionMsg
55
} from 'blive-message-listener'
6-
import { danmuMsg } from './component/msg'
6+
import { danmuMsgCom } from './component/msg'
77

88
export const startInstance = (roomId: number, options: AppOptions) => {
99
const handler: MsgHandler = {
1010
onIncomeDanmu: (msg) => {
11-
console.log(danmuMsg(msg.body))
11+
console.log(danmuMsgCom(msg.body))
1212
},
1313
}
1414
startListen(roomId, handler)

0 commit comments

Comments
 (0)