Skip to content

Commit 6538603

Browse files
feat(structures): add SoundboardSound structure (#11390)
* feat(structures): update barrel exports in preparation for new structure * feat(structures): add SoundboardSound structure * chore(structures): update doc comment * chore(structures): address review suggestions * chore(structures): consistency changes and use isIdSet to retrieve id * docs(structures): add remarks to conditionally present attributes --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 1251d47 commit 6538603

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed

packages/structures/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export * from './interactions/index.js';
77
export * from './invites/index.js';
88
export * from './messages/index.js';
99
export * from './polls/index.js';
10+
export * from './soundboards/index.js';
1011
export * from './stickers/index.js';
1112
export * from './teams/index.js';
1213
export * from './users/index.js';
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import { DiscordSnowflake } from '@sapphire/snowflake';
2+
import type { APISoundboardSound } from 'discord-api-types/v10';
3+
import { Structure } from '../Structure';
4+
import { kData } from '../utils/symbols';
5+
import { isIdSet } from '../utils/type-guards';
6+
import type { Partialize } from '../utils/types';
7+
8+
/**
9+
* Represents any soundboard sound 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+
* @remarks has substructure `User` which needs to be instantiated and stored by an extending class using it
13+
*/
14+
export class SoundboardSound<Omitted extends keyof APISoundboardSound | '' = ''> extends Structure<
15+
APISoundboardSound,
16+
Omitted
17+
> {
18+
/**
19+
* The template used for removing data from the raw data stored for each soundboard sound.
20+
*/
21+
public static override readonly DataTemplate: Partial<APISoundboardSound> = {};
22+
23+
/**
24+
* @param data - The raw data received from the API for the soundboard sound
25+
*/
26+
public constructor(data: Partialize<APISoundboardSound, Omitted>) {
27+
super(data);
28+
}
29+
30+
/**
31+
* The name of this sound
32+
*/
33+
public get name() {
34+
return this[kData].name;
35+
}
36+
37+
/**
38+
* The id of this sound
39+
*/
40+
public get soundId() {
41+
return this[kData].sound_id;
42+
}
43+
44+
/**
45+
* The volume of this sound, from 0 to 1
46+
*/
47+
public get volume() {
48+
return this[kData].volume;
49+
}
50+
51+
/**
52+
* The id of this sound's custom emoji
53+
*/
54+
public get emojiId() {
55+
return this[kData].emoji_id;
56+
}
57+
58+
/**
59+
* The unicode character of this sound's standard emoji
60+
*/
61+
public get emojiName() {
62+
return this[kData].emoji_name;
63+
}
64+
65+
/**
66+
* The id of the guild this sound is in
67+
*/
68+
public get guildId() {
69+
return this[kData].guild_id;
70+
}
71+
72+
/**
73+
* Whether this sound can be used, may be false due to loss of server boosts
74+
*/
75+
public get available() {
76+
return this[kData].available;
77+
}
78+
79+
/**
80+
* The timestamp this sound was created at
81+
*
82+
* @remarks only available for guild soundboard sounds
83+
*/
84+
public get createdTimestamp() {
85+
return isIdSet(this[kData].sound_id) && isIdSet(this[kData].guild_id)
86+
? DiscordSnowflake.timestampFrom(this[kData].sound_id)
87+
: null;
88+
}
89+
90+
/**
91+
* The time this sound was created at
92+
*
93+
* @remarks only available for guild soundboard sounds
94+
*/
95+
public get createdAt() {
96+
const createdTimestamp = this.createdTimestamp;
97+
98+
return createdTimestamp ? new Date(createdTimestamp) : null;
99+
}
100+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './SoundboardSound.js';

0 commit comments

Comments
 (0)