diff --git a/src/api/Routes/channels.ts b/src/api/Routes/channels.ts index ba0fea1..c148376 100644 --- a/src/api/Routes/channels.ts +++ b/src/api/Routes/channels.ts @@ -48,6 +48,7 @@ import type { RESTPostAPIChannelWebhookResult, RESTPostAPIGuildForumThreadsJSONBody, RESTPostAPIPollExpireResult, + RESTPostAPISendSoundboardSound, RESTPutAPIChannelMessageReactionResult, RESTPutAPIChannelPermissionJSONBody, RESTPutAPIChannelPermissionResult, @@ -199,6 +200,9 @@ export interface ChannelRoutes { post(args?: RestArgumentsNoBody): Promise; }; }; + 'send-soundboard-sound': { + post(args: RestArguments): Promise; + }; }; } diff --git a/src/api/Routes/guilds.ts b/src/api/Routes/guilds.ts index 0944cd8..60576f9 100644 --- a/src/api/Routes/guilds.ts +++ b/src/api/Routes/guilds.ts @@ -43,6 +43,7 @@ import type { RESTGetAPIGuildScheduledEventUsersResult, RESTGetAPIGuildScheduledEventsQuery, RESTGetAPIGuildScheduledEventsResult, + RESTGetAPIGuildSoundboardSoundsResult, RESTGetAPIGuildStickerResult, RESTGetAPIGuildStickersResult, RESTGetAPIGuildTemplatesResult, @@ -74,6 +75,8 @@ import type { RESTPatchAPIGuildRoleResult, RESTPatchAPIGuildScheduledEventJSONBody, RESTPatchAPIGuildScheduledEventResult, + RESTPatchAPIGuildSoundboardSound, + RESTPatchAPIGuildSoundboardSoundResult, RESTPatchAPIGuildStickerJSONBody, RESTPatchAPIGuildStickerResult, RESTPatchAPIGuildTemplateJSONBody, @@ -100,6 +103,8 @@ import type { RESTPostAPIGuildRoleResult, RESTPostAPIGuildScheduledEventJSONBody, RESTPostAPIGuildScheduledEventResult, + RESTPostAPIGuildSoundboardSound, + RESTPostAPIGuildSoundboardSoundResult, RESTPostAPIGuildStickerFormDataBody, RESTPostAPIGuildStickerResult, RESTPostAPIGuildTemplatesJSONBody, @@ -346,6 +351,19 @@ export interface GuildRoutes { delete(args?: RestArgumentsNoBody): Promise; }; }; + 'soundboard-sounds': { + get(args?: RestArgumentsNoBody): Promise; + post(args: RestArguments): Promise; + ( + id: string, + ): { + get(args?: RestArgumentsNoBody): Promise; + patch( + args?: RestArguments, + ): Promise; + delete(args?: RestArgumentsNoBody): Promise; + }; + }; }; }; } diff --git a/src/api/Routes/index.ts b/src/api/Routes/index.ts index 2b71bf5..35d3cdf 100644 --- a/src/api/Routes/index.ts +++ b/src/api/Routes/index.ts @@ -4,12 +4,12 @@ import type { GatewayRoutes } from './gateway'; import type { GuildRoutes } from './guilds'; import type { InteractionRoutes } from './interactions'; import type { InviteRoutes } from './invites'; +import type { SoundboardRoutes } from './soundboard'; import type { StageInstanceRoutes } from './stage-instances'; import type { StickerRoutes } from './stickers'; import type { UserRoutes } from './users'; import type { VoiceRoutes } from './voice'; import type { WebhookRoutes } from './webhooks'; -export type { SoundboardRoutes } from './soundboard'; export * from './cdn'; @@ -24,4 +24,5 @@ export interface APIRoutes StickerRoutes, UserRoutes, VoiceRoutes, - WebhookRoutes {} + WebhookRoutes, + SoundboardRoutes {} diff --git a/src/api/Routes/soundboard.ts b/src/api/Routes/soundboard.ts index 5e9eafc..3dce4cf 100644 --- a/src/api/Routes/soundboard.ts +++ b/src/api/Routes/soundboard.ts @@ -1,36 +1,8 @@ -import type { - RESTGetAPIDefaultsSoundboardSoundsResult, - RESTGetAPIGuildSoundboardSoundsResult, - RESTPatchAPIGuildSoundboardSound, - RESTPatchAPIGuildSoundboardSoundResult, - RESTPostAPIGuildSoundboardSound, - RESTPostAPIGuildSoundboardSoundResult, - RESTPostAPISendSoundboardSound, -} from '../../types'; -import type { RestArguments, RestArgumentsNoBody } from '../api'; +import type { RESTGetAPIDefaultsSoundboardSoundsResult } from '../../types'; +import type { RestArgumentsNoBody } from '../api'; export interface SoundboardRoutes { - channels(id: string): { - 'send-soundboard-sound': { - post(args: RestArguments): Promise; - }; - }; 'soundboard-default-sounds': { get(args?: RestArgumentsNoBody): Promise; }; - guilds(id: string): { - get(args?: RestArgumentsNoBody): Promise; - 'soundboard-sounds': { - post( - args: RestArguments, - ): Promise; - ( - id: string, - ): { - get(args?: RestArgumentsNoBody): Promise; - patch(args?: RestArguments): Promise; - delete(args?: RestArgumentsNoBody): Promise; - }; - }; - }; } diff --git a/src/client/base.ts b/src/client/base.ts index 9af6783..dbc3966 100644 --- a/src/client/base.ts +++ b/src/client/base.ts @@ -43,6 +43,7 @@ import { promises } from 'node:fs'; import { isBufferLike } from '../api/utils/utils'; import { HandleCommand } from '../commands/handle'; import { BanShorter } from '../common/shorters/bans'; +import { SoundboardShorter } from '../common/shorters/soundboard'; import { VoiceStateShorter } from '../common/shorters/voiceStates'; import type { Awaitable, DeepPartial, IntentStrings, OmitInsert, PermissionStrings, When } from '../common/types/util'; import type { ComponentCommand, ComponentContext, ModalCommand, ModalContext } from '../components'; @@ -78,6 +79,7 @@ export class BaseClient { bans = new BanShorter(this); interactions = new InteractionShorter(this); voiceStates = new VoiceStateShorter(this); + soundboards = new SoundboardShorter(this); debugger?: Logger; diff --git a/src/common/shorters/soundboard.ts b/src/common/shorters/soundboard.ts new file mode 100644 index 0000000..fd6b22b --- /dev/null +++ b/src/common/shorters/soundboard.ts @@ -0,0 +1,42 @@ +import type { + RESTPatchAPIGuildSoundboardSound, + RESTPostAPIGuildSoundboardSound, + RESTPostAPISendSoundboardSound, +} from '../../types'; +import { BaseShorter } from './base'; + +export class SoundboardShorter extends BaseShorter { + getDefaults() { + return this.client.proxy['soundboard-default-sounds'].get(); + } + + send(channelId: string, body: RESTPostAPISendSoundboardSound) { + return this.client.proxy.channels(channelId)['send-soundboard-sound'].post({ + body, + }); + } + + list(guildId: string) { + return this.client.proxy.guilds(guildId)['soundboard-sounds'].get(); + } + + get(guildId: string, soundID: string) { + return this.client.proxy.guilds(guildId)['soundboard-sounds'](soundID).get(); + } + + create(guildId: string, body: RESTPostAPIGuildSoundboardSound) { + return this.client.proxy.guilds(guildId)['soundboard-sounds'].post({ + body, + }); + } + + edit(guildId: string, soundID: string, body: RESTPatchAPIGuildSoundboardSound) { + return this.client.proxy.guilds(guildId)['soundboard-sounds'](soundID).patch({ + body, + }); + } + + delete(guildId: string, soundID: string, reason?: string) { + return this.client.proxy.guilds(guildId)['soundboard-sounds'](soundID).delete({ reason }); + } +} diff --git a/src/events/handler.ts b/src/events/handler.ts index 8d57a1e..17c2086 100644 --- a/src/events/handler.ts +++ b/src/events/handler.ts @@ -215,7 +215,7 @@ export class EventHandler extends BaseHandler { t: name, d: packet, } as GatewayDispatchPayload); - await Event.run(hook, client, shardId); + await (Event.run as any)(hook, client, shardId); } catch (e) { await this.onFail(name, e); } @@ -236,8 +236,7 @@ export class EventHandler extends BaseHandler { this.logger.debug(`executed a custom event [${name}]`, Event.data.once ? 'once' : ''); await Promise.all([ - // @ts-expect-error - Event.run(...args, this.client), + (Event.run as any)(...args, this.client), // @ts-expect-error this.client.collectors.run(name, args, this.client), ]);