From 4a12b7714bb1df812b35e07dad812f2b6d2816a7 Mon Sep 17 00:00:00 2001 From: TriForMine Date: Thu, 21 Oct 2021 21:41:51 +0200 Subject: [PATCH] Threads helpers --- src/helpers/channels/threads/add_to_thread.ts | 18 ++++----- .../channels/threads/archive_thread.ts | 6 +-- src/helpers/channels/threads/delete_thread.ts | 15 +++----- src/helpers/channels/threads/edit_thread.ts | 37 ++++++++++--------- .../channels/threads/get_active_threads.ts | 21 +++++------ .../channels/threads/get_archived_threads.ts | 32 ++++++++-------- .../channels/threads/get_thread_members.ts | 26 +++++-------- src/helpers/channels/threads/join_thread.ts | 13 +++---- src/helpers/channels/threads/leave_thread.ts | 13 +++---- src/helpers/channels/threads/lock_thread.ts | 6 +-- .../channels/threads/remove_thread_member.ts | 21 ++++------- .../channels/threads/start_private_thread.ts | 28 +++++++------- src/helpers/channels/threads/start_thread.ts | 26 ++++++------- .../channels/threads/unarchive_thread.ts | 6 +-- src/helpers/channels/threads/unlock_thread.ts | 6 +-- 15 files changed, 124 insertions(+), 150 deletions(-) diff --git a/src/helpers/channels/threads/add_to_thread.ts b/src/helpers/channels/threads/add_to_thread.ts index 520ad7c1e..7a59e6f2f 100644 --- a/src/helpers/channels/threads/add_to_thread.ts +++ b/src/helpers/channels/threads/add_to_thread.ts @@ -1,22 +1,18 @@ -import { cacheHandlers } from "../../../cache.ts"; -import { rest } from "../../../rest/rest.ts"; -import { Errors } from "../../../types/discordeno/errors.ts"; -import { endpoints } from "../../../util/constants.ts"; -import { requireBotChannelPermissions } from "../../../util/permissions.ts"; +import type { Bot } from "../../../bot.ts"; /** Adds a user to a thread. Requires the ability to send messages in the thread. Requires the thread is not archived. */ -export async function addToThread(threadId: bigint, userId: bigint) { - const thread = await cacheHandlers.get("threads", threadId); +export async function addToThread(bot: Bot, threadId: bigint, userId: bigint) { + const thread = await bot.cache.threads.get(threadId); if (thread) { if (thread.archived) { - throw new Error(Errors.CANNOT_ADD_USER_TO_ARCHIVED_THREADS); + throw new Error(bot.constants.Errors.CANNOT_ADD_USER_TO_ARCHIVED_THREADS); } // If a user id is provided SEND_MESSAGES is required. - const channel = await cacheHandlers.get("channels", thread.parentId); + const channel = await bot.cache.channels.get(thread.parentId); // TODO: does MANAGE_THREADS override this???? - if (channel) await requireBotChannelPermissions(channel, ["SEND_MESSAGES"]); + if (channel) await bot.utils.requireBotChannelPermissions(bot, channel, ["SEND_MESSAGES"]); } - return await rest.runMethod("put", endpoints.THREAD_USER(threadId, userId)); + return await bot.rest.runMethod(bot.rest, "put", bot.constants.endpoints.THREAD_USER(threadId, userId)); } diff --git a/src/helpers/channels/threads/archive_thread.ts b/src/helpers/channels/threads/archive_thread.ts index cc3884546..42987c1a7 100644 --- a/src/helpers/channels/threads/archive_thread.ts +++ b/src/helpers/channels/threads/archive_thread.ts @@ -1,6 +1,6 @@ -import { editThread } from "./edit_thread.ts"; +import type { Bot } from "../../../bot.ts"; /** Sets a thread channel to be archived. */ -export async function archiveThread(threadId: bigint) { - return await editThread(threadId, { archived: true }); +export async function archiveThread(bot: Bot, threadId: bigint) { + return await bot.helpers.editThread(bot, threadId, { archived: true }); } diff --git a/src/helpers/channels/threads/delete_thread.ts b/src/helpers/channels/threads/delete_thread.ts index ea5d01ac3..c6df49288 100644 --- a/src/helpers/channels/threads/delete_thread.ts +++ b/src/helpers/channels/threads/delete_thread.ts @@ -1,15 +1,12 @@ -import { cacheHandlers } from "../../../cache.ts"; -import { rest } from "../../../rest/rest.ts"; -import { endpoints } from "../../../util/constants.ts"; -import { requireBotGuildPermissions } from "../../../util/permissions.ts"; +import type { Bot } from "../../../bot.ts"; /** Delete a thread in your server. Bot needs MANAGE_THREADS permissions in the server. */ -export async function deleteThread(threadId: bigint, reason?: string) { - const thread = await cacheHandlers.get("threads", threadId); +export async function deleteThread(bot: Bot, threadId: bigint, reason?: string) { + const thread = await bot.cache.threads.get(threadId); if (thread) { - const channel = await cacheHandlers.get("channels", thread?.parentId); - if (channel?.guildId) await requireBotGuildPermissions(channel.guildId, ["MANAGE_THREADS"]); + const channel = await bot.cache.channels.get(thread?.parentId); + if (channel?.guildId) await bot.utils.requireBotGuildPermissions(bot, channel.guildId, ["MANAGE_THREADS"]); } - return await rest.runMethod("delete", endpoints.CHANNEL_BASE(threadId), { reason }); + return await bot.rest.runMethod(bot.rest,"delete", bot.constants.endpoints.CHANNEL_BASE(threadId), { reason }); } diff --git a/src/helpers/channels/threads/edit_thread.ts b/src/helpers/channels/threads/edit_thread.ts index 75a9a93bc..51ebfe281 100644 --- a/src/helpers/channels/threads/edit_thread.ts +++ b/src/helpers/channels/threads/edit_thread.ts @@ -1,23 +1,26 @@ -import { rest } from "../../../rest/rest.ts"; -import { ModifyThread } from "../../../types/channels/threads/modify_thread.ts"; -import { endpoints } from "../../../util/constants.ts"; -import { channelToThread } from "../../../util/transformers/channel_to_thread.ts"; -import { snakelize } from "../../../util/utils.ts"; +import type { ModifyThread } from "../../../types/channels/threads/modify_thread.ts"; +import type { Bot } from "../../../bot.ts"; +import {channelToThread} from "../../../util/transformers/channel_to_thread.ts"; /** Update a thread's settings. Requires the `MANAGE_CHANNELS` permission for the guild. */ -export async function editThread(threadId: bigint, options: ModifyThread, reason?: string) { - // const thread = await cacheHandlers.get("threads", threadId); +export async function editThread(bot: Bot, threadId: bigint, options: ModifyThread, reason?: string) { + // const thread = await cacheHandlers.get("threads", threadId); - // TODO: permission checking + // TODO: permission checking - const result = await rest.runMethod( - "patch", - endpoints.CHANNEL_BASE(threadId), - snakelize({ - ...options, - reason, - }) - ); + const result = await bot.rest.runMethod( + 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 channelToThread(result); + return channelToThread(result); } diff --git a/src/helpers/channels/threads/get_active_threads.ts b/src/helpers/channels/threads/get_active_threads.ts index f1b7e9ef8..fef963417 100644 --- a/src/helpers/channels/threads/get_active_threads.ts +++ b/src/helpers/channels/threads/get_active_threads.ts @@ -1,17 +1,14 @@ -import { rest } from "../../../rest/rest.ts"; -import { ListActiveThreads } from "../../../types/channels/threads/list_active_threads.ts"; -import { snowflakeToBigint } from "../../../util/bigint.ts"; +import type { Bot } from "../../../bot.ts"; +import type { ListActiveThreads } from "../../../types/channels/threads/list_active_threads.ts"; import { Collection } from "../../../util/collection.ts"; -import { endpoints } from "../../../util/constants.ts"; -import { requireBotChannelPermissions } from "../../../util/permissions.ts"; -import { channelToThread } from "../../../util/transformers/channel_to_thread.ts"; +import {channelToThread} from "../../../util/transformers/channel_to_thread.ts"; /** Returns all active threads in the channel, including public and private threads. Threads are ordered by their id, in descending order. Requires the VIEW_CHANNEL permission. */ -export async function getActiveThreads(channelId: bigint) { - await requireBotChannelPermissions(channelId, ["VIEW_CHANNEL"]); +export async function getActiveThreads(bot: Bot, channelId: bigint) { + await bot.utils.requireBotChannelPermissions(bot, channelId, ["VIEW_CHANNEL"]); // TODO: pagination - const result = (await rest.runMethod("get", endpoints.THREAD_ACTIVE(channelId))) as ListActiveThreads; + const result = (await bot.rest.runMethod(bot.rest,"get", bot.constants.endpoints.THREAD_ACTIVE(channelId))) as ListActiveThreads; const threads = new Collection( result.threads.map((t) => { @@ -21,9 +18,9 @@ export async function getActiveThreads(channelId: bigint) { ); for (const member of result.members) { - const thread = threads.get(snowflakeToBigint(member.id!)); - thread?.members.set(snowflakeToBigint(member.userId!), { - userId: snowflakeToBigint(member.userId!), + const thread = threads.get(bot.transformers.snowflake(member.id!)); + thread?.members.set(bot.transformers.snowflake(member.userId!), { + userId: bot.transformers.snowflake(member.userId!), flags: member.flags, joinTimestamp: Date.parse(member.joinTimestamp), }); diff --git a/src/helpers/channels/threads/get_archived_threads.ts b/src/helpers/channels/threads/get_archived_threads.ts index 7abd65291..baf42e4a9 100644 --- a/src/helpers/channels/threads/get_archived_threads.ts +++ b/src/helpers/channels/threads/get_archived_threads.ts @@ -1,16 +1,13 @@ -import { rest } from "../../../rest/rest.ts"; import { ListActiveThreads } from "../../../types/channels/threads/list_active_threads.ts"; import { ListPublicArchivedThreads } from "../../../types/channels/threads/list_public_archived_threads.ts"; import { PermissionStrings } from "../../../types/permissions/permission_strings.ts"; -import { snowflakeToBigint } from "../../../util/bigint.ts"; import { Collection } from "../../../util/collection.ts"; -import { endpoints } from "../../../util/constants.ts"; -import { requireBotChannelPermissions } from "../../../util/permissions.ts"; -import { channelToThread } from "../../../util/transformers/channel_to_thread.ts"; -import { snakelize } from "../../../util/utils.ts"; +import type { Bot } from "../../../bot.ts"; +import {channelToThread} from "../../../util/transformers/channel_to_thread.ts"; /** Get the archived threads for this channel, defaults to public */ export async function getArchivedThreads( + bot: Bot, channelId: bigint, options?: ListPublicArchivedThreads & { type?: "public" | "private" | "privateJoinedThreads"; @@ -19,18 +16,23 @@ export async function getArchivedThreads( const permissions = new Set(["READ_MESSAGE_HISTORY"]); if (options?.type === "private") permissions.add("MANAGE_THREADS"); - await requireBotChannelPermissions(channelId, [...permissions]); + await bot.utils.requireBotChannelPermissions(bot, channelId, [...permissions]); // TODO: pagination - const result = (await rest.runMethod( + const result = (await bot.rest.runMethod( + bot.rest, "get", options?.type === "privateJoinedThreads" - ? endpoints.THREAD_ARCHIVED_PRIVATE_JOINED(channelId) + ? bot.constants.endpoints.THREAD_ARCHIVED_PRIVATE_JOINED(channelId) : options?.type === "private" - ? endpoints.THREAD_ARCHIVED_PRIVATE(channelId) - : endpoints.THREAD_ARCHIVED_PUBLIC(channelId), - snakelize(options ?? {}) + ? bot.constants.endpoints.THREAD_ARCHIVED_PRIVATE(channelId) + : bot.constants.endpoints.THREAD_ARCHIVED_PUBLIC(channelId), + options ? { + before: options.before, + limit: options.limit, + type: options.type + } : {} )) as ListActiveThreads; const threads = new Collection( @@ -41,9 +43,9 @@ export async function getArchivedThreads( ); for (const member of result.members) { - const thread = threads.get(snowflakeToBigint(member.id!)); - thread?.members.set(snowflakeToBigint(member.userId!), { - userId: snowflakeToBigint(member.userId!), + const thread = threads.get(bot.transformers.snowflake(member.id!)); + thread?.members.set(bot.transformers.snowflake(member.userId!), { + userId: bot.transformers.snowflake(member.userId!), flags: member.flags, joinTimestamp: Date.parse(member.joinTimestamp), }); diff --git a/src/helpers/channels/threads/get_thread_members.ts b/src/helpers/channels/threads/get_thread_members.ts index 202e9c81a..ed84f81d7 100644 --- a/src/helpers/channels/threads/get_thread_members.ts +++ b/src/helpers/channels/threads/get_thread_members.ts @@ -1,29 +1,23 @@ -import { cacheHandlers } from "../../../cache.ts"; -import { rest } from "../../../rest/rest.ts"; +import type { Bot } from "../../../bot.ts"; import { ThreadMember } from "../../../types/channels/threads/thread_member.ts"; -import { Errors } from "../../../types/discordeno/errors.ts"; import { DiscordGatewayIntents } from "../../../types/gateway/gateway_intents.ts"; import { Collection } from "../../../util/collection.ts"; -import { endpoints } from "../../../util/constants.ts"; -import { botHasChannelPermissions } from "../../../util/permissions.ts"; -import { threadMemberModified } from "../../../util/transformers/thread_member_modified.ts"; -import { ws } from "../../../ws/ws.ts"; - +import {threadMemberModified} from "../../../util/transformers/thread_member_modified.ts"; /** Returns thread members objects that are members of the thread. */ -export async function getThreadMembers(threadId: bigint) { +export async function getThreadMembers(bot: Bot, threadId: bigint) { // Check if intents is not 0 as proxy ws won't set intents in other instances - if (ws.identifyPayload.intents && !(ws.identifyPayload.intents & DiscordGatewayIntents.GuildMembers)) { - throw new Error(Errors.MISSING_INTENT_GUILD_MEMBERS); + if (bot.gateway.identifyPayload.intents && !(bot.gateway.identifyPayload.intents & DiscordGatewayIntents.GuildMembers)) { + throw new Error(bot.constants.Errors.MISSING_INTENT_GUILD_MEMBERS); } - const thread = await cacheHandlers.get("threads", threadId); + const thread = await bot.cache.threads.get(threadId); if (thread?.isPrivate) { - const channel = await cacheHandlers.get("channels", thread.parentId); - if (channel && !(await botHasChannelPermissions(channel, ["MANAGE_THREADS"])) && !thread.botIsMember) - throw new Error(Errors.CANNOT_GET_MEMBERS_OF_AN_UNJOINED_PRIVATE_THREAD); + const channel = await bot.cache.channels.get(thread.parentId); + if (channel && !(await bot.utils.botHasChannelPermissions(bot, channel, ["MANAGE_THREADS"])) && !thread.botIsMember) + throw new Error(bot.constants.Errors.CANNOT_GET_MEMBERS_OF_AN_UNJOINED_PRIVATE_THREAD); } - const result = await rest.runMethod("get", endpoints.THREAD_MEMBERS(threadId)); + const result = await bot.rest.runMethod(bot.rest,"get", bot.constants.endpoints.THREAD_MEMBERS(threadId)); const members = result.map((member) => threadMemberModified(member)); diff --git a/src/helpers/channels/threads/join_thread.ts b/src/helpers/channels/threads/join_thread.ts index 815975de5..091feff0b 100644 --- a/src/helpers/channels/threads/join_thread.ts +++ b/src/helpers/channels/threads/join_thread.ts @@ -1,14 +1,11 @@ -import { cacheHandlers } from "../../../cache.ts"; -import { rest } from "../../../rest/rest.ts"; -import { Errors } from "../../../types/discordeno/errors.ts"; -import { endpoints } from "../../../util/constants.ts"; +import type { Bot } from "../../../bot.ts"; /** Adds the bot to the thread. Cannot join an archived thread. */ -export async function joinThread(threadId: bigint) { - const thread = await cacheHandlers.get("threads", threadId); +export async function joinThread(bot: Bot, threadId: bigint) { + const thread = await bot.cache.threads.get(threadId); if (thread?.archived) { - throw new Error(Errors.CANNOT_ADD_USER_TO_ARCHIVED_THREADS); + throw new Error(bot.contants.Errors.CANNOT_ADD_USER_TO_ARCHIVED_THREADS); } - return await rest.runMethod("put", endpoints.THREAD_ME(threadId)); + return await bot.rest.runMethod(bot.rest,"put", bot.constants.endpoints.THREAD_ME(threadId)); } diff --git a/src/helpers/channels/threads/leave_thread.ts b/src/helpers/channels/threads/leave_thread.ts index 867727397..a4e4961c1 100644 --- a/src/helpers/channels/threads/leave_thread.ts +++ b/src/helpers/channels/threads/leave_thread.ts @@ -1,12 +1,9 @@ -import { cacheHandlers } from "../../../cache.ts"; -import { rest } from "../../../rest/rest.ts"; -import { Errors } from "../../../types/discordeno/errors.ts"; -import { endpoints } from "../../../util/constants.ts"; +import type { Bot } from "../../../bot.ts"; /** Removes the bot from a thread. Requires the thread is not archived. */ -export async function leaveThread(threadId: bigint) { - const thread = await cacheHandlers.get("threads", threadId); - if (thread?.archived) throw new Error(Errors.CANNOT_LEAVE_ARCHIVED_THREAD); +export async function leaveThread(bot: Bot, threadId: bigint) { + const thread = await bot.cache.threads.get(threadId); + if (thread?.archived) throw new Error(bot.constants.Errors.CANNOT_LEAVE_ARCHIVED_THREAD); - return await rest.runMethod("delete", endpoints.THREAD_ME(threadId)); + return await bot.rest.runMethod(bot.rest,"delete", bot.constants.endpoints.THREAD_ME(threadId)); } diff --git a/src/helpers/channels/threads/lock_thread.ts b/src/helpers/channels/threads/lock_thread.ts index 5a5ca9fae..681335733 100644 --- a/src/helpers/channels/threads/lock_thread.ts +++ b/src/helpers/channels/threads/lock_thread.ts @@ -1,6 +1,6 @@ -import { editThread } from "./edit_thread.ts"; +import type { Bot } from "../../../bot.ts"; /** Sets a thread channel to be locked. */ -export async function lockThread(threadId: bigint) { - return await editThread(threadId, { locked: true }); +export async function lockThread(bot: Bot, threadId: bigint) { + return await bot.utils.editThread(bot, threadId, { locked: true }); } diff --git a/src/helpers/channels/threads/remove_thread_member.ts b/src/helpers/channels/threads/remove_thread_member.ts index 8c338c95e..5b4b633be 100644 --- a/src/helpers/channels/threads/remove_thread_member.ts +++ b/src/helpers/channels/threads/remove_thread_member.ts @@ -1,21 +1,16 @@ -import { botId } from "../../../bot.ts"; -import { cacheHandlers } from "../../../cache.ts"; -import { rest } from "../../../rest/rest.ts"; -import { Errors } from "../../../types/discordeno/errors.ts"; -import { endpoints } from "../../../util/constants.ts"; -import { requireBotChannelPermissions } from "../../../util/permissions.ts"; +import type { Bot } from "../../../bot.ts"; /** Removes a user from a thread. Requires the MANAGE_THREADS permission or that you are the creator of the thread. Also requires the thread is not archived. */ -export async function removeThreadMember(threadId: bigint, userId: bigint) { - const thread = await cacheHandlers.get("threads", threadId); +export async function removeThreadMember(bot: Bot, threadId: bigint, userId: bigint) { + const thread = await bot.cache.threads.get(threadId); if (thread) { - if (thread.archived) throw new Error(Errors.CANNOT_REMOVE_FROM_ARCHIVED_THREAD); + if (thread.archived) throw new Error(bot.constants.Errors.CANNOT_REMOVE_FROM_ARCHIVED_THREAD); - if (thread.ownerId !== botId) { - const channel = await cacheHandlers.get("channels", thread.parentId); - if (channel) await requireBotChannelPermissions(channel, ["MANAGE_THREADS"]); + if (thread.ownerId !== bot.id) { + const channel = await bot.cache.channels.get(thread.parentId); + if (channel) await bot.utils.requireBotChannelPermissions(bot, channel, ["MANAGE_THREADS"]); } } - return await rest.runMethod("delete", endpoints.THREAD_USER(threadId, userId)); + return await bot.rest.runMethod(bot.rest,"delete", bot.constants.endpoints.THREAD_USER(threadId, userId)); } diff --git a/src/helpers/channels/threads/start_private_thread.ts b/src/helpers/channels/threads/start_private_thread.ts index d4653df80..f62b416fe 100644 --- a/src/helpers/channels/threads/start_private_thread.ts +++ b/src/helpers/channels/threads/start_private_thread.ts @@ -1,25 +1,23 @@ -import { cacheHandlers } from "../../../cache.ts"; -import { rest } from "../../../rest/rest.ts"; -import { Channel } from "../../../types/channels/channel.ts"; -import { StartThread } from "../../../types/channels/threads/start_thread.ts"; -import { Errors } from "../../../types/discordeno/errors.ts"; -import { endpoints } from "../../../util/constants.ts"; -import { requireBotChannelPermissions } from "../../../util/permissions.ts"; -import { channelToThread } from "../../../util/transformers/channel_to_thread.ts"; -import { snakelize } from "../../../util/utils.ts"; +import type { Channel } from "../../../types/channels/channel.ts"; +import type { StartThread } from "../../../types/channels/threads/start_thread.ts"; +import type { Bot } from "../../../bot.ts"; +import {channelToThread} from "../../../util/transformers/channel_to_thread.ts"; /** Creates a new private thread. Returns a thread channel. */ -export async function startPrivateThread(channelId: bigint, options: StartThread) { - const channel = await cacheHandlers.get("channels", channelId); +export async function startPrivateThread(bot: Bot, channelId: bigint, options: StartThread) { + const channel = await bot.cache.channels.get(channelId); if (channel) { - if (!channel.isGuildTextBasedChannel) throw new Error(Errors.INVALID_THREAD_PARENT_CHANNEL_TYPE); + if (!channel.isGuildTextBasedChannel) throw new Error(bot.constants.Errors.INVALID_THREAD_PARENT_CHANNEL_TYPE); - if (channel.isNewsChannel) throw new Error(Errors.GUILD_NEWS_CHANNEL_ONLY_SUPPORT_PUBLIC_THREADS); + if (channel.isNewsChannel) throw new Error(bot.constants.Errors.GUILD_NEWS_CHANNEL_ONLY_SUPPORT_PUBLIC_THREADS); - await requireBotChannelPermissions(channel, ["SEND_MESSAGES", "USE_PRIVATE_THREADS"]); + await bot.utils.requireBotChannelPermissions(bot, channel, ["SEND_MESSAGES", "USE_PRIVATE_THREADS"]); } return channelToThread( - await rest.runMethod("post", endpoints.THREAD_START_PRIVATE(channelId), snakelize(options)) + await bot.rest.runMethod(bot.rest,"post", bot.constants.endpoints.THREAD_START_PRIVATE(channelId), { + name: options.name, + auto_archive_duration: options.autoArchiveDuration + }) ); } diff --git a/src/helpers/channels/threads/start_thread.ts b/src/helpers/channels/threads/start_thread.ts index 557e7d2f0..e53d25a62 100644 --- a/src/helpers/channels/threads/start_thread.ts +++ b/src/helpers/channels/threads/start_thread.ts @@ -1,25 +1,23 @@ -import { cacheHandlers } from "../../../cache.ts"; -import { rest } from "../../../rest/rest.ts"; -import { Channel } from "../../../types/channels/channel.ts"; -import { StartThread } from "../../../types/channels/threads/start_thread.ts"; -import { Errors } from "../../../types/discordeno/errors.ts"; -import { endpoints } from "../../../util/constants.ts"; -import { requireBotChannelPermissions } from "../../../util/permissions.ts"; -import { channelToThread } from "../../../util/transformers/channel_to_thread.ts"; -import { snakelize } from "../../../util/utils.ts"; +import type { Channel } from "../../../types/channels/channel.ts"; +import type { StartThread } from "../../../types/channels/threads/start_thread.ts"; +import type { Bot } from "../../../bot.ts"; +import {channelToThread} from "../../../util/transformers/channel_to_thread.ts"; /** Creates a new public thread from an existing message. Returns a thread channel. */ -export async function startThread(channelId: bigint, messageId: bigint, options: StartThread) { - const channel = await cacheHandlers.get("channels", channelId); +export async function startThread(bot: Bot, channelId: bigint, messageId: bigint, options: StartThread) { + const channel = await bot.cache.channels.get(channelId); if (channel) { if (!channel.isGuildTextBasedChannel) { - throw new Error(Errors.INVALID_THREAD_PARENT_CHANNEL_TYPE); + throw new Error(bot.constants.Errors.INVALID_THREAD_PARENT_CHANNEL_TYPE); } - await requireBotChannelPermissions(channel, ["SEND_MESSAGES", "USE_PUBLIC_THREADS"]); + await bot.utils.requireBotChannelPermissions(bot, channel, ["SEND_MESSAGES", "USE_PUBLIC_THREADS"]); } return channelToThread( - await rest.runMethod("post", endpoints.THREAD_START_PUBLIC(channelId, messageId), snakelize(options)) + await bot.rest.runMethod(bot.rest,"post", bot.constants.endpoints.THREAD_START_PUBLIC(channelId, messageId), { + name: options.name, + auto_archive_duration: options.autoArchiveDuration + }) ); } diff --git a/src/helpers/channels/threads/unarchive_thread.ts b/src/helpers/channels/threads/unarchive_thread.ts index d80a56885..4bc5c14ee 100644 --- a/src/helpers/channels/threads/unarchive_thread.ts +++ b/src/helpers/channels/threads/unarchive_thread.ts @@ -1,6 +1,6 @@ -import { editThread } from "./edit_thread.ts"; +import type { Bot } from "../../../bot.ts"; /** Sets a thread channel to be unarchived. */ -export async function unarchiveThread(threadId: bigint) { - return await editThread(threadId, { archived: false }); +export async function unarchiveThread(bot: Bot, threadId: bigint) { + return await bot.helpers.editThread(bot, threadId, { archived: false }); } diff --git a/src/helpers/channels/threads/unlock_thread.ts b/src/helpers/channels/threads/unlock_thread.ts index 277713aec..5e3b08396 100644 --- a/src/helpers/channels/threads/unlock_thread.ts +++ b/src/helpers/channels/threads/unlock_thread.ts @@ -1,6 +1,6 @@ -import { editThread } from "./edit_thread.ts"; +import type { Bot } from "../../../bot.ts"; /** Sets a thread channel to be unlocked. */ -export async function unlockThread(threadId: bigint) { - return await editThread(threadId, { locked: false }); +export async function unlockThread(bot: Bot, threadId: bigint) { + return await bot.helpers.editThread(bot, threadId, { locked: false }); }