Skip to content

Commit 18de718

Browse files
committed
feat: 房间设立、撤销房管
link #22
1 parent 0f21ef5 commit 18de718

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed

README.md

+21
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ export interface GuardBuyMsg {
534534
| --- | --- |
535535
| onRoomWarn | 房间被超管警告、切断 |
536536
| onRoomSilent | 房间开启、关闭全局禁言 |
537+
| onRoomAdminSet | 房间设立、撤销房管 |
537538

538539
<details>
539540
<summary>Type Definitions</summary>
@@ -579,6 +580,26 @@ export interface RoomSilentMsg {
579580
second: number
580581
}
581582
```
583+
584+
##### handler.onRoomAdminSet
585+
586+
房间设立、撤销房管
587+
588+
```ts
589+
export type Handler = {
590+
/** 房间设立、撤销房管 */
591+
onRoomAdminSet: (msg: Message<RoomAdminSetMsg>) => void
592+
}
593+
594+
type msgType = 'room_admin_entrance''ROOM_ADMIN_REVOKE'
595+
596+
export interface RoomAdminSetMsg {
597+
/** 类型(设立、撤销) */
598+
type: 'set' | 'revoke'
599+
/** 用户uid */
600+
uid: number
601+
}
602+
```
582603
</details>
583604

584605
#### 监听原始消息

src/listener/index.ts

+18
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
INTERACT_WORD, ENTRY_EFFECT, LIKE_INFO_V3_CLICK, type UserActionMsgHandler,
88
LIKE_INFO_V3_UPDATE, type LikedChangeMsgHandler,
99
ONLINE_RANK_COUNT, type RankCountChangeMsgHandler,
10+
room_admin_entrance, ROOM_ADMIN_REVOKE, type RoomAdminSetMsgHandler,
1011
ROOM_CHANGE, type RoomInfoChangeHandler,
1112
ROOM_SILENT_ON, ROOM_SILENT_OFF, type RoomSilentMsgHandler,
1213
SEND_GIFT, type GiftHandler,
@@ -36,6 +37,7 @@ export type MsgHandler = Partial<
3637
& UserActionMsgHandler
3738
& LikedChangeMsgHandler
3839
& RankCountChangeMsgHandler
40+
& RoomAdminSetMsgHandler
3941
& RoomInfoChangeHandler
4042
& RoomSilentMsgHandler
4143
& GiftHandler
@@ -166,6 +168,22 @@ export const listenAll = (instance: KeepLiveTCP | KeepLiveWS, roomId: number, ha
166168
})
167169
}
168170

171+
// room_admin_entrance, ROOM_ADMIN_REVOKE
172+
if (handler[room_admin_entrance.handlerName] || handler[ROOM_ADMIN_REVOKE.handlerName] || rawHandlerNames.has(room_admin_entrance.eventName) || rawHandlerNames.has(ROOM_SILENT_OFF.eventName)) {
173+
rawHandlerNames.delete(room_admin_entrance.eventName)
174+
rawHandlerNames.delete(ROOM_ADMIN_REVOKE.eventName)
175+
instance.on(room_admin_entrance.eventName as any, (data: WSMessage<any>) => {
176+
isHandleRaw && rawHandler[room_admin_entrance.eventName]?.(data.data)
177+
const parsedData = room_admin_entrance.parser(data.data, roomId)
178+
handler[room_admin_entrance.handlerName]?.(normalizeDanmu(room_admin_entrance.eventName, parsedData, data.data))
179+
})
180+
instance.on(ROOM_ADMIN_REVOKE.eventName as any, (data: WSMessage<any>) => {
181+
isHandleRaw && rawHandler[ROOM_ADMIN_REVOKE.eventName]?.(data.data)
182+
const parsedData = ROOM_ADMIN_REVOKE.parser(data.data, roomId)
183+
handler[ROOM_ADMIN_REVOKE.handlerName]?.(normalizeDanmu(ROOM_ADMIN_REVOKE.eventName, parsedData, data.data))
184+
})
185+
}
186+
169187
// ROOM_CHANGE
170188
if (handler[ROOM_CHANGE.handlerName] || rawHandlerNames.has(ROOM_CHANGE.eventName)) {
171189
rawHandlerNames.delete(ROOM_CHANGE.eventName)

src/parser/ROOM_ADMIN.ts

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import type { Message } from '../types/app'
2+
3+
export interface RoomAdminSetMsg {
4+
/** 类型(设立、撤销) */
5+
type: 'set' | 'revoke'
6+
/** 用户uid */
7+
uid: number
8+
}
9+
10+
const parser = (data: any, roomId: number): RoomAdminSetMsg => {
11+
const msgType = data.cmd
12+
const rawData = data
13+
14+
return {
15+
type: msgType === 'room_admin_entrance' ? 'set' : 'revoke',
16+
uid: rawData.uid,
17+
}
18+
}
19+
20+
export const room_admin_entrance = {
21+
parser,
22+
eventName: 'room_admin_entrance' as const,
23+
handlerName: 'onRoomAdminSet' as const,
24+
}
25+
26+
export const ROOM_ADMIN_REVOKE = {
27+
parser,
28+
eventName: 'ROOM_ADMIN_REVOKE' as const,
29+
handlerName: 'onRoomAdminSet' as const,
30+
}
31+
32+
export type Handler = {
33+
/** 房间设立、撤销房管 */
34+
onRoomAdminSet: (msg: Message<RoomAdminSetMsg>) => void
35+
}

src/parser/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export { GUARD_BUY, type Handler as GuardBuyHandler, type GuardBuyMsg } from './
66
export { INTERACT_WORD, ENTRY_EFFECT, LIKE_INFO_V3_CLICK, type Handler as UserActionMsgHandler, type UserActionMsg } from './INTERACT_WORD_ENTRY_EFFECT'
77
export { LIKE_INFO_V3_UPDATE, type Handler as LikedChangeMsgHandler, type LikedChangeMsg } from './LIKE_INFO_V3_UPDATE'
88
export { ONLINE_RANK_COUNT, type Handler as RankCountChangeMsgHandler, type RankCountChangeMsg } from './ONLINE_RANK_COUNT'
9+
export { room_admin_entrance, ROOM_ADMIN_REVOKE, type Handler as RoomAdminSetMsgHandler, type RoomAdminSetMsg } from './ROOM_ADMIN'
910
export { ROOM_CHANGE, type Handler as RoomInfoChangeHandler, type RoomInfoChangeMsg } from './ROOM_CHANGE'
1011
export { ROOM_SILENT_ON, ROOM_SILENT_OFF, type Handler as RoomSilentMsgHandler, type RoomSilentMsg } from './ROOM_SILENT'
1112
export { SEND_GIFT, type Handler as GiftHandler, type GiftMsg } from './SEND_GIFT'

0 commit comments

Comments
 (0)