-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathROOM_SILENT.ts
40 lines (33 loc) · 1.12 KB
/
ROOM_SILENT.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
import type { Message } from '../types/app'
import type { ROOM_SILENT_OFF as ROOM_SILENT_OFF_TYPE, ROOM_SILENT_ON as ROOM_SILENT_ON_TYPE } from 'tiny-bilibili-ws'
export interface RoomSilentMsg {
/** 禁言类型(按用户等级、勋章等级、全员、关闭) */
type: 'level' | 'medal' | 'member' | 'off'
/** 禁言等级 */
level: number
/** 禁言结束时间,秒级时间戳,-1 为无限 */
second: number
}
const parser = (data: ROOM_SILENT_OFF_TYPE | ROOM_SILENT_ON_TYPE, roomId: number): RoomSilentMsg => {
const msgType = data.cmd
const rawData = data.data
return {
type: msgType === 'ROOM_SILENT_OFF' ? 'off' : rawData.type as 'level' | 'medal' | 'member' | 'off',
level: rawData.level,
second: rawData.second,
}
}
export const ROOM_SILENT_ON = {
parser,
eventName: 'ROOM_SILENT_ON' as const,
handlerName: 'onRoomSilent' as const,
}
export const ROOM_SILENT_OFF = {
parser,
eventName: 'ROOM_SILENT_OFF' as const,
handlerName: 'onRoomSilent' as const,
}
export type Handler = {
/** 房间开启、关闭全局禁言 */
onRoomSilent: (msg: Message<RoomSilentMsg>) => void
}