From d25ef434aea3cc8f1ce20af7769adaf9af82acf5 Mon Sep 17 00:00:00 2001 From: Danial Raza Date: Mon, 4 Nov 2024 11:03:13 +0100 Subject: [PATCH] feat: add soundboard (#10536) * feat: add soundboard * chore: disable `jsdoc/check-param-names` rule * fix: export `SoundboardSoundsAPI` --- packages/core/src/api/channel.ts | 21 +++++ packages/core/src/api/guild.ts | 95 +++++++++++++++++++++++ packages/core/src/api/index.ts | 5 ++ packages/core/src/api/soundboardSounds.ts | 20 +++++ packages/core/src/client.ts | 8 ++ 5 files changed, 149 insertions(+) create mode 100644 packages/core/src/api/soundboardSounds.ts diff --git a/packages/core/src/api/channel.ts b/packages/core/src/api/channel.ts index 2d45183e0..302ff5086 100644 --- a/packages/core/src/api/channel.ts +++ b/packages/core/src/api/channel.ts @@ -34,6 +34,8 @@ import { type RESTPutAPIChannelPermissionJSONBody, type RESTPutAPIChannelRecipientJSONBody, type Snowflake, + type RESTPostAPISoundboardSendSoundJSONBody, + type RESTPostAPISendSoundboardSoundResult, } from 'discord-api-types/v10'; export interface StartForumThreadOptions extends RESTPostAPIGuildForumThreadsJSONBody { @@ -595,6 +597,25 @@ export class ChannelsAPI { }); } + /** + * Sends a soundboard sound in a channel + * + * @see {@link https://discord.com/developers/docs/resources/soundboard#send-soundboard-sound} + * @param channelId - The id of the channel to send the soundboard sound in + * @param body - The data for sending the soundboard sound + * @param options - The options for sending the soundboard sound + */ + public async sendSoundboardSound( + channelId: Snowflake, + body: RESTPostAPISoundboardSendSoundJSONBody, + { signal }: Pick = {}, + ) { + return this.rest.post(Routes.sendSoundboardSound(channelId), { + body, + signal, + }) as Promise; + } + /** * Adds a recipient to a group DM channel * diff --git a/packages/core/src/api/guild.ts b/packages/core/src/api/guild.ts index de105f878..f09f51c91 100644 --- a/packages/core/src/api/guild.ts +++ b/packages/core/src/api/guild.ts @@ -102,6 +102,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'; @@ -1362,6 +1368,95 @@ export class GuildsAPI { }) as Promise; } + /** + * 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 = {}) { + return this.rest.get(Routes.guildSoundboardSounds(guildId), { + signal, + }) as Promise; + } + + /** + * Fetches a soundboard sound for a guild + * + * @see {@link https://discord.com/developers/docs/resources/soundboard#get-guild-soundboard-sound} + * @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 = {}, + ) { + return this.rest.get(Routes.guildSoundboardSound(guildId, soundId), { + signal, + }) as Promise; + } + + /** + * Creates a new soundboard sound for a guild + * + * @see {@link https://discord.com/developers/docs/resources/soundboard#create-guild-soundboard-sound} + * @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 = {}, + ) { + return this.rest.post(Routes.guildSoundboardSounds(guildId), { + body, + reason, + signal, + }) as Promise; + } + + /** + * Edits a soundboard sound for a guild + * + * @see {@link https://discord.com/developers/docs/resources/soundboard#modify-guild-soundboard-sound} + * @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 = {}, + ) { + return this.rest.patch(Routes.guildSoundboardSound(guildId, soundId), { + body, + reason, + signal, + }) as Promise; + } + + /** + * Deletes a soundboard sound for a guild + * + * @see {@link https://discord.com/developers/docs/resources/soundboard#delete-guild-soundboard-sound} + * @param guildId - The id of the guild to delete the soundboard sound for + * @param soundId - The id of the soundboard sound to delete + * @param options - The options for deleting the soundboard sound + */ + public async deleteSoundboardSound( + guildId: Snowflake, + soundId: Snowflake, + { reason, signal }: Pick = {}, + ) { + await this.rest.delete(Routes.guildSoundboardSound(guildId, soundId), { reason, signal }); + } + /** * Modifies incident actions for a guild. * diff --git a/packages/core/src/api/index.ts b/packages/core/src/api/index.ts index a0a908255..67135e551 100644 --- a/packages/core/src/api/index.ts +++ b/packages/core/src/api/index.ts @@ -10,6 +10,7 @@ import { MonetizationAPI } from './monetization.js'; import { OAuth2API } from './oauth2.js'; import { PollAPI } from './poll.js'; import { RoleConnectionsAPI } from './roleConnections.js'; +import { SoundboardSoundsAPI } from './soundboardSounds.js'; import { StageInstancesAPI } from './stageInstances.js'; import { StickersAPI } from './sticker.js'; import { ThreadsAPI } from './thread.js'; @@ -28,6 +29,7 @@ export * from './monetization.js'; export * from './oauth2.js'; export * from './poll.js'; export * from './roleConnections.js'; +export * from './soundboardSounds.js'; export * from './stageInstances.js'; export * from './sticker.js'; export * from './thread.js'; @@ -58,6 +60,8 @@ export class API { public readonly roleConnections: RoleConnectionsAPI; + public readonly soundboardSounds: SoundboardSoundsAPI; + public readonly stageInstances: StageInstancesAPI; public readonly stickers: StickersAPI; @@ -81,6 +85,7 @@ export class API { this.oauth2 = new OAuth2API(rest); this.poll = new PollAPI(rest); this.roleConnections = new RoleConnectionsAPI(rest); + this.soundboardSounds = new SoundboardSoundsAPI(rest); this.stageInstances = new StageInstancesAPI(rest); this.stickers = new StickersAPI(rest); this.threads = new ThreadsAPI(rest); diff --git a/packages/core/src/api/soundboardSounds.ts b/packages/core/src/api/soundboardSounds.ts new file mode 100644 index 000000000..b474fd1e7 --- /dev/null +++ b/packages/core/src/api/soundboardSounds.ts @@ -0,0 +1,20 @@ +/* eslint-disable jsdoc/check-param-names */ + +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) {} + + /** + * Fetches all the soundboard default sounds. + * + * @see {@link https://discord.com/developers/docs/resources/soundboard#list-default-soundboard-sounds} + * @param options - The options for fetching the soundboard default sounds. + */ + public async getSoundboardDefaultSounds({ signal }: Pick = {}) { + return this.rest.get(Routes.soundboardDefaultSounds(), { + signal, + }) as Promise; + } +} diff --git a/packages/core/src/client.ts b/packages/core/src/client.ts index 63db5ffca..c233b29d6 100644 --- a/packages/core/src/client.ts +++ b/packages/core/src/client.ts @@ -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, @@ -135,6 +139,10 @@ export interface MappedEvents { [GatewayDispatchEvents.GuildScheduledEventUserRemove]: [ ToEventProps, ]; + [GatewayDispatchEvents.GuildSoundboardSoundCreate]: [ToEventProps]; + [GatewayDispatchEvents.GuildSoundboardSoundDelete]: [ToEventProps]; + [GatewayDispatchEvents.GuildSoundboardSoundUpdate]: [ToEventProps]; + [GatewayDispatchEvents.GuildSoundboardSoundsUpdate]: [ToEventProps]; [GatewayDispatchEvents.GuildStickersUpdate]: [ToEventProps]; [GatewayDispatchEvents.GuildUpdate]: [ToEventProps]; [GatewayDispatchEvents.IntegrationCreate]: [ToEventProps];