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 <to@itoh.at>

* convert before number timestampt to ISO string

Co-authored-by: ITOH <to@itoh.at>
This commit is contained in:
LTS20050703
2022-05-15 14:14:45 -04:00
committed by GitHub
co-authored by ITOH
parent 73e34b262d
commit c2e3ef47b9
2 changed files with 14 additions and 12 deletions
+9 -12
View File
@@ -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<DiscordListActiveThreads>(
const result = (await bot.rest.runMethod<DiscordListArchivedThreads>(
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;
}
+5
View File
@@ -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;