Files
discordeno/helpers/channels/threads/getArchivedThreads.ts
ITOH 03996c5f58 refactor: revert "feat: base plugin lib idea (#2308)" (#2336)
* Revert "feat: base plugin lib idea (#2308)"

This reverts commit ffe7cdbc6f.

* fmt
2022-07-02 14:24:43 +01:00

49 lines
1.5 KiB
TypeScript

import { Collection } from "../../../util/collection.ts";
import type { Bot } from "../../../bot.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?: ListArchivedThreads & {
type?: "public" | "private" | "privateJoinedThreads";
},
) {
let url = options?.type === "privateJoinedThreads"
? bot.constants.routes.THREAD_ARCHIVED_PRIVATE_JOINED(channelId, options)
: options?.type === "private"
? bot.constants.routes.THREAD_ARCHIVED_PRIVATE(channelId, options)
: bot.constants.routes.THREAD_ARCHIVED_PUBLIC(channelId, options);
const result = (await bot.rest.runMethod<DiscordListArchivedThreads>(
bot.rest,
"GET",
url,
));
return {
threads: new Collection(
result.threads.map((t) => {
const thread = bot.transformers.channel(bot, { channel: t });
return [thread.id, thread];
}),
),
members: new Collection(
result.members.map((m) => {
const member = bot.transformers.threadMember(bot, m);
return [member.id, member];
}),
),
hasMore: result.has_more,
};
}
/** 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;
}