diff --git a/src/helpers/guilds/create_guild.ts b/src/helpers/guilds/create_guild.ts index 38bd03165..819bbc355 100644 --- a/src/helpers/guilds/create_guild.ts +++ b/src/helpers/guilds/create_guild.ts @@ -1,22 +1,28 @@ -import { botId } from "../../bot.ts"; -import { cacheHandlers } from "../../cache.ts"; -import { rest } from "../../rest/rest.ts"; -import { structures } from "../../structures/mod.ts"; import type { CreateGuild } from "../../types/guilds/create_guild.ts"; import type { Guild } from "../../types/guilds/guild.ts"; -import { endpoints } from "../../util/constants.ts"; -import { snakelize } from "../../util/utils.ts"; -import { getMember } from "../members/get_member.ts"; +import type { Bot } from "../../bot.ts"; /** Create a new guild. Returns a guild object on success. Fires a Guild Create Gateway event. This endpoint can be used only by bots in less than 10 guilds. */ -export async function createGuild(options: CreateGuild) { - const result = await rest.runMethod("post", endpoints.GUILDS, snakelize(options)); +export async function createGuild(bot: Bot, options: CreateGuild) { + const result = await bot.rest.runMethod(bot.rest,"post", bot.constants.endpoints.GUILDS, { + name: options.name, + afk_channel_id: options.afkChannelId, + afk_timeout: options.afkTimeout, + channels: options.channels, + default_message_notifications: options.defaultMessageNotifications, + explicit_content_filter: options.explicitContentFilter, + icon: options.icon, + roles: options.roles, + system_channel_flags: options.systemChannelFlags, + system_channel_id: options.systemChannelId, + verification_level: options.verificationLevel + }); - const guild = await structures.createDiscordenoGuild(result, 0); + const guild = bot.transformers.guild(bot, {guild: result, shardId: 0}); // MANUALLY CACHE THE GUILD - await cacheHandlers.set("guilds", guild.id, guild); + await bot.cache.guilds.set(guild.id, guild); // MANUALLY CACHE THE BOT - await getMember(guild.id, botId); + await bot.helpers.getMember(bot, guild.id, bot.id); return guild; } diff --git a/src/helpers/guilds/delete_guild.ts b/src/helpers/guilds/delete_guild.ts index 8e98de769..3962364f0 100644 --- a/src/helpers/guilds/delete_guild.ts +++ b/src/helpers/guilds/delete_guild.ts @@ -1,7 +1,6 @@ -import { rest } from "../../rest/rest.ts"; -import { endpoints } from "../../util/constants.ts"; +import type { Bot } from "../../bot.ts"; /** Delete a guild permanently. User must be owner. Returns 204 No Content on success. Fires a Guild Delete Gateway event. */ -export async function deleteGuild(guildId: bigint) { - return await rest.runMethod("delete", endpoints.GUILDS_BASE(guildId)); +export async function deleteGuild(bot: Bot, guildId: bigint) { + return await bot.rest.runMethod(bot.rest,"delete", bot.constants.endpoints.GUILDS_BASE(guildId)); } diff --git a/src/helpers/guilds/edit_guild.ts b/src/helpers/guilds/edit_guild.ts index 760e387ce..e5421d38a 100644 --- a/src/helpers/guilds/edit_guild.ts +++ b/src/helpers/guilds/edit_guild.ts @@ -1,34 +1,33 @@ -import { cacheHandlers } from "../../cache.ts"; -import { rest } from "../../rest/rest.ts"; -import { structures } from "../../structures/mod.ts"; +import type { Bot } from "../../bot.ts"; import type { Guild } from "../../types/guilds/guild.ts"; import type { ModifyGuild } from "../../types/guilds/modify_guild.ts"; -import { endpoints } from "../../util/constants.ts"; -import { requireBotGuildPermissions } from "../../util/permissions.ts"; -import { snakelize, urlToBase64 } from "../../util/utils.ts"; -import { ws } from "../../ws/ws.ts"; /** Modify a guilds settings. Requires the MANAGE_GUILD permission. */ -export async function editGuild(guildId: bigint, options: ModifyGuild) { - await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); +export async function editGuild(bot: Bot, guildId: bigint, options: ModifyGuild) { + await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]); if (options.icon && !options.icon.startsWith("data:image/")) { - options.icon = await urlToBase64(options.icon); + options.icon = await bot.utils.urlToBase64(options.icon); } if (options.banner && !options.banner.startsWith("data:image/")) { - options.banner = await urlToBase64(options.banner); + options.banner = await bot.utils.urlToBase64(options.banner); } if (options.splash && !options.splash.startsWith("data:image/")) { - options.splash = await urlToBase64(options.splash); + options.splash = await bot.utils.urlToBase64(options.splash); } - const result = await rest.runMethod("patch", endpoints.GUILDS_BASE(guildId), snakelize(options)); + const result = await bot.rest.runMethod(bot.rest,"patch", bot.constants.endpoints.GUILDS_BASE(guildId), { - const cached = await cacheHandlers.get("guilds", guildId); - return structures.createDiscordenoGuild( - result, - cached?.shardId || Number((BigInt(result.id) >> 22n % BigInt(ws.botGatewayData.shards)).toString()) + }); + + const cached = await bot.cache.guilds.get(guildId); + return bot.transformers.guild( + bot, + { + guild: result, + shardId: cached?.shardId || Number((BigInt(result.id) >> 22n % BigInt(bot.gateway.botGatewayData.shards)).toString()) + } ); } diff --git a/src/helpers/guilds/edit_welcome_screen.ts b/src/helpers/guilds/edit_welcome_screen.ts index 8ab1e4759..6e4a11647 100644 --- a/src/helpers/guilds/edit_welcome_screen.ts +++ b/src/helpers/guilds/edit_welcome_screen.ts @@ -1,9 +1,18 @@ -import { rest } from "../../rest/rest.ts"; import type { ModifyGuildWelcomeScreen } from "../../types/guilds/modify_guild_welcome_screen.ts"; import type { WelcomeScreen } from "../../types/guilds/welcome_screen.ts"; -import { endpoints } from "../../util/constants.ts"; -import { snakelize } from "../../util/utils.ts"; +import type { Bot } from "../../bot.ts"; -export async function editWelcomeScreen(guildId: bigint, options: ModifyGuildWelcomeScreen) { - return await rest.runMethod("patch", endpoints.GUILD_WELCOME_SCREEN(guildId), snakelize(options)); +export async function editWelcomeScreen(bot: Bot, guildId: bigint, options: ModifyGuildWelcomeScreen) { + return await bot.rest.runMethod("patch", bot.constants.endpoints.GUILD_WELCOME_SCREEN(guildId), { + enabled: options.enabled, + welcomeScreen: options.welcomeScreen?.map((welcomeScreen) => { + return { + channel_id: welcomeScreen.channelId, + description: welcomeScreen.description, + emoji_id: welcomeScreen.emojiId, + emoji_name: welcomeScreen.emojiName + } + }), + description: options.description + }); } diff --git a/src/helpers/guilds/edit_widget.ts b/src/helpers/guilds/edit_widget.ts index 66cd803e4..410b89331 100644 --- a/src/helpers/guilds/edit_widget.ts +++ b/src/helpers/guilds/edit_widget.ts @@ -1,13 +1,11 @@ -import { rest } from "../../rest/rest.ts"; import type { GuildWidget } from "../../types/guilds/guild_widget.ts"; -import { endpoints } from "../../util/constants.ts"; -import { requireBotGuildPermissions } from "../../util/permissions.ts"; +import type { Bot } from "../../bot.ts"; /** Modify a guild widget object for the guild. Requires the MANAGE_GUILD permission. */ -export async function editWidget(guildId: bigint, enabled: boolean, channelId?: string | null) { - await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); +export async function editWidget(bot: Bot, guildId: bigint, enabled: boolean, channelId?: string | null) { + await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]); - return await rest.runMethod("patch", endpoints.GUILD_WIDGET(guildId), { + return await bot.rest.runMethod(bot.rest,"patch", bot.constants.endpoints.GUILD_WIDGET(guildId), { enabled, channel_id: channelId, }); diff --git a/src/helpers/guilds/get_audit_logs.ts b/src/helpers/guilds/get_audit_logs.ts index ed8e9ab0d..471e28f3e 100644 --- a/src/helpers/guilds/get_audit_logs.ts +++ b/src/helpers/guilds/get_audit_logs.ts @@ -1,20 +1,20 @@ -import { rest } from "../../rest/rest.ts"; import type { AuditLog } from "../../types/audit_log/audit_log.ts"; import type { GetGuildAuditLog } from "../../types/audit_log/get_guild_audit_log.ts"; -import { endpoints } from "../../util/constants.ts"; -import { requireBotGuildPermissions } from "../../util/permissions.ts"; -import { snakelize } from "../../util/utils.ts"; +import type { Bot } from "../../bot.ts"; /** Returns the audit logs for the guild. Requires VIEW AUDIT LOGS permission */ -export async function getAuditLogs(guildId: bigint, options?: GetGuildAuditLog) { - await requireBotGuildPermissions(guildId, ["VIEW_AUDIT_LOG"]); +export async function getAuditLogs(bot: Bot, guildId: bigint, options?: GetGuildAuditLog) { + await bot.utils.requireBotGuildPermissions(bot, guildId, ["VIEW_AUDIT_LOG"]); - return await rest.runMethod( + return await bot.rest.runMethod( + bot.rest, "get", - endpoints.GUILD_AUDIT_LOGS(guildId), - snakelize({ - ...options, + bot.constants.endpoints.GUILD_AUDIT_LOGS(guildId), + { + user_id: options.userId, + action_type: options.actionType, + before: options.before, limit: options?.limit && options.limit >= 1 && options.limit <= 100 ? options.limit : 50, - }) + } ); } diff --git a/src/helpers/guilds/get_available_voice_regions.ts b/src/helpers/guilds/get_available_voice_regions.ts index 2111f6a3d..81d0e732e 100644 --- a/src/helpers/guilds/get_available_voice_regions.ts +++ b/src/helpers/guilds/get_available_voice_regions.ts @@ -1,8 +1,7 @@ -import { rest } from "../../rest/rest.ts"; import type { VoiceRegion } from "../../types/voice/voice_region.ts"; -import { endpoints } from "../../util/constants.ts"; +import type { Bot } from "../../bot.ts"; /** Returns an array of voice regions that can be used when creating servers. */ -export async function getAvailableVoiceRegions() { - return await rest.runMethod("get", endpoints.VOICE_REGIONS); +export async function getAvailableVoiceRegions(bot: Bot) { + return await bot.rest.runMethod(bot.rest,"get", bot.constants.endpoints.VOICE_REGIONS); } diff --git a/src/helpers/guilds/get_ban.ts b/src/helpers/guilds/get_ban.ts index 125277417..4633105c3 100644 --- a/src/helpers/guilds/get_ban.ts +++ b/src/helpers/guilds/get_ban.ts @@ -1,11 +1,9 @@ -import { rest } from "../../rest/rest.ts"; import type { Ban } from "../../types/guilds/ban.ts"; -import { endpoints } from "../../util/constants.ts"; -import { requireBotGuildPermissions } from "../../util/permissions.ts"; +import type { Bot } from "../../bot.ts"; /** Returns a ban object for the given user or a 404 not found if the ban cannot be found. Requires the BAN_MEMBERS permission. */ -export async function getBan(guildId: bigint, memberId: bigint) { - await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]); +export async function getBan(bot: Bot, guildId: bigint, memberId: bigint) { + await bot.utils.requireBotGuildPermissions(bot, guildId, ["BAN_MEMBERS"]); - return await rest.runMethod("get", endpoints.GUILD_BAN(guildId, memberId)); + return await bot.rest.runMethod(bot.rest,"get", bot.constants.endpoints.GUILD_BAN(guildId, memberId)); } diff --git a/src/helpers/guilds/get_bans.ts b/src/helpers/guilds/get_bans.ts index dd158e1aa..16f6fed39 100644 --- a/src/helpers/guilds/get_bans.ts +++ b/src/helpers/guilds/get_bans.ts @@ -1,15 +1,12 @@ -import { rest } from "../../rest/rest.ts"; import type { Ban } from "../../types/guilds/ban.ts"; -import { snowflakeToBigint } from "../../util/bigint.ts"; +import type { Bot } from "../../bot.ts"; import { Collection } from "../../util/collection.ts"; -import { endpoints } from "../../util/constants.ts"; -import { requireBotGuildPermissions } from "../../util/permissions.ts"; /** Returns a list of ban objects for the users banned from this guild. Requires the BAN_MEMBERS permission. */ -export async function getBans(guildId: bigint) { - await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]); +export async function getBans(bot: Bot, guildId: bigint) { + await bot.utils.requireBotGuildPermissions(bot, guildId, ["BAN_MEMBERS"]); - const results = await rest.runMethod("get", endpoints.GUILD_BANS(guildId)); + const results = await bot.rest.runMethod(bot.rest,"get", bot.constants.endpoints.GUILD_BANS(guildId)); - return new Collection(results.map((res) => [snowflakeToBigint(res.user.id), res])); + return new Collection(results.map((res) => [bot.transformers.snowflake(res.user.id), res])); } diff --git a/src/helpers/guilds/get_guild.ts b/src/helpers/guilds/get_guild.ts index 4e38d934d..3d815f2da 100644 --- a/src/helpers/guilds/get_guild.ts +++ b/src/helpers/guilds/get_guild.ts @@ -1,9 +1,5 @@ -import { cacheHandlers } from "../../cache.ts"; -import { rest } from "../../rest/rest.ts"; -import { structures } from "../../structures/mod.ts"; import type { Guild } from "../../types/guilds/guild.ts"; -import { endpoints } from "../../util/constants.ts"; -import { ws } from "../../ws/ws.ts"; +import type { Bot } from "../../bot.ts"; /** * ⚠️ **If you need this, you are probably doing something wrong. Always use cache.guilds.get() @@ -13,23 +9,27 @@ import { ws } from "../../ws/ws.ts"; * So it does not cache the guild, you must do it manually. * */ export async function getGuild( - guildId: bigint, - options: { counts?: boolean; addToCache?: boolean } = { - counts: true, - addToCache: true, - } + bot: Bot, + guildId: bigint, + options: { counts?: boolean; addToCache?: boolean } = { + counts: true, + addToCache: true, + } ) { - const result = await rest.runMethod("get", endpoints.GUILDS_BASE(guildId), { + const result = await bot.rest.runMethod(bot.rest,"get", bot.constants.endpoints.GUILDS_BASE(guildId), { with_counts: options.counts, }); - const guild = await structures.createDiscordenoGuild( - result, - Number((BigInt(guildId) >> 22n) % BigInt(ws.botGatewayData.shards)) + const guild = await bot.transformers.guild( + bot, + { + guild: result, + shardId: Number((BigInt(guildId) >> 22n) % BigInt(ws.botGatewayData.shards)) + } ); if (options.addToCache) { - await cacheHandlers.set("guilds", guild.id, guild); + await bot.cache.guilds.set(guild.id, guild); } return guild; diff --git a/src/helpers/guilds/get_guild_preview.ts b/src/helpers/guilds/get_guild_preview.ts index 04238da4d..388ee24cc 100644 --- a/src/helpers/guilds/get_guild_preview.ts +++ b/src/helpers/guilds/get_guild_preview.ts @@ -1,8 +1,7 @@ -import { rest } from "../../rest/rest.ts"; import type { GuildPreview } from "../../types/guilds/guild_preview.ts"; -import { endpoints } from "../../util/constants.ts"; +import type { Bot } from "../../bot.ts"; /** Returns the guild preview object for the given id. If the bot is not in the guild, then the guild must be Discoverable. */ -export async function getGuildPreview(guildId: bigint) { - return await rest.runMethod("get", endpoints.GUILD_PREVIEW(guildId)); +export async function getGuildPreview(bot: Bot, guildId: bigint) { + return await bot.rest.runMethod(bot.rest,"get", bot.constants.endpoints.GUILD_PREVIEW(guildId)); } diff --git a/src/helpers/guilds/get_prune_count.ts b/src/helpers/guilds/get_prune_count.ts index 3614aae14..e160df5f3 100644 --- a/src/helpers/guilds/get_prune_count.ts +++ b/src/helpers/guilds/get_prune_count.ts @@ -1,20 +1,19 @@ -import { rest } from "../../rest/rest.ts"; -import { Errors } from "../../types/discordeno/errors.ts"; import type { GetGuildPruneCountQuery } from "../../types/guilds/get_guild_prune_count.ts"; -import { endpoints } from "../../util/constants.ts"; -import { requireBotGuildPermissions } from "../../util/permissions.ts"; -import { snakelize } from "../../util/utils.ts"; +import type { Bot } from "../../bot.ts"; /** Check how many members would be removed from the server in a prune operation. Requires the KICK_MEMBERS permission */ -export async function getPruneCount(guildId: bigint, options?: GetGuildPruneCountQuery) { - if (options?.days && options.days < 1) throw new Error(Errors.PRUNE_MIN_DAYS); +export async function getPruneCount(bot: Bot, guildId: bigint, options?: GetGuildPruneCountQuery) { + if (options?.days && options.days < 1) throw new Error(bot.constants.Errors.PRUNE_MIN_DAYS); if (options?.days && options.days > 30) { - throw new Error(Errors.PRUNE_MAX_DAYS); + throw new Error(bot.constants.Errors.PRUNE_MAX_DAYS); } - await requireBotGuildPermissions(guildId, ["KICK_MEMBERS"]); + await bot.utils.requireBotGuildPermissions(guildId, ["KICK_MEMBERS"]); - const result = await rest.runMethod("get", endpoints.GUILD_PRUNE(guildId), snakelize(options ?? {})); + const result = await bot.rest.runMethod(bot.rest,"get", bot.constants.endpoints.GUILD_PRUNE(guildId), options ? { + days: options.days, + include_roles: options.includeRoles + } : {}); return result.pruned as number; } diff --git a/src/helpers/guilds/get_vainty_url.ts b/src/helpers/guilds/get_vanity_url.ts similarity index 59% rename from src/helpers/guilds/get_vainty_url.ts rename to src/helpers/guilds/get_vanity_url.ts index 7f5087556..64675f86e 100644 --- a/src/helpers/guilds/get_vainty_url.ts +++ b/src/helpers/guilds/get_vanity_url.ts @@ -1,13 +1,12 @@ -import { rest } from "../../rest/rest.ts"; import type { InviteMetadata } from "../../types/invites/invite_metadata.ts"; -import { endpoints } from "../../util/constants.ts"; +import type { Bot } from "../../bot.ts"; /** Returns the code and uses of the vanity url for this server if it is enabled else `code` will be null. Requires the `MANAGE_GUILD` permission. */ -export async function getVanityURL(guildId: bigint) { - return await rest.runMethod< +export async function getVanityURL(bot: Bot, guildId: bigint) { + return await bot.rest.runMethod< | (Partial & Pick) | { code: null; } - >("get", endpoints.GUILD_VANITY_URL(guildId)); + >(bot.rest,"get", bot.constants.endpoints.GUILD_VANITY_URL(guildId)); } diff --git a/src/helpers/guilds/get_voice_regions.ts b/src/helpers/guilds/get_voice_regions.ts index 756d876b3..b65ef53a0 100644 --- a/src/helpers/guilds/get_voice_regions.ts +++ b/src/helpers/guilds/get_voice_regions.ts @@ -1,11 +1,10 @@ -import { rest } from "../../rest/rest.ts"; import type { VoiceRegion } from "../../types/voice/voice_region.ts"; import { Collection } from "../../util/collection.ts"; -import { endpoints } from "../../util/constants.ts"; +import type { Bot } from "../../bot.ts"; /** Returns a list of voice region objects for the guild. Unlike the similar /voice route, this returns VIP servers when the guild is VIP-enabled. */ -export async function getVoiceRegions(guildId: bigint) { - const result = await rest.runMethod("get", endpoints.GUILD_REGIONS(guildId)); +export async function getVoiceRegions(boot: Bot, guildId: bigint) { + const result = await bot.rest.runMethod(bot.rest,"get", bot.constants.endpoints.GUILD_REGIONS(guildId)); return new Collection(result.map((region) => [region.id, region])); } diff --git a/src/helpers/guilds/get_welcome_screen.ts b/src/helpers/guilds/get_welcome_screen.ts index d048baf0b..c627ddb82 100644 --- a/src/helpers/guilds/get_welcome_screen.ts +++ b/src/helpers/guilds/get_welcome_screen.ts @@ -1,7 +1,6 @@ -import { rest } from "../../rest/rest.ts"; import type { WelcomeScreen } from "../../types/guilds/welcome_screen.ts"; -import { endpoints } from "../../util/constants.ts"; +import type { Bot } from "../../bot.ts"; -export async function getWelcomeScreen(guildId: bigint) { - return await rest.runMethod("get", endpoints.GUILD_WELCOME_SCREEN(guildId)); +export async function getWelcomeScreen(bot: Bot, guildId: bigint) { + return await bot.rest.runMethod(bot.rset,"get", bot.constants.endpoints.GUILD_WELCOME_SCREEN(guildId)); } diff --git a/src/helpers/guilds/get_widget.ts b/src/helpers/guilds/get_widget.ts index c66020cee..99b30d7a6 100644 --- a/src/helpers/guilds/get_widget.ts +++ b/src/helpers/guilds/get_widget.ts @@ -1,16 +1,13 @@ -import { cacheHandlers } from "../../cache.ts"; -import { rest } from "../../rest/rest.ts"; import type { GuildWidgetDetails } from "../../types/guilds/guild_widget_details.ts"; -import { Errors } from "../../types/discordeno/errors.ts"; -import { endpoints } from "../../util/constants.ts"; +import type { Bot } from "../../bot.ts"; /** Returns the widget for the guild. */ -export async function getWidget(guildId: bigint, options?: { force: boolean }) { +export async function getWidget(bot: Bot, guildId: bigint, options?: { force: boolean }) { if (!options?.force) { - const guild = await cacheHandlers.get("guilds", guildId); - if (!guild) throw new Error(Errors.GUILD_NOT_FOUND); - if (!guild?.widgetEnabled) throw new Error(Errors.GUILD_WIDGET_NOT_ENABLED); + const guild = await bot.cacahe.guilds.get(guildId); + if (!guild) throw new Error(bot.constants.Errors.GUILD_NOT_FOUND); + if (!guild?.widgetEnabled) throw new Error(bot.constants.Errors.GUILD_WIDGET_NOT_ENABLED); } - return await rest.runMethod("get", `${endpoints.GUILD_WIDGET(guildId)}.json`); + return await bot.rest.runMethod(bot.rest,"get", `${bot.constants.endpoints.GUILD_WIDGET(guildId)}.json`); } diff --git a/src/helpers/guilds/get_widget_image_url.ts b/src/helpers/guilds/get_widget_image_url.ts index 28cd5d94f..355035898 100644 --- a/src/helpers/guilds/get_widget_image_url.ts +++ b/src/helpers/guilds/get_widget_image_url.ts @@ -1,15 +1,13 @@ -import { cacheHandlers } from "../../cache.ts"; +import type { Bot } from "../../bot.ts"; import type { GetGuildWidgetImageQuery } from "../../types/guilds/get_guild_widget_image.ts"; -import { Errors } from "../../types/discordeno/errors.ts"; -import { endpoints } from "../../util/constants.ts"; /** Returns the widget image URL for the guild. */ -export async function getWidgetImageURL(guildId: bigint, options?: GetGuildWidgetImageQuery & { force?: boolean }) { +export async function getWidgetImageURL(bot: Bot, guildId: bigint, options?: GetGuildWidgetImageQuery & { force?: boolean }) { if (!options?.force) { - const guild = await cacheHandlers.get("guilds", guildId); - if (!guild) throw new Error(Errors.GUILD_NOT_FOUND); - if (!guild.widgetEnabled) throw new Error(Errors.GUILD_WIDGET_NOT_ENABLED); + const guild = await bot.cache.guilds.get(guildId); + if (!guild) throw new Error(bot.constants.Errors.GUILD_NOT_FOUND); + if (!guild.widgetEnabled) throw new Error(bot.constants.Errors.GUILD_WIDGET_NOT_ENABLED); } - return `${endpoints.GUILD_WIDGET(guildId)}.png?style=${options?.style ?? "shield"}`; + return `${bot.constants.endpoints.GUILD_WIDGET(guildId)}.png?style=${options?.style ?? "shield"}`; } diff --git a/src/helpers/guilds/get_widget_settings.ts b/src/helpers/guilds/get_widget_settings.ts index 23417a61a..e6cb44d33 100644 --- a/src/helpers/guilds/get_widget_settings.ts +++ b/src/helpers/guilds/get_widget_settings.ts @@ -1,11 +1,9 @@ -import { rest } from "../../rest/rest.ts"; import type { GuildWidget } from "../../types/guilds/guild_widget.ts"; -import { endpoints } from "../../util/constants.ts"; -import { requireBotGuildPermissions } from "../../util/permissions.ts"; +import type { Bot } from "../../bot.ts"; /** Returns the guild widget object. Requires the MANAGE_GUILD permission. */ -export async function getWidgetSettings(guildId: bigint) { - await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); +export async function getWidgetSettings(bot: Bot, guildId: bigint) { + await bot.utils.requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); - return await rest.runMethod("get", endpoints.GUILD_WIDGET(guildId)); + return await bot.rest.runMethod(bot.rest,"get", bot.constants.endpoints.GUILD_WIDGET(guildId)); } diff --git a/src/helpers/guilds/guild_banner_url.ts b/src/helpers/guilds/guild_banner_url.ts index e4167c3cc..310a9aa52 100644 --- a/src/helpers/guilds/guild_banner_url.ts +++ b/src/helpers/guilds/guild_banner_url.ts @@ -1,11 +1,10 @@ import type { DiscordImageFormat } from "../../types/misc/image_format.ts"; import type { DiscordImageSize } from "../../types/misc/image_size.ts"; -import { endpoints } from "../../util/constants.ts"; -import { iconBigintToHash } from "../../util/hash.ts"; -import { formatImageURL } from "../../util/utils.ts"; +import type { Bot } from "../../bot.ts"; /** The full URL of the banner from Discords CDN. Undefined if no banner is set. */ export function guildBannerURL( + bot: Bot, id: bigint, options: { banner?: string | bigint; @@ -15,12 +14,12 @@ export function guildBannerURL( } ) { return options.banner - ? formatImageURL( - endpoints.GUILD_BANNER( + ? bot.utils.formatImageURL( + bot.constants.endpoints.GUILD_BANNER( id, typeof options.banner === "string" ? options.banner - : iconBigintToHash(options.banner, options.animated ?? true) + : bot.utils.iconBigintToHash(options.banner, options.animated ?? true) ), options.size || 128, options.format diff --git a/src/helpers/guilds/guild_icon_url.ts b/src/helpers/guilds/guild_icon_url.ts index 3d7af4a4d..ae399abe0 100644 --- a/src/helpers/guilds/guild_icon_url.ts +++ b/src/helpers/guilds/guild_icon_url.ts @@ -1,11 +1,10 @@ import type { DiscordImageFormat } from "../../types/misc/image_format.ts"; import type { DiscordImageSize } from "../../types/misc/image_size.ts"; -import { endpoints } from "../../util/constants.ts"; -import { iconBigintToHash } from "../../util/hash.ts"; -import { formatImageURL } from "../../util/utils.ts"; +import type { Bot } from "../../bot.ts"; /** The full URL of the icon from Discords CDN. Undefined when no icon is set. */ export function guildIconURL( + bot: Bot, id: bigint, options: { icon?: string | bigint; @@ -15,10 +14,10 @@ export function guildIconURL( } ) { return options.icon - ? formatImageURL( - endpoints.GUILD_ICON( + ? bot.utils.formatImageURL( + bot.constants.endpoints.GUILD_ICON( id, - typeof options.icon === "string" ? options.icon : iconBigintToHash(options.icon, options.animated ?? true) + typeof options.icon === "string" ? options.icon : bot.utils.iconBigintToHash(options.icon, options.animated ?? true) ), options.size || 128, options.format diff --git a/src/helpers/guilds/guild_splash_url.ts b/src/helpers/guilds/guild_splash_url.ts index 86e029982..aaee1f810 100644 --- a/src/helpers/guilds/guild_splash_url.ts +++ b/src/helpers/guilds/guild_splash_url.ts @@ -1,11 +1,10 @@ import type { DiscordImageFormat } from "../../types/misc/image_format.ts"; import type { DiscordImageSize } from "../../types/misc/image_size.ts"; -import { endpoints } from "../../util/constants.ts"; -import { iconBigintToHash } from "../../util/hash.ts"; -import { formatImageURL } from "../../util/utils.ts"; +import type { Bot } from "../../bot.ts"; /** The full URL of the splash from Discords CDN. Undefined if no splash is set. */ export function guildSplashURL( + bot: Bot, id: bigint, options: { splash?: string | bigint; @@ -15,12 +14,12 @@ export function guildSplashURL( } ) { return options.splash - ? formatImageURL( - endpoints.GUILD_SPLASH( + ? bot.utils.formatImageURL( + bot.constants.endpoints.GUILD_SPLASH( id, typeof options.splash === "string" ? options.splash - : iconBigintToHash(options.splash, options.animated ?? true) + : bot.utils.iconBigintToHash(options.splash, options.animated ?? true) ), options.size || 128, options.format diff --git a/src/helpers/guilds/leave_guild.ts b/src/helpers/guilds/leave_guild.ts index 3e8813535..28b4da5d2 100644 --- a/src/helpers/guilds/leave_guild.ts +++ b/src/helpers/guilds/leave_guild.ts @@ -1,7 +1,6 @@ -import { rest } from "../../rest/rest.ts"; -import { endpoints } from "../../util/constants.ts"; +import type { Bot } from "../../bot.ts"; /** Leave a guild */ -export async function leaveGuild(guildId: bigint) { - return await rest.runMethod("delete", endpoints.GUILD_LEAVE(guildId)); +export async function leaveGuild(bot: Bot, guildId: bigint) { + return await bot.rest.runMethod(bot.rest,"delete", bot.constants.endpoints.GUILD_LEAVE(guildId)); } diff --git a/src/helpers/interactions/commands/edit_slash_response.ts b/src/helpers/interactions/commands/edit_slash_response.ts index c2bb4cbf2..d3f186b17 100644 --- a/src/helpers/interactions/commands/edit_slash_response.ts +++ b/src/helpers/interactions/commands/edit_slash_response.ts @@ -66,5 +66,5 @@ export async function editSlashResponse(bot: Bot, token: string, options: Discor // If the original message was edited, this will not return a message if (!options.messageId) return result as undefined; - return bot.transformers.message(result); + return bot.transformers.message(bot, result); } diff --git a/src/helpers/interactions/get_original_interaction_response.ts b/src/helpers/interactions/get_original_interaction_response.ts index 83cc029ae..accb0cf65 100644 --- a/src/helpers/interactions/get_original_interaction_response.ts +++ b/src/helpers/interactions/get_original_interaction_response.ts @@ -10,5 +10,5 @@ export async function getOriginalInteractionResponse(bot: Bot, token: string) { bot.constants.endpoints.INTERACTION_ORIGINAL_ID_TOKEN(bot.applicationId, token) ); - return bot.transformers.message(result); + return bot.transformers.message(bot, result); } diff --git a/src/helpers/members/send_direct_message.ts b/src/helpers/members/send_direct_message.ts index 1d1a50ed1..e1990b950 100644 --- a/src/helpers/members/send_direct_message.ts +++ b/src/helpers/members/send_direct_message.ts @@ -18,7 +18,7 @@ export async function sendDirectMessage(bot: Bot, memberId: bigint, content: str recipient_id: memberId, } ); - const discordenoChannel = await bot.transformers.channel(bot, dmChannelData); + const discordenoChannel = await bot.transformers.channel(bot, {channel: dmChannelData}); // Recreate the channel and add it under the users id await bot.cache.channels.set(memberId, discordenoChannel); dmChannel = discordenoChannel; diff --git a/src/helpers/mod.ts b/src/helpers/mod.ts index 37825487b..3c7a37fde 100644 --- a/src/helpers/mod.ts +++ b/src/helpers/mod.ts @@ -37,7 +37,7 @@ import { getBans } from "./guilds/get_bans.ts"; import { getGuild } from "./guilds/get_guild.ts"; import { getGuildPreview } from "./guilds/get_guild_preview.ts"; import { getPruneCount } from "./guilds/get_prune_count.ts"; -import { getVanityURL } from "./guilds/get_vainty_url.ts"; +import { getVanityURL } from "./guilds/get_vanity_url.ts"; import { getVoiceRegions } from "./guilds/get_voice_regions.ts"; import { getWelcomeScreen } from "./guilds/get_welcome_screen.ts"; import { getWidget } from "./guilds/get_widget.ts"; diff --git a/src/helpers/webhooks/edit_webhook_message.ts b/src/helpers/webhooks/edit_webhook_message.ts index 16760855c..5bbc7f316 100644 --- a/src/helpers/webhooks/edit_webhook_message.ts +++ b/src/helpers/webhooks/edit_webhook_message.ts @@ -67,5 +67,5 @@ export async function editWebhookMessage( } ); - return bot.transformers.message(result); + return bot.transformers.message(bot, result); } diff --git a/src/helpers/webhooks/get_webhook_message.ts b/src/helpers/webhooks/get_webhook_message.ts index 070eb2fb9..275a74a3e 100644 --- a/src/helpers/webhooks/get_webhook_message.ts +++ b/src/helpers/webhooks/get_webhook_message.ts @@ -10,5 +10,5 @@ export async function getWebhookMessage(bot: Bot, webhookId: bigint, webhookToke bot.constants.endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId) ); - return bot.transformers.message(result); + return bot.transformers.message(bot, result); } diff --git a/src/helpers/webhooks/send_webhook.ts b/src/helpers/webhooks/send_webhook.ts index b0991bc37..c9ecab292 100644 --- a/src/helpers/webhooks/send_webhook.ts +++ b/src/helpers/webhooks/send_webhook.ts @@ -58,5 +58,5 @@ export async function sendWebhook(bot: Bot, webhookId: bigint, webhookToken: str ); if (!options.wait) return; - return bot.transformers.message(result); + return bot.transformers.message(bot, result); }