-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistener.ts
62 lines (57 loc) · 1.47 KB
/
listener.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import type { MsgHandler, startListen } from 'blive-message-listener'
import type { Biliver } from './biliver'
import { actionMap } from './dictMap'
class Listener {
constructor(private roomId: number, private messageListener: typeof startListen) {
}
get getRoomId() {
return this.roomId
}
startListen(handler: MsgHandler) {
this.messageListener(this.roomId, handler)
}
}
export const basicListenerHandler = (biliver: Biliver) => {
const handler: MsgHandler = {
onIncomeDanmu: (msg) => {
biliver.add(msg)
},
onIncomeSuperChat: (msg) => {
biliver.add(msg)
},
onUserAction: (msg) => {
const { action, user } = msg.body
if (action !== 'unknown')
biliver.notice(user.uname + actionMap[action as keyof typeof actionMap])
},
onGift: (msg) => {
biliver.noticeGift(msg)
},
onRoomInfoChange: (msg) => {
biliver.view.updateRoomInfo(msg.body)
},
onOpen: () => {
biliver.view.loading(true)
},
onStartListen: () => {
biliver.view.loading(false)
},
onClose: () => {
biliver.view.loading(true, 'up 下播了')
setTimeout(() => {
process.exit()
}, 6000)
},
onError: (err) => {
// eslint-disable-next-line no-console
console.log(err)
biliver.view.loading(false, 'connect error')
biliver.notice('damn')
setTimeout(() => {
process.exit()
}, 6000)
},
}
return handler
}
export default Listener