-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
voiceState.ts
44 lines (40 loc) · 1.65 KB
/
voiceState.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
import type { VoiceState } from "../types/voice/voiceState.ts";
import { Bot } from "../bot.ts";
import { SnakeCasedPropertiesDeep } from "../types/util.ts";
export function transformVoiceState(
bot: Bot,
payload: { voiceState: SnakeCasedPropertiesDeep<VoiceState> } & { guildId: bigint },
): DiscordenoVoiceState {
return {
bitfield: (payload.voiceState.deaf ? 1n : 0n) |
(payload.voiceState.mute ? 2n : 0n) |
(payload.voiceState.self_deaf ? 4n : 0n) |
(payload.voiceState.self_mute ? 8n : 0n) |
(payload.voiceState.self_stream ? 16n : 0n) |
(payload.voiceState.self_video ? 32n : 0n) |
(payload.voiceState.suppress ? 64n : 0n),
requestToSpeakTimestamp: payload.voiceState.request_to_speak_timestamp
? Date.parse(payload.voiceState.request_to_speak_timestamp)
: undefined,
sessionId: payload.voiceState.session_id,
channelId: payload.voiceState.channel_id ? bot.transformers.snowflake(payload.voiceState.channel_id) : undefined,
guildId: payload.guildId ||
(payload.voiceState.guild_id ? bot.transformers.snowflake(payload.voiceState.guild_id) : 0n),
userId: payload.guildId ||
(payload.voiceState.user_id ? bot.transformers.snowflake(payload.voiceState.user_id) : 0n),
};
}
export interface DiscordenoVoiceState {
/** The guild id */
guildId: bigint;
/** The channel id this user is connected to */
channelId?: bigint;
/** The user id this voice state is for */
userId: bigint;
/** Holds all the boolean toggles. */
bitfield: bigint;
/** The time at which the user requested to speak */
requestToSpeakTimestamp?: number;
/** The unique session id */
sessionId: string;
}