Skip to content

Commit b0e413c

Browse files
AsadHumayunalmeidx
andauthored
feat(structure): add voice structure (#11400)
* feat(structure): add Voice structures * feat(structure): add VoiceState structure * feat(structure): add VoiceRegion structure * chore(structures): lib exports consistency --------- Co-authored-by: Almeida <[email protected]>
1 parent 6538603 commit b0e413c

File tree

4 files changed

+170
-1
lines changed

4 files changed

+170
-1
lines changed

packages/structures/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ export * from './invites/index.js';
88
export * from './messages/index.js';
99
export * from './polls/index.js';
1010
export * from './soundboards/index.js';
11+
export * from './stageInstances/index.js';
1112
export * from './stickers/index.js';
1213
export * from './teams/index.js';
1314
export * from './users/index.js';
14-
export * from './stageInstances/index.js';
15+
export * from './voice/index.js';
1516
export * from './Structure.js';
1617
export * from './subscriptions/index.js';
1718
export * from './Mixin.js';
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import type { APIVoiceRegion } from 'discord-api-types/v10';
2+
import { Structure } from '../Structure.js';
3+
import { kData } from '../utils/symbols.js';
4+
import type { Partialize } from '../utils/types.js';
5+
6+
/**
7+
* Represents any voice region on Discord.
8+
*
9+
* @typeParam Omitted - Specify the properties that will not be stored in the raw data field as a union, implement via `DataTemplate`
10+
*/
11+
export class VoiceRegion<Omitted extends keyof APIVoiceRegion | '' = ''> extends Structure<APIVoiceRegion, Omitted> {
12+
/**
13+
* The template used for removing data from the raw data stored for each voice region
14+
*/
15+
public static override readonly DataTemplate: Partial<APIVoiceRegion> = {};
16+
17+
/**
18+
* @param data - The raw data received from the API for the voice region
19+
*/
20+
public constructor(data: Partialize<APIVoiceRegion, Omitted>) {
21+
super(data);
22+
}
23+
24+
/**
25+
* Unique id for the region
26+
*/
27+
public get id() {
28+
return this[kData].id;
29+
}
30+
31+
/**
32+
* Name of the region
33+
*/
34+
public get name() {
35+
return this[kData].name;
36+
}
37+
38+
/**
39+
* `true` for a single server that is closest to the current user's client
40+
*/
41+
public get optimal() {
42+
return this[kData].optimal;
43+
}
44+
45+
/**
46+
* Whether this is a deprecated voice region (avoid switching to these)
47+
*/
48+
public get deprecated() {
49+
return this[kData].deprecated;
50+
}
51+
52+
/**
53+
* Whether this is a custom voice region (used for events/etc)
54+
*/
55+
public get custom() {
56+
return this[kData].custom;
57+
}
58+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import type { APIVoiceState } from 'discord-api-types/v10';
2+
import { Structure } from '../Structure.js';
3+
import { kData } from '../utils/symbols.js';
4+
import type { Partialize } from '../utils/types.js';
5+
6+
/**
7+
* Represents any voice state on Discord.
8+
*
9+
* @typeParam Omitted - Specify the properties that will not be stored in the raw data field as a union, implement via `DataTemplate`
10+
* @remarks has substructure `GuildMember` which needs to be instantiated and stored by an extending class using it
11+
*/
12+
export class VoiceState<Omitted extends keyof APIVoiceState | '' = ''> extends Structure<APIVoiceState, Omitted> {
13+
/**
14+
* The template used for removing data from the raw data stored for each voice state
15+
*/
16+
public static override readonly DataTemplate: Partial<APIVoiceState> = {};
17+
18+
/**
19+
* @param data - The raw data received from the API for the voice state
20+
*/
21+
public constructor(data: Partialize<APIVoiceState, Omitted>) {
22+
super(data);
23+
}
24+
25+
/**
26+
* The guild id this voice state is for
27+
*/
28+
public get guildId() {
29+
return this[kData].guild_id;
30+
}
31+
32+
/**
33+
* The channel id this user is connected to
34+
*/
35+
public get channelId() {
36+
return this[kData].channel_id;
37+
}
38+
39+
/**
40+
* The user id this voice state is for
41+
*/
42+
public get userId() {
43+
return this[kData].user_id;
44+
}
45+
46+
/**
47+
* The session id for this voice state
48+
*/
49+
public get sessionId() {
50+
return this[kData].session_id;
51+
}
52+
53+
/**
54+
* Whether this user is deafened by the server
55+
*/
56+
public get deaf() {
57+
return this[kData].deaf;
58+
}
59+
60+
/**
61+
* Whether this user is muted by the server
62+
*/
63+
public get mute() {
64+
return this[kData].mute;
65+
}
66+
67+
/**
68+
* Whether this user is locally deafened
69+
*/
70+
public get selfDeaf() {
71+
return this[kData].self_deaf;
72+
}
73+
74+
/**
75+
* Whether this user is locally muted
76+
*/
77+
public get selfMute() {
78+
return this[kData].self_mute;
79+
}
80+
81+
/**
82+
* Whether this user is streaming using "Go Live"
83+
*/
84+
public get selfStream() {
85+
return this[kData].self_stream;
86+
}
87+
88+
/**
89+
* Whether this user's camera is enabled
90+
*/
91+
public get selfVideo() {
92+
return this[kData].self_video;
93+
}
94+
95+
/**
96+
* Whether this user's permission to speak is denied
97+
*/
98+
public get suppress() {
99+
return this[kData].suppress;
100+
}
101+
102+
/**
103+
* The time at which the user requested to speak
104+
*/
105+
public get requestToSpeakTimestamp() {
106+
return this[kData].request_to_speak_timestamp;
107+
}
108+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './VoiceState.js';
2+
export * from './VoiceRegion.js';

0 commit comments

Comments
 (0)