Skip to content

Commit

Permalink
feat: add soundboard
Browse files Browse the repository at this point in the history
  • Loading branch information
sdanialraza committed Oct 5, 2024
1 parent c1b849f commit e2b939f
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/core/src/api/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
type RESTPostAPIChannelThreadsResult,
type APIThreadChannel,
type RESTPostAPIGuildForumThreadsJSONBody,
type RESTPostAPISoundboardSendSoundJSONBody,
} from 'discord-api-types/v10';

export interface StartForumThreadOptions extends RESTPostAPIGuildForumThreadsJSONBody {
Expand Down Expand Up @@ -583,4 +584,15 @@ export class ChannelsAPI {
signal,
});
}

public async sendSoundboardSound(
channelId: Snowflake,
body: RESTPostAPISoundboardSendSoundJSONBody,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.post(Routes.sendSoundboardSound(channelId), {
body,
signal,
}) as Promise<RESTPostAPISoundboardSendSoundResult>;
}
}
91 changes: 91 additions & 0 deletions packages/core/src/api/guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ import {
type RESTPutAPIGuildOnboardingJSONBody,
type RESTPutAPIGuildOnboardingResult,
type RESTPutAPIGuildTemplateSyncResult,
type RESTGetAPIGuildSoundboardSoundResult,
type RESTGetAPIGuildSoundboardSoundsResult,
type RESTPatchAPIGuildSoundboardSoundJSONBody,
type RESTPatchAPIGuildSoundboardSoundResult,
type RESTPostAPIGuildSoundboardSoundJSONBody,
type RESTPostAPIGuildSoundboardSoundResult,
type Snowflake,
} from 'discord-api-types/v10';
import { VoiceAPI } from './voice';
Expand Down Expand Up @@ -1356,4 +1362,89 @@ export class GuildsAPI {
signal,
}) as Promise<RESTPutAPIGuildOnboardingResult>;
}

/**
* Fetches all the soundboard sounds for a guild
*
* @see {@link https://discord.com/developers/docs/resources/soundboard#list-guild-soundboard-sounds}
* @param guildId - The id of the guild to fetch the soundboard sounds for
* @param options - The options for fetching the soundboard sounds
*/
public async getSoundboardSounds(guildId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.guildSoundboardSounds(guildId), {
signal,
}) as Promise<RESTGetAPIGuildSoundboardSoundsResult>;
}

/**
* Fetches a soundboard sound for a guild
*
* @param guildId - The id of the guild to fetch the soundboard sound for
* @param soundId - The id of the soundboard sound to fetch
* @param options - The options for fetching the soundboard sound
*/
public async getSoundboardSound(
guildId: Snowflake,
soundId: Snowflake,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.get(Routes.guildSoundboardSound(guildId, soundId), {
signal,
}) as Promise<RESTGetAPIGuildSoundboardSoundResult>;
}

/**
* Creates a new soundboard sound for a guild
*
* @param guildId - The id of the guild to create the soundboard sound for
* @param body - The data for creating the soundboard sound
* @param options - The options for creating the soundboard sound
*/
public async createSoundboardSound(
guildId: Snowflake,
body: RESTPostAPIGuildSoundboardSoundJSONBody,
{ reason, signal }: Pick<RequestData, 'reason' | 'signal'> = {},
) {
return this.rest.post(Routes.guildSoundboardSounds(guildId), {
body,
reason,
signal,
}) as Promise<RESTPostAPIGuildSoundboardSoundResult>;
}

/**
* Edits a soundboard sound for a guild
*
* @param guildId - The id of the guild to edit the soundboard sound for
* @param soundId - The id of the soundboard sound to edit
* @param body - The data for editing the soundboard sound
* @param options - The options for editing the soundboard sound
*/
public async editSoundboardSound(
guildId: Snowflake,
soundId: Snowflake,
body: RESTPatchAPIGuildSoundboardSoundJSONBody,
{ reason, signal }: Pick<RequestData, 'reason' | 'signal'> = {},
) {
return this.rest.patch(Routes.guildSoundboardSound(guildId, soundId), {
body,
reason,
signal,
}) as Promise<RESTPatchAPIGuildSoundboardSoundResult>;
}

/**
* Deletes a soundboard sound for a guild
*
* @param guildId - The id of the guild to delete the soundboard sound for
* @param soundId - The id of the soundboard sound to delete
* @param param2 - The options for deleting the soundboard sound
*/
public async deleteSoundboardSound(
guildId: Snowflake,
soundId: Snowflake,
{ reason, signal }: Pick<RequestData, 'reason' | 'signal'> = {},
) {
await this.rest.delete(Routes.guildSoundboardSound(guildId, soundId), { reason, signal });
}
}
12 changes: 12 additions & 0 deletions packages/core/src/api/soundboardSounds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { RequestData, REST } from '@discordjs/rest';
import { Routes, type RESTGetAPISoundboardDefaultSoundsResult } from 'discord-api-types/v10';

export class SoundboardSoundsAPI {
public constructor(private readonly rest: REST) {}

public async getSoundboardDefaultSounds({ signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.soundboardDefaultSounds(), {
signal,
}) as Promise<RESTGetAPISoundboardDefaultSoundsResult>;
}
}
8 changes: 8 additions & 0 deletions packages/core/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ import {
type GatewayGuildScheduledEventUpdateDispatchData,
type GatewayGuildScheduledEventUserAddDispatchData,
type GatewayGuildScheduledEventUserRemoveDispatchData,
type GatewayGuildSoundboardSoundCreateDispatch,
type GatewayGuildSoundboardSoundDeleteDispatch,
type GatewayGuildSoundboardSoundUpdateDispatch,
type GatewayGuildSoundboardSoundsUpdateDispatch,
type GatewayGuildStickersUpdateDispatchData,
type GatewayGuildUpdateDispatchData,
type GatewayIntegrationCreateDispatchData,
Expand Down Expand Up @@ -131,6 +135,10 @@ export interface MappedEvents {
[GatewayDispatchEvents.GuildScheduledEventUserRemove]: [
ToEventProps<GatewayGuildScheduledEventUserRemoveDispatchData>,
];
[GatewayDispatchEvents.GuildSoundboardSoundCreate]: [ToEventProps<GatewayGuildSoundboardSoundCreateDispatch>];
[GatewayDispatchEvents.GuildSoundboardSoundDelete]: [ToEventProps<GatewayGuildSoundboardSoundDeleteDispatch>];
[GatewayDispatchEvents.GuildSoundboardSoundUpdate]: [ToEventProps<GatewayGuildSoundboardSoundUpdateDispatch>];
[GatewayDispatchEvents.GuildSoundboardSoundsUpdate]: [ToEventProps<GatewayGuildSoundboardSoundsUpdateDispatch>];
[GatewayDispatchEvents.GuildStickersUpdate]: [ToEventProps<GatewayGuildStickersUpdateDispatchData>];
[GatewayDispatchEvents.GuildUpdate]: [ToEventProps<GatewayGuildUpdateDispatchData>];
[GatewayDispatchEvents.IntegrationCreate]: [ToEventProps<GatewayIntegrationCreateDispatchData>];
Expand Down

0 comments on commit e2b939f

Please sign in to comment.