Skip to content

Commit 693fcbc

Browse files
feat(structures): add Stage Instance structure (#11397)
* feat(structures): update barrel exports for stage instance structure * feat(structures): add stage instance structure * docs(structure): cleanup and use see/link correctly --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent c126367 commit 693fcbc

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

packages/structures/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export * from './polls/index.js';
1010
export * from './stickers/index.js';
1111
export * from './teams/index.js';
1212
export * from './users/index.js';
13+
export * from './stageInstances/index.js';
1314
export * from './Structure.js';
1415
export * from './subscriptions/index.js';
1516
export * from './Mixin.js';
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import { DiscordSnowflake } from '@sapphire/snowflake';
2+
import type { APIStageInstance } from 'discord-api-types/v10';
3+
import { Structure } from '../Structure.js';
4+
import { kData } from '../utils/symbols.js';
5+
import { isIdSet } from '../utils/type-guards.js';
6+
import type { Partialize } from '../utils/types.js';
7+
8+
/**
9+
* Represents any stage instance on Discord.
10+
*
11+
* @typeParam Omitted - Specify the properties that will not be stored in the raw data field as a union, implement via `DataTemplate`
12+
*/
13+
export class StageInstance<Omitted extends keyof APIStageInstance | '' = ''> extends Structure<
14+
APIStageInstance,
15+
Omitted
16+
> {
17+
/**
18+
* The template used for removing data from the raw data stored for each stage instance
19+
*/
20+
public static override readonly DataTemplate: Partial<APIStageInstance> = {};
21+
22+
/**
23+
* @param data - The raw data received from the API for the stage instance
24+
*/
25+
public constructor(data: Partialize<APIStageInstance, Omitted>) {
26+
super(data);
27+
}
28+
29+
/**
30+
* The stage instance's id
31+
*/
32+
public get id() {
33+
return this[kData].id;
34+
}
35+
36+
/**
37+
* The guild id of the associated stage channel
38+
*/
39+
public get guildId() {
40+
return this[kData].guild_id;
41+
}
42+
43+
/**
44+
* The id of the associated stage channel
45+
*/
46+
public get channelId() {
47+
return this[kData].channel_id;
48+
}
49+
50+
/**
51+
* The topic of the stage instance (1-120 characters)
52+
*/
53+
public get topic() {
54+
return this[kData].topic;
55+
}
56+
57+
/**
58+
* The privacy level of the stage instance
59+
*/
60+
public get privacyLevel() {
61+
return this[kData].privacy_level;
62+
}
63+
64+
/**
65+
* The id of the scheduled event for this stage instance
66+
*/
67+
public get guildScheduledEventId() {
68+
return this[kData].guild_scheduled_event_id;
69+
}
70+
71+
/**
72+
* The timestamp the stage instance was created at
73+
*/
74+
public get createdTimestamp() {
75+
return isIdSet(this.id) ? DiscordSnowflake.timestampFrom(this.id) : null;
76+
}
77+
78+
/**
79+
* The time the stage instance was created at
80+
*/
81+
public get createdAt() {
82+
const createdTimestamp = this.createdTimestamp;
83+
return createdTimestamp ? new Date(createdTimestamp) : null;
84+
}
85+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './StageInstance.js';

0 commit comments

Comments
 (0)