From d6a305a37168978204ffc738fd78b34a9be6f3ec Mon Sep 17 00:00:00 2001 From: Xeno Date: Sun, 17 Nov 2024 00:12:34 +0530 Subject: [PATCH] feat(MessageMethods#list): implements /channels/{channel.id}/messages for getting bulk messages (#297) * feat(Formatter#generateOAuth2URL): addition of a new method for creating discord oauth2 links * feat(MessageMethods#list): implements /channels/{channel.id}/messages for getting bulk messages --- src/common/shorters/messages.ts | 10 +++++++++- src/structures/channels.ts | 7 ++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/common/shorters/messages.ts b/src/common/shorters/messages.ts index cb89c26..d348f91 100644 --- a/src/common/shorters/messages.ts +++ b/src/common/shorters/messages.ts @@ -1,13 +1,14 @@ import { resolveFiles } from '../../builders'; import { MessagesMethods } from '../../structures'; import type { + RESTGetAPIChannelMessagesQuery, RESTPatchAPIChannelMessageJSONBody, RESTPostAPIChannelMessageJSONBody, RESTPostAPIChannelMessagesThreadsJSONBody, } from '../../types'; import type { ValidAnswerId } from '../../api/Routes/channels'; -import { Transformers } from '../../client/transformers'; +import { Transformers } from '../../client'; import type { MessageCreateBodyRequest, MessageUpdateBodyRequest } from '../types/write'; import { BaseShorter } from './base'; @@ -111,4 +112,11 @@ export class MessageShorter extends BaseShorter { .get() .then(data => data.users.map(user => Transformers.User(this.client, user))); } + + list(channelId: string, fetchOptions: RESTGetAPIChannelMessagesQuery) { + return this.client.proxy + .channels(channelId) + .messages.get({ query: fetchOptions }) + .then(messages => messages.map(message => Transformers.Message(this.client, message))); + } } diff --git a/src/structures/channels.ts b/src/structures/channels.ts index aea63a4..334d469 100644 --- a/src/structures/channels.ts +++ b/src/structures/channels.ts @@ -15,7 +15,7 @@ import { type ThreadChannelStructure, Transformers, type VoiceChannelStructure, -} from '../client/transformers'; +} from '../client'; import type { UsingClient } from '../commands'; import type { EmojiResolvable, @@ -45,6 +45,7 @@ import { ChannelType, type RESTAPIAttachment, type RESTGetAPIChannelMessageReactionUsersQuery, + type RESTGetAPIChannelMessagesQuery, type RESTPatchAPIChannelJSONBody, type RESTPatchAPIGuildChannelPositionsJSONBody, type RESTPostAPIChannelWebhookJSONBody, @@ -253,6 +254,7 @@ export class MessagesMethods extends DiscordBase { delete: (messageId: string, reason?: string) => ctx.client.messages.delete(messageId, ctx.channelId, reason), fetch: (messageId: string) => ctx.client.messages.fetch(messageId, ctx.channelId), purge: (messages: string[], reason?: string) => ctx.client.messages.purge(messages, ctx.channelId, reason), + list: (fetchOptions: RESTGetAPIChannelMessagesQuery) => ctx.client.messages.list(ctx.channelId, fetchOptions), }; } @@ -406,8 +408,7 @@ export class VoiceChannelMethods extends DiscordBase { if (!this.guildId) return []; const states = await this.cache.voiceStates?.values(this.guildId); if (!states?.length) return []; - const filter = states.filter(state => state.channelId === this.id); - return filter; + return states.filter(state => state.channelId === this.id); } public async members(force?: boolean) {