From c2e3ef47b957a3656e0b7622e650800323eb76ed Mon Sep 17 00:00:00 2001 From: LTS20050703 <87189679+lts20050703@users.noreply.github.com> Date: Mon, 16 May 2022 01:14:45 +0700 Subject: [PATCH] fix(rest,types): `getArchivedThreads` `before` option and wrong return type (#2222) * deno fmt * fix: getArchivedThreads options and return type * Update types/discord.ts Co-authored-by: ITOH * convert before number timestampt to ISO string Co-authored-by: ITOH --- .../channels/threads/getArchivedThreads.ts | 21 ++++++++----------- types/discord.ts | 5 +++++ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/helpers/channels/threads/getArchivedThreads.ts b/helpers/channels/threads/getArchivedThreads.ts index 52cd7b10d..4d23295ec 100644 --- a/helpers/channels/threads/getArchivedThreads.ts +++ b/helpers/channels/threads/getArchivedThreads.ts @@ -1,12 +1,12 @@ import { Collection } from "../../../util/collection.ts"; import type { Bot } from "../../../bot.ts"; -import { DiscordListActiveThreads } from "../../../types/discord.ts"; +import { DiscordListArchivedThreads } from "../../../types/discord.ts"; /** Get the archived threads for this channel, defaults to public */ export async function getArchivedThreads( bot: Bot, channelId: bigint, - options?: ListPublicArchivedThreads & { + options?: ListArchivedThreads & { type?: "public" | "private" | "privateJoinedThreads"; }, ) { @@ -15,20 +15,17 @@ export async function getArchivedThreads( : options?.type === "private" ? bot.constants.endpoints.THREAD_ARCHIVED_PRIVATE(channelId) : bot.constants.endpoints.THREAD_ARCHIVED_PUBLIC(channelId); - if (options) { url += "?"; - if (options.before) url += `before=${options.before}`; + if (options.before) url += `before=${new Date(options.before).toISOString()}`; if (options.limit) url += `&limit=${options.limit}`; - if (options.type) url += `&type=${options.type}`; } - const result = (await bot.rest.runMethod( + const result = (await bot.rest.runMethod( bot.rest, "get", url, )); - return { threads: new Collection( result.threads.map((t) => { @@ -42,14 +39,14 @@ export async function getArchivedThreads( return [member.id, member]; }), ), + hasMore: result.has_more, }; } -// TODO: add docs link -export interface ListPublicArchivedThreads { - // TODO: convert unix to ISO9601 timestamp - /** Returns threads before this timestamp. UNIX or ISO8601 timestamp */ - before?: number | string; +/** https://discord.com/developers/docs/resources/channel#list-public-archived-threads-query-string-params */ +export interface ListArchivedThreads { + /** Returns threads before this timestamp */ + before?: number; /** Optional maximum number of threads to return */ limit?: number; } diff --git a/types/discord.ts b/types/discord.ts index cb2c3b924..4f7e428b3 100644 --- a/types/discord.ts +++ b/types/discord.ts @@ -1368,6 +1368,11 @@ export interface DiscordListActiveThreads { members: DiscordThreadMember[]; } +export interface DiscordListArchivedThreads extends DiscordListActiveThreads { + /** Whether there are potentially additional threads that could be returned on a subsequent call */ + has_more: boolean; +} + export interface DiscordThreadListSync { /** The id of the guild */ guild_id: string;