fix: needless getter

This commit is contained in:
Marcos Susaña 2025-01-15 17:24:43 -04:00
parent e2d5813496
commit 316a533696
No known key found for this signature in database

View File

@ -104,284 +104,272 @@ export class GuildShorter extends BaseShorter {
/** /**
* Provides access to channel-related functionality in a guild. * Provides access to channel-related functionality in a guild.
*/ */
get channels() { channels = {
return { /**
/** * Retrieves a list of channels in the guild.
* Retrieves a list of channels in the guild. * @param guildId The ID of the guild.
* @param guildId The ID of the guild. * @param force Whether to force fetching channels from the API even if they exist in the cache.
* @param force Whether to force fetching channels from the API even if they exist in the cache. * @returns A Promise that resolves to an array of channels.
* @returns A Promise that resolves to an array of channels. */
*/ list: async (guildId: string, force = false): Promise<AllChannels[]> => {
list: async (guildId: string, force = false): Promise<AllChannels[]> => { let channels: ReturnType<Channels['values']> | APIChannel[];
let channels: ReturnType<Channels['values']> | APIChannel[]; if (!force) {
if (!force) { channels = (await this.client.cache.channels?.values(guildId)) ?? [];
channels = (await this.client.cache.channels?.values(guildId)) ?? []; if (channels.length) {
if (channels.length) { return channels;
return channels;
}
} }
channels = await this.client.proxy.guilds(guildId).channels.get(); }
await this.client.cache.channels?.set( channels = await this.client.proxy.guilds(guildId).channels.get();
CacheFrom.Rest, await this.client.cache.channels?.set(
channels.map<[string, APIChannel]>(x => [x.id, x]), CacheFrom.Rest,
guildId, channels.map<[string, APIChannel]>(x => [x.id, x]),
); guildId,
return channels.map(m => channelFrom(m, this.client)); );
}, return channels.map(m => channelFrom(m, this.client));
},
/** /**
* Fetches a channel by its ID. * Fetches a channel by its ID.
* @param guildId The ID of the guild. * @param guildId The ID of the guild.
* @param channelId The ID of the channel to fetch. * @param channelId The ID of the channel to fetch.
* @param force Whether to force fetching the channel from the API even if it exists in the cache. * @param force Whether to force fetching the channel from the API even if it exists in the cache.
* @returns A Promise that resolves to the fetched channel. * @returns A Promise that resolves to the fetched channel.
*/ */
fetch: async (guildId: string, channelId: string, force?: boolean) => { fetch: async (guildId: string, channelId: string, force?: boolean) => {
let channel: APIChannel | ReturnType<Channels['get']>; let channel: APIChannel | ReturnType<Channels['get']>;
if (!force) { if (!force) {
channel = await this.client.cache.channels?.get(channelId); channel = await this.client.cache.channels?.get(channelId);
if (channel) return channel as ReturnType<typeof channelFrom>; if (channel) return channel as ReturnType<typeof channelFrom>;
} }
channel = await this.client.proxy.channels(channelId).get(); channel = await this.client.proxy.channels(channelId).get();
await this.client.cache.channels?.patch(CacheFrom.Rest, channelId, guildId, channel); await this.client.cache.channels?.patch(CacheFrom.Rest, channelId, guildId, channel);
return channelFrom(channel, this.client); return channelFrom(channel, this.client);
}, },
/** /**
* Creates a new channel in the guild. * Creates a new channel in the guild.
* @param guildId The ID of the guild. * @param guildId The ID of the guild.
* @param body The data for creating the channel. * @param body The data for creating the channel.
* @returns A Promise that resolves to the created channel. * @returns A Promise that resolves to the created channel.
*/ */
create: async (guildId: string, body: RESTPostAPIGuildChannelJSONBody) => { create: async (guildId: string, body: RESTPostAPIGuildChannelJSONBody) => {
const res = await this.client.proxy.guilds(guildId).channels.post({ body }); const res = await this.client.proxy.guilds(guildId).channels.post({ body });
await this.client.cache.channels?.setIfNI( await this.client.cache.channels?.setIfNI(CacheFrom.Rest, BaseChannel.__intent__(guildId), res.id, guildId, res);
CacheFrom.Rest, return channelFrom(res, this.client);
BaseChannel.__intent__(guildId), },
res.id,
guildId,
res,
);
return channelFrom(res, this.client);
},
/** /**
* Deletes a channel from the guild. * Deletes a channel from the guild.
* @param guildId The ID of the guild. * @param guildId The ID of the guild.
* @param channelId The ID of the channel to delete. * @param channelId The ID of the channel to delete.
* @param reason The reason for deleting the channel. * @param reason The reason for deleting the channel.
* @returns A Promise that resolves to the deleted channel. * @returns A Promise that resolves to the deleted channel.
*/ */
delete: async (guildId: string, channelId: string, reason?: string) => { delete: async (guildId: string, channelId: string, reason?: string) => {
const res = await this.client.proxy.channels(channelId).delete({ reason }); const res = await this.client.proxy.channels(channelId).delete({ reason });
await this.client.cache.channels?.removeIfNI(BaseChannel.__intent__(guildId), res.id, guildId); await this.client.cache.channels?.removeIfNI(BaseChannel.__intent__(guildId), res.id, guildId);
return channelFrom(res, this.client); return channelFrom(res, this.client);
}, },
/** /**
* Edits a channel in the guild. * Edits a channel in the guild.
* @param guildchannelId The ID of the guild. * @param guildchannelId The ID of the guild.
* @param channelId The ID of the channel to edit. * @param channelId The ID of the channel to edit.
* @param body The data to update the channel with. * @param body The data to update the channel with.
* @param reason The reason for editing the channel. * @param reason The reason for editing the channel.
* @returns A Promise that resolves to the edited channel. * @returns A Promise that resolves to the edited channel.
*/ */
edit: async (guildchannelId: string, channelId: string, body: RESTPatchAPIChannelJSONBody, reason?: string) => { edit: async (guildchannelId: string, channelId: string, body: RESTPatchAPIChannelJSONBody, reason?: string) => {
const res = await this.client.proxy.channels(channelId).patch({ body, reason }); const res = await this.client.proxy.channels(channelId).patch({ body, reason });
await this.client.cache.channels?.setIfNI( await this.client.cache.channels?.setIfNI(
CacheFrom.Rest, CacheFrom.Rest,
BaseChannel.__intent__(guildchannelId), BaseChannel.__intent__(guildchannelId),
res.id, res.id,
guildchannelId, guildchannelId,
res, res,
); );
return channelFrom(res, this.client); return channelFrom(res, this.client);
}, },
/** /**
* Edits the positions of channels in the guild. * Edits the positions of channels in the guild.
* @param guildId The ID of the guild. * @param guildId The ID of the guild.
* @param body The data containing the new positions of channels. * @param body The data containing the new positions of channels.
*/ */
editPositions: (guildId: string, body: RESTPatchAPIGuildChannelPositionsJSONBody) => editPositions: (guildId: string, body: RESTPatchAPIGuildChannelPositionsJSONBody) =>
this.client.proxy.guilds(guildId).channels.patch({ body }), this.client.proxy.guilds(guildId).channels.patch({ body }),
addFollower: async (channelId: string, webhook_channel_id: string, reason?: string) => { addFollower: async (channelId: string, webhook_channel_id: string, reason?: string) => {
return this.client.proxy.channels(channelId).followers.post({ return this.client.proxy.channels(channelId).followers.post({
body: { body: {
webhook_channel_id, webhook_channel_id,
}, },
reason, reason,
}); });
}, },
}; };
}
/** /**
* Provides access to auto-moderation rule-related functionality in a guild. * Provides access to auto-moderation rule-related functionality in a guild.
*/ */
get moderation() { moderation = {
return { /**
/** * Retrieves a list of auto-moderation rules in the guild.
* Retrieves a list of auto-moderation rules in the guild. * @param guildId The ID of the guild.
* @param guildId The ID of the guild. * @returns A Promise that resolves to an array of auto-moderation rules.
* @returns A Promise that resolves to an array of auto-moderation rules. */
*/ list: (guildId: string): Promise<AutoModerationRuleStructure[]> =>
list: (guildId: string): Promise<AutoModerationRuleStructure[]> => this.client.proxy
this.client.proxy .guilds(guildId)
.guilds(guildId) ['auto-moderation'].rules.get()
['auto-moderation'].rules.get() .then(rules => rules.map(rule => Transformers.AutoModerationRule(this.client, rule))),
.then(rules => rules.map(rule => Transformers.AutoModerationRule(this.client, rule))),
/** /**
* Creates a new auto-moderation rule in the guild. * Creates a new auto-moderation rule in the guild.
* @param guildId The ID of the guild. * @param guildId The ID of the guild.
* @param body The data for creating the auto-moderation rule. * @param body The data for creating the auto-moderation rule.
* @returns A Promise that resolves to the created auto-moderation rule. * @returns A Promise that resolves to the created auto-moderation rule.
*/ */
create: (guildId: string, body: RESTPostAPIAutoModerationRuleJSONBody): Promise<AutoModerationRuleStructure> => create: (guildId: string, body: RESTPostAPIAutoModerationRuleJSONBody): Promise<AutoModerationRuleStructure> =>
this.client.proxy this.client.proxy
.guilds(guildId) .guilds(guildId)
['auto-moderation'].rules.post({ body }) ['auto-moderation'].rules.post({ body })
.then(rule => Transformers.AutoModerationRule(this.client, rule)), .then(rule => Transformers.AutoModerationRule(this.client, rule)),
/** /**
* Deletes an auto-moderation rule from the guild. * Deletes an auto-moderation rule from the guild.
* @param guildId The ID of the guild. * @param guildId The ID of the guild.
* @param ruleId The ID of the rule to delete. * @param ruleId The ID of the rule to delete.
* @param reason The reason for deleting the rule. * @param reason The reason for deleting the rule.
* @returns A Promise that resolves once the rule is deleted. * @returns A Promise that resolves once the rule is deleted.
*/ */
delete: (guildId: string, ruleId: string, reason?: string) => { delete: (guildId: string, ruleId: string, reason?: string) => {
return this.client.proxy.guilds(guildId)['auto-moderation'].rules(ruleId).delete({ reason }); return this.client.proxy.guilds(guildId)['auto-moderation'].rules(ruleId).delete({ reason });
}, },
/** /**
* Fetches an auto-moderation rule by its ID. * Fetches an auto-moderation rule by its ID.
* @param guildId The ID of the guild. * @param guildId The ID of the guild.
* @param ruleId The ID of the rule to fetch. * @param ruleId The ID of the rule to fetch.
* @returns A Promise that resolves to the fetched auto-moderation rule. * @returns A Promise that resolves to the fetched auto-moderation rule.
*/ */
fetch: (guildId: string, ruleId: string): Promise<AutoModerationRuleStructure> => { fetch: (guildId: string, ruleId: string): Promise<AutoModerationRuleStructure> => {
return this.client.proxy return this.client.proxy
.guilds(guildId) .guilds(guildId)
['auto-moderation'].rules(ruleId) ['auto-moderation'].rules(ruleId)
.get() .get()
.then(rule => Transformers.AutoModerationRule(this.client, rule)); .then(rule => Transformers.AutoModerationRule(this.client, rule));
}, },
/** /**
* Edits an auto-moderation rule in the guild. * Edits an auto-moderation rule in the guild.
* @param guildId The ID of the guild. * @param guildId The ID of the guild.
* @param ruleId The ID of the rule to edit. * @param ruleId The ID of the rule to edit.
* @param body The data to update the rule with. * @param body The data to update the rule with.
* @param reason The reason for editing the rule. * @param reason The reason for editing the rule.
* @returns A Promise that resolves to the edited auto-moderation rule. * @returns A Promise that resolves to the edited auto-moderation rule.
*/ */
edit: ( edit: (
guildId: string, guildId: string,
ruleId: string, ruleId: string,
body: RESTPatchAPIAutoModerationRuleJSONBody, body: RESTPatchAPIAutoModerationRuleJSONBody,
reason?: string, reason?: string,
): Promise<AutoModerationRuleStructure> => { ): Promise<AutoModerationRuleStructure> => {
return this.client.proxy return this.client.proxy
.guilds(guildId) .guilds(guildId)
['auto-moderation'].rules(ruleId) ['auto-moderation'].rules(ruleId)
.patch({ body, reason }) .patch({ body, reason })
.then(rule => Transformers.AutoModerationRule(this.client, rule)); .then(rule => Transformers.AutoModerationRule(this.client, rule));
}, },
}; };
}
/** /**
* Provides access to sticker-related functionality in a guild. * Provides access to sticker-related functionality in a guild.
*/ */
get stickers() { stickers = {
return { /**
/** * Retrieves a list of stickers in the guild.
* Retrieves a list of stickers in the guild. * @param guildId The ID of the guild.
* @param guildId The ID of the guild. * @returns A Promise that resolves to an array of stickers.
* @returns A Promise that resolves to an array of stickers. */
*/ list: async (guildId: string): Promise<StickerStructure[]> => {
list: async (guildId: string): Promise<StickerStructure[]> => { const stickers = await this.client.proxy.guilds(guildId).stickers.get();
const stickers = await this.client.proxy.guilds(guildId).stickers.get(); await this.client.cache.stickers?.set(
await this.client.cache.stickers?.set( CacheFrom.Rest,
CacheFrom.Rest, stickers.map(st => [st.id, st] as any),
stickers.map(st => [st.id, st] as any), guildId,
guildId, );
); return stickers.map(st => Transformers.Sticker(this.client, st));
return stickers.map(st => Transformers.Sticker(this.client, st)); },
},
/** /**
* Creates a new sticker in the guild. * Creates a new sticker in the guild.
* @param guildId The ID of the guild. * @param guildId The ID of the guild.
* @param request The request body for creating the sticker. * @param request The request body for creating the sticker.
* @param reason The reason for creating the sticker. * @param reason The reason for creating the sticker.
* @returns A Promise that resolves to the created sticker. * @returns A Promise that resolves to the created sticker.
*/ */
create: async ( create: async (
guildId: string, guildId: string,
{ file, ...json }: CreateStickerBodyRequest, { file, ...json }: CreateStickerBodyRequest,
reason?: string, reason?: string,
): Promise<StickerStructure> => { ): Promise<StickerStructure> => {
const fileResolve = await resolveFiles([file]); const fileResolve = await resolveFiles([file]);
const sticker = await this.client.proxy const sticker = await this.client.proxy
.guilds(guildId) .guilds(guildId)
.stickers.post({ reason, body: json, files: [{ ...fileResolve[0], key: 'file' }], appendToFormData: true }); .stickers.post({ reason, body: json, files: [{ ...fileResolve[0], key: 'file' }], appendToFormData: true });
await this.client.cache.stickers?.setIfNI(CacheFrom.Rest, 'GuildExpressions', sticker.id, guildId, sticker); await this.client.cache.stickers?.setIfNI(CacheFrom.Rest, 'GuildExpressions', sticker.id, guildId, sticker);
return Transformers.Sticker(this.client, sticker); return Transformers.Sticker(this.client, sticker);
}, },
/** /**
* Edits an existing sticker in the guild. * Edits an existing sticker in the guild.
* @param guildId The ID of the guild. * @param guildId The ID of the guild.
* @param stickerId The ID of the sticker to edit. * @param stickerId The ID of the sticker to edit.
* @param body The data to update the sticker with. * @param body The data to update the sticker with.
* @param reason The reason for editing the sticker. * @param reason The reason for editing the sticker.
* @returns A Promise that resolves to the edited sticker. * @returns A Promise that resolves to the edited sticker.
*/ */
edit: async ( edit: async (
guildId: string, guildId: string,
stickerId: string, stickerId: string,
body: RESTPatchAPIGuildStickerJSONBody, body: RESTPatchAPIGuildStickerJSONBody,
reason?: string, reason?: string,
): Promise<StickerStructure> => { ): Promise<StickerStructure> => {
const sticker = await this.client.proxy.guilds(guildId).stickers(stickerId).patch({ body, reason }); const sticker = await this.client.proxy.guilds(guildId).stickers(stickerId).patch({ body, reason });
await this.client.cache.stickers?.setIfNI(CacheFrom.Rest, 'GuildExpressions', stickerId, guildId, sticker); await this.client.cache.stickers?.setIfNI(CacheFrom.Rest, 'GuildExpressions', stickerId, guildId, sticker);
return Transformers.Sticker(this.client, sticker); return Transformers.Sticker(this.client, sticker);
}, },
/** /**
* Fetches a sticker by its ID from the guild. * Fetches a sticker by its ID from the guild.
* @param guildId The ID of the guild. * @param guildId The ID of the guild.
* @param stickerId The ID of the sticker to fetch. * @param stickerId The ID of the sticker to fetch.
* @param force Whether to force fetching the sticker from the API even if it exists in the cache. * @param force Whether to force fetching the sticker from the API even if it exists in the cache.
* @returns A Promise that resolves to the fetched sticker. * @returns A Promise that resolves to the fetched sticker.
*/ */
fetch: async (guildId: string, stickerId: string, force = false): Promise<StickerStructure> => { fetch: async (guildId: string, stickerId: string, force = false): Promise<StickerStructure> => {
let sticker: APISticker | StickerStructure | undefined; let sticker: APISticker | StickerStructure | undefined;
if (!force) { if (!force) {
sticker = await this.client.cache.stickers?.get(stickerId); sticker = await this.client.cache.stickers?.get(stickerId);
if (sticker) return sticker; if (sticker) return sticker;
} }
sticker = await this.client.proxy.guilds(guildId).stickers(stickerId).get(); sticker = await this.client.proxy.guilds(guildId).stickers(stickerId).get();
await this.client.cache.stickers?.patch(CacheFrom.Rest, stickerId, guildId, sticker); await this.client.cache.stickers?.patch(CacheFrom.Rest, stickerId, guildId, sticker);
return Transformers.Sticker(this.client, sticker); return Transformers.Sticker(this.client, sticker);
}, },
/** /**
* Deletes a sticker from the guild. * Deletes a sticker from the guild.
* @param guildId The ID of the guild. * @param guildId The ID of the guild.
* @param stickerId The ID of the sticker to delete. * @param stickerId The ID of the sticker to delete.
* @param reason The reason for deleting the sticker. * @param reason The reason for deleting the sticker.
* @returns A Promise that resolves once the sticker is deleted. * @returns A Promise that resolves once the sticker is deleted.
*/ */
delete: async (guildId: string, stickerId: string, reason?: string) => { delete: async (guildId: string, stickerId: string, reason?: string) => {
await this.client.proxy.guilds(guildId).stickers(stickerId).delete({ reason }); await this.client.proxy.guilds(guildId).stickers(stickerId).delete({ reason });
await this.client.cache.stickers?.removeIfNI('GuildExpressions', stickerId, guildId); await this.client.cache.stickers?.removeIfNI('GuildExpressions', stickerId, guildId);
}, },
}; };
}
} }