diff --git a/src/helpers/emojis/create_emoji.ts b/src/helpers/emojis/create_emoji.ts index e16adbe5d..2687fe34c 100644 --- a/src/helpers/emojis/create_emoji.ts +++ b/src/helpers/emojis/create_emoji.ts @@ -1,20 +1,17 @@ -import { rest } from "../../rest/rest.ts"; -import { CreateGuildEmoji } from "../../types/emojis/create_guild_emoji.ts"; +import type { CreateGuildEmoji } from "../../types/emojis/create_guild_emoji.ts"; import type { Emoji } from "../../types/emojis/emoji.ts"; -import { snowflakeToBigint } from "../../util/bigint.ts"; -import { endpoints } from "../../util/constants.ts"; -import { requireBotGuildPermissions } from "../../util/permissions.ts"; -import { urlToBase64 } from "../../util/utils.ts"; +import type {Bot} from "../../bot.ts"; +import type {SnakeCasedPropertiesDeep} from "../../types/util.ts"; /** Create an emoji in the server. Emojis and animated emojis have a maximum file size of 256kb. Attempting to upload an emoji larger than this limit will fail and return 400 Bad Request and an error message, but not a JSON status code. If a URL is provided to the image parameter, Discordeno will automatically convert it to a base64 string internally. */ -export async function createEmoji(guildId: bigint, name: string, image: string, options: CreateGuildEmoji) { - await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]); +export async function createEmoji(bot: Bot, guildId: bigint, name: string, image: string, options: CreateGuildEmoji) { + await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_EMOJIS"]); if (image && !image.startsWith("data:image/")) { - image = await urlToBase64(image); + image = await bot.utils.urlToBase64(image); } - const emoji = await rest.runMethod("post", endpoints.GUILD_EMOJIS(guildId), { + const emoji = await bot.rest.runMethod>("post", bot.constants.endpoints.GUILD_EMOJIS(guildId), { ...options, name, image, @@ -22,6 +19,6 @@ export async function createEmoji(guildId: bigint, name: string, image: string, return { ...emoji, - id: snowflakeToBigint(emoji.id!), + id: bot.transformers.snowflake(emoji.id!), }; } diff --git a/src/helpers/emojis/delete_emoji.ts b/src/helpers/emojis/delete_emoji.ts index 402a095dd..9119ff5f0 100644 --- a/src/helpers/emojis/delete_emoji.ts +++ b/src/helpers/emojis/delete_emoji.ts @@ -1,10 +1,8 @@ -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 the given emoji. Requires the MANAGE_EMOJIS permission. Returns 204 No Content on success. */ -export async function deleteEmoji(guildId: bigint, id: bigint, reason?: string) { - await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]); +export async function deleteEmoji(bot: Bot, guildId: bigint, id: bigint, reason?: string) { + await bot.utils.requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]); - return await rest.runMethod("delete", endpoints.GUILD_EMOJI(guildId, id), { reason }); + return await bot.rest.runMethod(bot.rest,"delete", bot.constants.endpoints.GUILD_EMOJI(guildId, id), { reason }); } diff --git a/src/helpers/emojis/edit_emoji.ts b/src/helpers/emojis/edit_emoji.ts index c1917ebef..be3e9149d 100644 --- a/src/helpers/emojis/edit_emoji.ts +++ b/src/helpers/emojis/edit_emoji.ts @@ -1,12 +1,11 @@ -import { rest } from "../../rest/rest.ts"; import type { Emoji } from "../../types/emojis/emoji.ts"; import type { ModifyGuildEmoji } from "../../types/emojis/modify_guild_emoji.ts"; -import { endpoints } from "../../util/constants.ts"; -import { requireBotGuildPermissions } from "../../util/permissions.ts"; +import type {Bot} from "../../bot.ts"; +import type {SnakeCasedPropertiesDeep} from "../../types/util.ts"; /** Modify the given emoji. Requires the MANAGE_EMOJIS permission. */ -export async function editEmoji(guildId: bigint, id: bigint, options: ModifyGuildEmoji) { - await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]); +export async function editEmoji(bot: Bot, guildId: bigint, id: bigint, options: ModifyGuildEmoji) { + await bot.utils.requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]); - return await rest.runMethod("patch", endpoints.GUILD_EMOJI(guildId, id), options); + return await bot.rest.runMethod>("patch", bot.constants.endpoints.GUILD_EMOJI(guildId, id), options); } diff --git a/src/helpers/emojis/get_emoji.ts b/src/helpers/emojis/get_emoji.ts index 7bde027ef..631e808b8 100644 --- a/src/helpers/emojis/get_emoji.ts +++ b/src/helpers/emojis/get_emoji.ts @@ -1,22 +1,20 @@ -import { cacheHandlers } from "../../cache.ts"; -import { rest } from "../../rest/rest.ts"; import type { Emoji } from "../../types/emojis/emoji.ts"; import { Errors } from "../../types/discordeno/errors.ts"; -import { endpoints } from "../../util/constants.ts"; +import {Bot} from "../../bot.ts"; /** * Returns an emoji for the given guild and emoji Id. * * ⚠️ **If you need this, you are probably doing something wrong. Always use cache.guilds.get()?.emojis */ -export async function getEmoji(guildId: bigint, emojiId: bigint, addToCache = true) { - const result = await rest.runMethod("get", endpoints.GUILD_EMOJI(guildId, emojiId)); +export async function getEmoji(bot: Bot, guildId: bigint, emojiId: bigint, addToCache = true) { + const result = await bot.rest.runMethod("get", bot.constants.endpoints.GUILD_EMOJI(guildId, emojiId)); if (addToCache) { - const guild = await cacheHandlers.get("guilds", guildId); + const guild = await bot.cache.guilds.get(guildId); if (!guild) throw new Error(Errors.GUILD_NOT_FOUND); guild.emojis.set(emojiId, result); - await cacheHandlers.set("guilds", guildId, guild); + await bot.cache.guilds.set(guildId, guild); } return result; diff --git a/src/helpers/emojis/get_emojis.ts b/src/helpers/emojis/get_emojis.ts index babbeb3c7..30bf9ae49 100644 --- a/src/helpers/emojis/get_emojis.ts +++ b/src/helpers/emojis/get_emojis.ts @@ -1,30 +1,26 @@ -import { eventHandlers } from "../../bot.ts"; -import { cacheHandlers } from "../../cache.ts"; -import { rest } from "../../rest/rest.ts"; +import {Bot} from "../../bot.ts"; import type { Emoji } from "../../types/emojis/emoji.ts"; import { Errors } from "../../types/discordeno/errors.ts"; -import { snowflakeToBigint } from "../../util/bigint.ts"; import { Collection } from "../../util/collection.ts"; -import { endpoints } from "../../util/constants.ts"; /** * Returns a list of emojis for the given guild. * * ⚠️ **If you need this, you are probably doing something wrong. Always use cache.guilds.get()?.emojis */ -export async function getEmojis(guildId: bigint, addToCache = true) { - const result = await rest.runMethod("get", endpoints.GUILD_EMOJIS(guildId)); +export async function getEmojis(bot: Bot, guildId: bigint, addToCache = true) { + const result = await bot.rest.runMethod(bot.rest,"get", bot.constants.endpoints.GUILD_EMOJIS(guildId)); if (addToCache) { - const guild = await cacheHandlers.get("guilds", guildId); + const guild = await bot.cache.guilds.get("guilds", guildId); if (!guild) throw new Error(Errors.GUILD_NOT_FOUND); result.forEach((emoji) => { - eventHandlers.debug?.("loop", `Running forEach loop in get_emojis file.`); - guild.emojis.set(snowflakeToBigint(emoji.id!), emoji); + bot.events.debug("loop", `Running forEach loop in get_emojis file.`); + guild.emojis.set(bot.transformers.snowflake(emoji.id!), emoji); }); - await cacheHandlers.set("guilds", guildId, guild); + await bot.cache.guilds.set(guildId, guild); } return new Collection(result.map((e) => [e.id!, e]));