diff --git a/src/bot.ts b/src/bot.ts index 8a3127222..2a4f1adca 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -74,7 +74,7 @@ import { DiscordenoShard, } from "./ws/mod.ts"; import { validateLength } from "./util/validate_length.ts"; -import { delay, validateSlashOptionChoices, validateSlashOptions } from "./util/utils.ts"; +import {delay, validateComponents, validateSlashOptionChoices, validateSlashOptions} from "./util/utils.ts"; import { iconBigintToHash, iconHashToBigInt } from "./util/hash.ts"; import { calculateShardId } from "./util/calculate_shard_id.ts"; @@ -284,6 +284,7 @@ export function createUtils(options: Partial) { validateSlashOptions, validateSlashOptionChoices, requireBotChannelPermissions, + validateComponents }; } @@ -310,6 +311,7 @@ export interface HelperUtils { validateSlashOptions: typeof validateSlashOptions; validateSlashOptionChoices: typeof validateSlashOptionChoices; requireBotChannelPermissions: typeof requireBotChannelPermissions; + validateComponents: typeof validateComponents; } export function createGatewayManager(options: Partial): GatewayManager { diff --git a/src/helpers/messages/add_reaction.ts b/src/helpers/messages/add_reaction.ts index 0c0400f47..c832b53c3 100644 --- a/src/helpers/messages/add_reaction.ts +++ b/src/helpers/messages/add_reaction.ts @@ -1,4 +1,4 @@ -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; /** Create a reaction for the message. Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. Requires READ_MESSAGE_HISTORY and ADD_REACTIONS */ export async function addReaction(bot: Bot, channelId: bigint, messageId: bigint, reaction: string) { diff --git a/src/helpers/messages/add_reactions.ts b/src/helpers/messages/add_reactions.ts index 06ed6f3f4..9a013414e 100644 --- a/src/helpers/messages/add_reactions.ts +++ b/src/helpers/messages/add_reactions.ts @@ -1,4 +1,4 @@ -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; import { addReaction } from "./add_reaction.ts"; /** Adds multiple reactions to a message. If `ordered` is true(default is false), it will add the reactions one at a time in the order provided. Note: Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. Requires READ_MESSAGE_HISTORY and ADD_REACTIONS */ diff --git a/src/helpers/messages/delete_message.ts b/src/helpers/messages/delete_message.ts index 71ecf3ce5..ad12e2992 100644 --- a/src/helpers/messages/delete_message.ts +++ b/src/helpers/messages/delete_message.ts @@ -1,6 +1,4 @@ -import { Bot } from "../../bot.ts"; -import { cacheHandlers } from "../../cache.ts"; -import { delay } from "../../util/utils.ts"; +import type { Bot } from "../../bot.ts"; /** Delete a message with the channel id and message id only. */ export async function deleteMessage( @@ -16,7 +14,7 @@ export async function deleteMessage( await bot.utils.requireBotChannelPermissions(bot, message.channelId, ["MANAGE_MESSAGES"]); } - if (delayMilliseconds) await delay(delayMilliseconds); + if (delayMilliseconds) await bot.utils.delay(delayMilliseconds); return await bot.rest.runMethod( bot.rest, diff --git a/src/helpers/messages/delete_messages.ts b/src/helpers/messages/delete_messages.ts index 8421957cf..57159b481 100644 --- a/src/helpers/messages/delete_messages.ts +++ b/src/helpers/messages/delete_messages.ts @@ -1,4 +1,4 @@ -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; /** Delete messages from the channel. 2-100. Requires the MANAGE_MESSAGES permission */ export async function deleteMessages(bot: Bot, channelId: bigint, ids: bigint[], reason?: string) { diff --git a/src/helpers/messages/edit_message.ts b/src/helpers/messages/edit_message.ts index 9286c41bf..c8e227cf3 100644 --- a/src/helpers/messages/edit_message.ts +++ b/src/helpers/messages/edit_message.ts @@ -1,10 +1,9 @@ import { cacheHandlers } from "../../cache.ts"; -import { EditMessage } from "../../types/messages/edit_message.ts"; +import type { EditMessage } from "../../types/messages/edit_message.ts"; import type { Message } from "../../types/messages/message.ts"; import type { PermissionStrings } from "../../types/permissions/permission_strings.ts"; -import { validateComponents } from "../../util/utils.ts"; -import { Bot } from "../../bot.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import type { Bot } from "../../bot.ts"; +import type { SnakeCasedPropertiesDeep } from "../../types/util.ts"; /** Edit the message. */ export async function editMessage(bot: Bot, channelId: bigint, messageId: bigint, content: string | EditMessage) { @@ -22,7 +21,7 @@ export async function editMessage(bot: Bot, channelId: bigint, messageId: bigint if (typeof content === "string") content = { content }; if (content.components?.length) { - validateComponents(bot, content.components); + bot.utils.validateComponents(bot, content.components); } content.embeds?.splice(10); diff --git a/src/helpers/messages/get_message.ts b/src/helpers/messages/get_message.ts index 417d568d3..b48833799 100644 --- a/src/helpers/messages/get_message.ts +++ b/src/helpers/messages/get_message.ts @@ -1,7 +1,7 @@ import { cacheHandlers } from "../../cache.ts"; import type { Message } from "../../types/messages/message.ts"; -import { Bot } from "../../bot.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import type { Bot } from "../../bot.ts"; +import type { SnakeCasedPropertiesDeep } from "../../types/util.ts"; /** Fetch a single message from the server. Requires VIEW_CHANNEL and READ_MESSAGE_HISTORY */ export async function getMessage(bot: Bot, channelId: bigint, id: bigint) { diff --git a/src/helpers/messages/get_messages.ts b/src/helpers/messages/get_messages.ts index 38e9c2ea8..b052dafce 100644 --- a/src/helpers/messages/get_messages.ts +++ b/src/helpers/messages/get_messages.ts @@ -1,28 +1,26 @@ -import { rest } from "../../rest/rest.ts"; -import { structures } from "../../structures/mod.ts"; -import { Errors } from "../../types/discordeno/errors.ts"; -import { +import type { GetMessagesAfter, GetMessagesAround, GetMessagesBefore, GetMessagesLimit, } from "../../types/messages/get_messages.ts"; import type { Message } from "../../types/messages/message.ts"; -import { endpoints } from "../../util/constants.ts"; -import { requireBotChannelPermissions } from "../../util/permissions.ts"; +import type { Bot } from "../../bot.ts"; +import type {SnakeCasedPropertiesDeep} from "../../types/util.ts"; /** Fetches between 2-100 messages. Requires VIEW_CHANNEL and READ_MESSAGE_HISTORY */ export async function getMessages( + bot: Bot, channelId: bigint, options?: GetMessagesAfter | GetMessagesBefore | GetMessagesAround | GetMessagesLimit ) { - await requireBotChannelPermissions(channelId, ["VIEW_CHANNEL", "READ_MESSAGE_HISTORY"]); + await bot.utils.requireBotChannelPermissions(bot, channelId, ["VIEW_CHANNEL", "READ_MESSAGE_HISTORY"]); if (options?.limit && (options.limit < 0 || options.limit > 100)) { - throw new Error(Errors.INVALID_GET_MESSAGES_LIMIT); + throw new Error(bot.constants.Errors.INVALID_GET_MESSAGES_LIMIT); } - const result = await rest.runMethod("get", endpoints.CHANNEL_MESSAGES(channelId), options); + const result = await bot.rest.runMethod[]>(bot.rest, "get", bot.constants.endpoints.CHANNEL_MESSAGES(channelId), options); - return await Promise.all(result.map((res) => structures.createDiscordenoMessage(res))); + return await Promise.all(result.map((res) => bot.transformers.message(bot, res))); }