Skip to content

Commit

Permalink
feat: 上舰消息
Browse files Browse the repository at this point in the history
  • Loading branch information
ddiu8081 committed Oct 24, 2022
1 parent ad5f6a0 commit 96bc202
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
14 changes: 14 additions & 0 deletions packages/live-mini/src/component/msg/guardBuy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import ansis from 'ansis'
import type { GuardBuyMsg } from 'blive-message-listener'
import { usernameCom } from '../username'
import { getGuardColor } from '../../utils/parse'

export const guardBuyMsgCom = (msg: GuardBuyMsg) => {
const components = [
`${usernameCom(msg.user)}:`,
`(¥${ msg.price / 1000 })`,
ansis.hex(getGuardColor(msg.user.identity?.guard_level))(msg.gift_name),
].filter(Boolean)

return components.join(' ')
}
3 changes: 2 additions & 1 deletion packages/live-mini/src/component/msg/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './danmu'
export * from './superChat'
export * from './gift'
export * from './gift'
export * from './guardBuy'
7 changes: 5 additions & 2 deletions packages/live-mini/src/instance.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { startListen } from 'blive-message-listener'
import type { MsgHandler } from 'blive-message-listener'
import { danmuMsgCom, superChatMsgCom, giftMsgCom } from './component/msg'
import { danmuMsgCom, superChatMsgCom, giftMsgCom, guardBuyMsgCom } from './component/msg'

export const startInstance = (roomId: number, options: AppOptions) => {
const handler: MsgHandler = {
Expand All @@ -12,7 +12,10 @@ export const startInstance = (roomId: number, options: AppOptions) => {
},
onGift: (msg) => {
console.log(giftMsgCom(msg.body))
}
},
onGuardBuy(msg) {
console.log(guardBuyMsgCom(msg.body))
},
}
startListen(roomId, handler)
}

0 comments on commit 96bc202

Please sign in to comment.