feat: soundboard missing things (#10850)

This commit is contained in:
Danial Raza
2025-04-26 01:49:05 +02:00
committed by GitHub
parent 1605a2c289
commit 2d817df3b5
3 changed files with 57 additions and 19 deletions

View File

@@ -157,35 +157,57 @@ class GuildSoundboardSoundManager extends CachedManager {
await this.client.rest.delete(Routes.guildSoundboardSound(this.guild.id, soundId), { reason });
}
/**
* Options used to fetch a soundboard sound.
* @typedef {BaseFetchOptions} FetchSoundboardSoundOptions
* @property {SoundboardSoundResolvable} soundboardSound The soundboard sound to fetch
*/
/**
* Options used to fetch soundboard sounds from Discord
* @typedef {Object} FetchGuildSoundboardSoundsOptions
* @property {boolean} [cache] Whether to cache the fetched soundboard sounds
*/
/* eslint-disable max-len */
/**
* Obtains one or more soundboard sounds from Discord, or the soundboard sound cache if they're already available.
* @param {Snowflake} [id] The soundboard sound's id
* @param {BaseFetchOptions} [options] Additional options for this fetch
* @param {SoundboardSoundResolvable|FetchSoundboardSoundOptions|FetchGuildSoundboardSoundsOptions} [options] Options for fetching soundboard sound(s)
* @returns {Promise<SoundboardSound|Collection<Snowflake, SoundboardSound>>}
* @example
* // Fetch all soundboard sounds from the guild
* guild.soundboardSounds.fetch()
* .then(sounds => console.log(`There are ${sounds.size} soundboard sounds.`))
* .catch(console.error);
* @example
* // Fetch a single soundboard sound
* guild.soundboardSounds.fetch('222078108977594368')
* .then(sound => console.log(`The soundboard sound name is: ${sound.name}`))
* .catch(console.error);
* @example
* // Fetch all soundboard sounds from the guild
* guild.soundboardSounds.fetch()
* .then(sounds => console.log(`There are ${sounds.size} soundboard sounds.`))
* .catch(console.error);
*/
async fetch(id, { cache = true, force = false } = {}) {
if (id) {
if (!force) {
const existing = this.cache.get(id);
if (existing) return existing;
}
/* eslint-enable max-len */
async fetch(options) {
if (!options) return this._fetchMany();
const { cache, force, soundboardSound } = options;
const resolvedSoundboardSound = this.resolveId(soundboardSound ?? options);
if (resolvedSoundboardSound) return this._fetchSingle({ cache, force, soundboardSound });
return this._fetchMany({ cache });
}
const sound = await this.client.rest.get(Routes.guildSoundboardSound(this.guild.id, id));
return this._add(sound, cache);
async _fetchSingle({ cache, force, soundboardSound } = {}) {
if (!force) {
const existing = this.cache.get(soundboardSound);
if (existing) return existing;
}
const data = await this.client.rest.get(Routes.guildSoundboardSound(this.guild.id, soundboardSound));
return this._add(data, cache);
}
async _fetchMany({ cache } = {}) {
const data = await this.client.rest.get(Routes.guildSoundboardSounds(this.guild.id));
return new Collection(data.map(sound => [sound.sound_id, this._add(sound, cache)]));
return data.items.reduce((coll, sound) => coll.set(sound.sound_id, this._add(sound, cache)), new Collection());
}
}

View File

@@ -32,6 +32,7 @@ const Targets = {
AutoModeration: 'AutoModeration',
GuildOnboarding: 'GuildOnboarding',
GuildOnboardingPrompt: 'GuildOnboardingPrompt',
SoundboardSound: 'SoundboardSound',
Unknown: 'Unknown',
};
@@ -87,6 +88,7 @@ const Targets = {
* * ApplicationCommandPermission
* * GuildOnboarding
* * GuildOnboardingPrompt
* * SoundboardSound
* * Unknown
* @typedef {string} AuditLogTargetType
*/
@@ -395,7 +397,8 @@ class GuildAuditLogsEntry {
if (target < 110) return Targets.GuildScheduledEvent;
if (target < 120) return Targets.Thread;
if (target < 130) return Targets.ApplicationCommand;
if (target >= 140 && target < 150) return Targets.AutoModeration;
if (target < 140) return Targets.SoundboardSound;
if (target >= 143 && target < 150) return Targets.AutoModeration;
if (target >= 163 && target <= 165) return Targets.GuildOnboardingPrompt;
if (target >= 160 && target < 170) return Targets.GuildOnboarding;
return Targets.Unknown;
@@ -423,6 +426,7 @@ class GuildAuditLogsEntry {
AuditLogEvent.StickerCreate,
AuditLogEvent.GuildScheduledEventCreate,
AuditLogEvent.ThreadCreate,
AuditLogEvent.SoundboardSoundCreate,
AuditLogEvent.AutoModerationRuleCreate,
AuditLogEvent.AutoModerationBlockMessage,
AuditLogEvent.OnboardingPromptCreate,
@@ -452,6 +456,7 @@ class GuildAuditLogsEntry {
AuditLogEvent.StickerDelete,
AuditLogEvent.GuildScheduledEventDelete,
AuditLogEvent.ThreadDelete,
AuditLogEvent.SoundboardSoundDelete,
AuditLogEvent.AutoModerationRuleDelete,
AuditLogEvent.OnboardingPromptDelete,
].includes(action)
@@ -476,6 +481,7 @@ class GuildAuditLogsEntry {
AuditLogEvent.StickerUpdate,
AuditLogEvent.GuildScheduledEventUpdate,
AuditLogEvent.ThreadUpdate,
AuditLogEvent.SoundboardSoundUpdate,
AuditLogEvent.ApplicationCommandPermissionUpdate,
AuditLogEvent.AutoModerationRuleUpdate,
AuditLogEvent.OnboardingPromptUpdate,

View File

@@ -4862,6 +4862,12 @@ export interface GuildSoundboardSoundEditOptions {
emojiName?: string | null;
}
export interface FetchGuildSoundboardSoundOptions extends BaseFetchOptions {
soundboardSound: SoundboardSoundResolvable;
}
export interface FetchGuildSoundboardSoundsOptions extends Pick<BaseFetchOptions, 'cache'> {}
export class GuildSoundboardSoundManager extends CachedManager<Snowflake, SoundboardSound, SoundboardSoundResolvable> {
private constructor(guild: Guild, iterable?: Iterable<APISoundboardSound>);
public guild: Guild;
@@ -4871,8 +4877,8 @@ export class GuildSoundboardSoundManager extends CachedManager<Snowflake, Soundb
options: GuildSoundboardSoundEditOptions,
): Promise<GuildSoundboardSound>;
public delete(soundboardSound: SoundboardSoundResolvable): Promise<void>;
public fetch(id: Snowflake, options?: BaseFetchOptions): Promise<GuildSoundboardSound>;
public fetch(options?: BaseFetchOptions): Promise<Collection<Snowflake, GuildSoundboardSound>>;
public fetch(options: SoundboardSoundResolvable | FetchGuildSoundboardSoundOptions): Promise<GuildSoundboardSound>;
public fetch(options?: FetchGuildSoundboardSoundsOptions): Promise<Collection<Snowflake, GuildSoundboardSound>>;
}
export class GuildStickerManager extends CachedManager<Snowflake, Sticker, StickerResolvable> {
@@ -6334,6 +6340,9 @@ interface GuildAuditLogsTypes {
[AuditLogEvent.ThreadUpdate]: ['Thread', 'Update'];
[AuditLogEvent.ThreadDelete]: ['Thread', 'Delete'];
[AuditLogEvent.ApplicationCommandPermissionUpdate]: ['ApplicationCommand', 'Update'];
[AuditLogEvent.SoundboardSoundCreate]: ['SoundboardSound', 'Create'];
[AuditLogEvent.SoundboardSoundUpdate]: ['SoundboardSound', 'Update'];
[AuditLogEvent.SoundboardSoundDelete]: ['SoundboardSound', 'Delete'];
[AuditLogEvent.AutoModerationRuleCreate]: ['AutoModeration', 'Create'];
[AuditLogEvent.AutoModerationRuleUpdate]: ['AutoModeration', 'Update'];
[AuditLogEvent.AutoModerationRuleDelete]: ['AutoModeration', 'Delete'];
@@ -6410,6 +6419,7 @@ export interface GuildAuditLogsEntryTargetField<TActionType extends GuildAuditLo
ApplicationCommand: ApplicationCommand | { id: Snowflake };
AutoModerationRule: AutoModerationRule;
GuildOnboardingPrompt: GuildOnboardingPrompt;
SoundboardSound: { id: Snowflake };
}
export interface GuildAuditLogsFetchOptions<Event extends GuildAuditLogsResolvable> {