Files
discordeno/helpers/channels/threads/getPublicArchivedThreads.ts
T
Skillz4Killz 3a5bdce32d feat: helpers support strings in args (#2478)
* fix: helpers support strings in args

* fix: fmt
2022-09-15 20:59:02 -05:00

64 lines
2.2 KiB
TypeScript

import type { Bot } from "../../../bot.ts";
import { DiscordListArchivedThreads } from "../../../types/discord.ts";
import { BigString } from "../../../types/shared.ts";
import { Collection } from "../../../util/collection.ts";
import { ActiveThreads } from "./getActiveThreads.ts";
/**
* Gets the list of public archived threads for a channel.
*
* @param bot - The bot instance to use to make the request.
* @param channelId - The ID of the channel to get the archived threads for.
* @param options - The parameters for the fetching of threads.
* @returns An instance of {@link ArchivedThreads}.
*
* @remarks
* Requires the `READ_MESSAGE_HISTORY` permission.
*
* If called on a channel of type {@link ChannelTypes.GuildText}, returns threads of type {@link ChannelTypes.GuildPublicThread}.
* If called on a channel of type {@link ChannelTypes.GuildNews}, returns threads of type {@link ChannelTypes.GuildNewsThread}.
*
* Threads are ordered by the `archive_timestamp` property included in the metadata of the object in descending order.
*
* @see {@link https://discord.com/developers/docs/resources/channel#list-public-archived-threads}
*/
export async function getPublicArchivedThreads(
bot: Bot,
channelId: BigString,
options?: ListArchivedThreads,
): Promise<ArchivedThreads> {
const results = await bot.rest.runMethod<DiscordListArchivedThreads>(
bot.rest,
"GET",
bot.constants.routes.THREAD_ARCHIVED_PUBLIC(channelId, options),
);
return {
threads: new Collection(
results.threads.map((result) => {
const thread = bot.transformers.channel(bot, { channel: result });
return [thread.id, thread];
}),
),
members: new Collection(
results.members.map((result) => {
const member = bot.transformers.threadMember(bot, result);
return [member.id!, member];
}),
),
hasMore: results.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;
}
export type ArchivedThreads = ActiveThreads & {
hasMore: boolean;
};