From 80b9edf512ebdb3d3a49a2a63a7032f2b62fa160 Mon Sep 17 00:00:00 2001 From: MARCROCK22 Date: Thu, 23 Jan 2025 22:12:00 -0400 Subject: [PATCH] fix: return cache types --- src/commands/applications/chatcontext.ts | 2 +- src/commands/applications/entrycontext.ts | 2 +- src/structures/AutoModerationRule.ts | 2 +- src/structures/Guild.ts | 4 ++-- src/structures/GuildBan.ts | 2 +- src/structures/GuildEmoji.ts | 2 +- src/structures/GuildMember.ts | 9 ++++----- src/structures/GuildRole.ts | 2 +- src/structures/GuildTemplate.ts | 2 +- src/structures/Interaction.ts | 2 +- src/structures/Poll.ts | 12 ++++++++++-- src/structures/Sticker.ts | 2 +- src/structures/VoiceState.ts | 10 ++++++++-- src/structures/Webhook.ts | 2 +- src/structures/extra/BaseGuild.ts | 3 +-- 15 files changed, 35 insertions(+), 23 deletions(-) diff --git a/src/commands/applications/chatcontext.ts b/src/commands/applications/chatcontext.ts index b0860cc..e451913 100644 --- a/src/commands/applications/chatcontext.ts +++ b/src/commands/applications/chatcontext.ts @@ -1,4 +1,4 @@ -import type { ReturnCache } from '../..'; +import type { ReturnCache } from '../../cache'; import type { Client, WorkerClient } from '../../client'; import type { GuildMemberStructure, diff --git a/src/commands/applications/entrycontext.ts b/src/commands/applications/entrycontext.ts index ed510a8..3ee9ee5 100644 --- a/src/commands/applications/entrycontext.ts +++ b/src/commands/applications/entrycontext.ts @@ -1,4 +1,4 @@ -import type { ReturnCache } from '../..'; +import type { ReturnCache } from '../../cache'; import type { GuildMemberStructure, GuildStructure, diff --git a/src/structures/AutoModerationRule.ts b/src/structures/AutoModerationRule.ts index e05f119..0370e2f 100644 --- a/src/structures/AutoModerationRule.ts +++ b/src/structures/AutoModerationRule.ts @@ -1,4 +1,4 @@ -import type { ReturnCache } from '../../src'; +import type { ReturnCache } from '../cache'; import type { AutoModerationRuleStructure, GuildMemberStructure, GuildStructure } from '../client'; import type { UsingClient } from '../commands'; import type { MethodContext, ObjectToLower } from '../common'; diff --git a/src/structures/Guild.ts b/src/structures/Guild.ts index 00f88c8..f5983d8 100644 --- a/src/structures/Guild.ts +++ b/src/structures/Guild.ts @@ -1,4 +1,4 @@ -import type { GuildMemberStructure } from '../client'; +import type { GuildMemberStructure, GuildStructure } from '../client'; import type { UsingClient } from '../commands'; import type { ObjectToLower, StructPropState, StructStates, ToClass } from '../common/types/util'; import type { APIGuild, APIPartialGuild, GatewayGuildCreateDispatchData, RESTPatchAPIGuildJSONBody } from '../types'; @@ -79,7 +79,7 @@ export class Guild extends (BaseGuild as unk emojis = GuildEmoji.methods({ client: this.client, guildId: this.id }); bans = GuildBan.methods({ client: this.client, guildId: this.id }); - edit(body: RESTPatchAPIGuildJSONBody, reason?: string) { + edit(body: RESTPatchAPIGuildJSONBody, reason?: string): Promise> { return this.client.guilds.edit(this.id, body, reason); } } diff --git a/src/structures/GuildBan.ts b/src/structures/GuildBan.ts index 1c6ad7e..d0ae6f6 100644 --- a/src/structures/GuildBan.ts +++ b/src/structures/GuildBan.ts @@ -1,4 +1,4 @@ -import type { ReturnCache } from '../../src'; +import type { ReturnCache } from '../cache'; import type { GuildBanStructure, GuildStructure } from '../client'; import type { UsingClient } from '../commands'; import { Formatter, type MethodContext, type ObjectToLower } from '../common'; diff --git a/src/structures/GuildEmoji.ts b/src/structures/GuildEmoji.ts index 4d6921b..6cdaeae 100644 --- a/src/structures/GuildEmoji.ts +++ b/src/structures/GuildEmoji.ts @@ -1,5 +1,5 @@ -import type { ReturnCache } from '../../src'; import type { BaseCDNUrlOptions } from '../api'; +import type { ReturnCache } from '../cache'; import type { GuildEmojiStructure, GuildStructure } from '../client'; import type { UsingClient } from '../commands'; import { type EmojiShorter, Formatter, type MethodContext, type ObjectToLower } from '../common'; diff --git a/src/structures/GuildMember.ts b/src/structures/GuildMember.ts index 63d8eaa..cb5f6c0 100644 --- a/src/structures/GuildMember.ts +++ b/src/structures/GuildMember.ts @@ -7,7 +7,7 @@ export type GuildMemberData = | GatewayGuildMemberAddDispatchData | APIInteractionDataResolvedGuildMember; -import type { ReturnCache } from '../'; +import type { GuildRoleStructure, ReturnCache } from '../'; import { type DMChannelStructure, type GuildMemberStructure, @@ -38,7 +38,6 @@ import type { RESTPutAPIGuildBanJSONBody, RESTPutAPIGuildMemberJSONBody, } from '../types'; -import type { GuildRole } from './GuildRole'; import { PermissionsBitField } from './extra/Permissions'; export interface BaseGuildMember extends DiscordBase, ObjectToLower> {} @@ -133,7 +132,7 @@ export class BaseGuildMember extends DiscordBase { get roles() { return { keys: Object.freeze(this._roles.concat(this.guildId)) as string[], - list: (force = false): Promise => + list: (force = false): Promise => this.client.roles .list(this.guildId, force) .then(roles => roles.filter(role => this.roles.keys.includes(role.id))), @@ -141,9 +140,9 @@ export class BaseGuildMember extends DiscordBase { remove: (id: string) => this.client.members.removeRole(this.guildId, this.id, id), permissions: (force = false) => this.roles.list(force).then(roles => new PermissionsBitField(roles.map(x => BigInt(x.permissions.bits)))), - sorted: (force = false): Promise => + sorted: (force = false): Promise => this.roles.list(force).then(roles => roles.sort((a, b) => b.position - a.position)), - highest: (force = false): Promise => this.roles.sorted(force).then(roles => roles[0]), + highest: (force = false): Promise => this.roles.sorted(force).then(roles => roles[0]), }; } diff --git a/src/structures/GuildRole.ts b/src/structures/GuildRole.ts index b33ede2..200674d 100644 --- a/src/structures/GuildRole.ts +++ b/src/structures/GuildRole.ts @@ -1,4 +1,4 @@ -import type { ReturnCache } from '../../src'; +import type { ReturnCache } from '../cache'; import type { GuildRoleStructure, GuildStructure } from '../client'; import type { UsingClient } from '../commands'; import { Formatter, type MethodContext, type ObjectToLower } from '../common'; diff --git a/src/structures/GuildTemplate.ts b/src/structures/GuildTemplate.ts index 8db3393..bc00479 100644 --- a/src/structures/GuildTemplate.ts +++ b/src/structures/GuildTemplate.ts @@ -1,4 +1,4 @@ -import type { ReturnCache } from '../../src'; +import type { ReturnCache } from '../cache'; import type { GuildStructure, GuildTemplateStructure } from '../client'; import type { UsingClient } from '../commands'; import type { MethodContext, ObjectToLower } from '../common'; diff --git a/src/structures/Interaction.ts b/src/structures/Interaction.ts index 866e6b8..82b2d12 100644 --- a/src/structures/Interaction.ts +++ b/src/structures/Interaction.ts @@ -42,9 +42,9 @@ import { type RESTPostAPIInteractionCallbackResult, } from '../types'; -import type { ReturnCache } from '../../src'; import type { RawFile } from '../api'; import { ActionRow, Embed, Modal, PollBuilder, resolveAttachment, resolveFiles } from '../builders'; +import type { ReturnCache } from '../cache'; import { type EntitlementStructure, type GuildRoleStructure, diff --git a/src/structures/Poll.ts b/src/structures/Poll.ts index e59bc4c..643c27b 100644 --- a/src/structures/Poll.ts +++ b/src/structures/Poll.ts @@ -30,8 +30,16 @@ export class Poll extends Base { return this.client.messages.endPoll(this.channelId, this.messageId); } - getAnswerVoters(id: ValidAnswerId): Promise { - if (!this.answers.find(x => x.answerId === id)) throw new Error('Invalid answer id'); + /** + * @param id - The ID of the answer whose voters need to be fetched. + * @param checkAnswer - A flag that determines if the answer ID should be validated before fetching voters. + * Default is `false`. If `true`, the method checks if the answer ID exists in the list + * of answers and throws an error if not. + */ + async getAnswerVoters(id: ValidAnswerId, checkAnswer = false): Promise { + if (checkAnswer && !this.answers.find(answer => answer.answerId === id)) { + throw new Error('Invalid answer id'); + } return this.client.messages.getAnswerVoters(this.channelId, this.messageId, id); } } diff --git a/src/structures/Sticker.ts b/src/structures/Sticker.ts index ebea926..fc58af9 100644 --- a/src/structures/Sticker.ts +++ b/src/structures/Sticker.ts @@ -1,6 +1,6 @@ import type { GuildStructure, RawFile, StickerStructure, UsingClient } from '..'; -import type { ReturnCache } from '../../src'; import type { Attachment, AttachmentBuilder } from '../builders'; +import type { ReturnCache } from '../cache'; import { Transformers, type UserStructure } from '../client/transformers'; import type { MethodContext, ObjectToLower } from '../common'; import type { APISticker, RESTPatchAPIGuildStickerJSONBody, RESTPostAPIGuildStickerFormDataBody } from '../types'; diff --git a/src/structures/VoiceState.ts b/src/structures/VoiceState.ts index d66a383..08d429e 100644 --- a/src/structures/VoiceState.ts +++ b/src/structures/VoiceState.ts @@ -1,5 +1,11 @@ -import type { AllGuildVoiceChannels, UserStructure, UsingClient, VoiceStateStructure } from '../'; -import type { GuildStructure, ReturnCache } from '../../src'; +import type { + AllGuildVoiceChannels, + GuildStructure, + ReturnCache, + UserStructure, + UsingClient, + VoiceStateStructure, +} from '../'; import type { VoiceStateResource } from '../cache/resources/voice-states'; import { type GuildMemberStructure, Transformers } from '../client/transformers'; import type { ObjectToLower } from '../common'; diff --git a/src/structures/Webhook.ts b/src/structures/Webhook.ts index 097db4d..db81ea0 100644 --- a/src/structures/Webhook.ts +++ b/src/structures/Webhook.ts @@ -1,4 +1,4 @@ -import type { ReturnCache } from '../../src'; +import type { ReturnCache } from '../cache'; import { type AnonymousGuildStructure, type GuildStructure, diff --git a/src/structures/extra/BaseGuild.ts b/src/structures/extra/BaseGuild.ts index 6584878..d82a983 100644 --- a/src/structures/extra/BaseGuild.ts +++ b/src/structures/extra/BaseGuild.ts @@ -1,5 +1,4 @@ -import type { WorkerClient } from '../..'; -import type { ReturnCache } from '../../../src'; +import type { ReturnCache, WorkerClient } from '../..'; import type { GuildStructure } from '../../client'; import { type ObjectToLower, calculateShardId } from '../../common'; import type { ImageOptions } from '../../common/types/options';