Files
discordeno/plugins/helpers/src/threads.ts
ITOH 81f8e0377c style: move to deno fmt (#1992)
* Create deno.json

* run format

* run format

* ci: only check formatting

* f

* Update settings.json

* Update settings.json
2022-02-04 15:00:04 +01:00

39 lines
1.4 KiB
TypeScript

import { Bot, Channel, ModifyThread } from "../deps.ts";
/** Sets a thread channel to be archived. */
export async function archiveThread(bot: Bot, threadId: bigint) {
return await editThread(bot, threadId, { archived: true });
}
/** Sets a thread channel to be unarchived. */
export async function unarchiveThread(bot: Bot, threadId: bigint) {
return await editThread(bot, threadId, { archived: false });
}
/** Sets a thread channel to be locked. */
export async function lockThread(bot: Bot, threadId: bigint) {
return await editThread(bot, threadId, { locked: true });
}
/** Sets a thread channel to be unlocked. */
export async function unlockThread(bot: Bot, threadId: bigint) {
return await editThread(bot, threadId, { locked: false });
}
/** Update a thread's settings. Requires the `MANAGE_CHANNELS` permission for the guild. */
export async function editThread(bot: Bot, threadId: bigint, options: ModifyThread, reason?: string) {
const result = await bot.rest.runMethod<Channel>(bot.rest, "patch", bot.constants.endpoints.CHANNEL_BASE(threadId), {
name: options.name,
archived: options.archived,
auto_archive_duration: options.autoArchiveDuration,
locked: options.locked,
rate_limit_per_user: options.rateLimitPerUser,
reason,
});
return bot.transformers.channel(bot, {
channel: result,
guildId: result.guild_id ? bot.transformers.snowflake(result.guild_id) : undefined,
});
}