From 3d39b3878a1ef69102ec284de98fa2cc29ca77c6 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Mon, 3 May 2021 13:05:18 -0400 Subject: [PATCH] change: ids to use bigint instead of string (#892) * p1 of bigints change * shtuff fixes and bits * Commit from GitHub Actions (Lint) * finish bigint structs * typings fixes * Commit from GitHub Actions (Lint) * more fixes * Commit from GitHub Actions (Lint) * more fixes * Commit from GitHub Actions (Lint) * blame wolf * Commit from GitHub Actions (Lint) * foxed * Commit from GitHub Actions (Lint) * fix unit tests * Commit from GitHub Actions (Lint) * change: guildUpdate guild ID can't change * delete server has been renamed to delete guild * fixes Co-authored-by: Skillz4Killz Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> --- src/bot.ts | 9 +- src/cache.ts | 104 ++++++------ src/handlers/channels/CHANNEL_DELETE.ts | 14 +- src/handlers/channels/CHANNEL_PINS_UPDATE.ts | 8 +- src/handlers/channels/CHANNEL_UPDATE.ts | 6 +- src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts | 10 +- src/handlers/guilds/GUILD_BAN_ADD.ts | 11 +- src/handlers/guilds/GUILD_BAN_REMOVE.ts | 11 +- src/handlers/guilds/GUILD_CREATE.ts | 19 +-- src/handlers/guilds/GUILD_DELETE.ts | 20 ++- .../guilds/GUILD_INTEGRATIONS_UPDATE.ts | 6 +- src/handlers/guilds/GUILD_UPDATE.ts | 9 +- .../interactions/INTERACTION_CREATE.ts | 3 +- src/handlers/members/GUILD_MEMBERS_CHUNK.ts | 7 +- src/handlers/members/GUILD_MEMBER_ADD.ts | 8 +- src/handlers/members/GUILD_MEMBER_REMOVE.ts | 11 +- src/handlers/members/GUILD_MEMBER_UPDATE.ts | 25 ++- src/handlers/messages/MESSAGE_CREATE.ts | 14 +- src/handlers/messages/MESSAGE_DELETE.ts | 10 +- src/handlers/messages/MESSAGE_DELETE_BULK.ts | 10 +- src/handlers/messages/MESSAGE_REACTION_ADD.ts | 19 ++- .../messages/MESSAGE_REACTION_REMOVE.ts | 8 +- .../messages/MESSAGE_REACTION_REMOVE_ALL.ts | 12 +- .../messages/MESSAGE_REACTION_REMOVE_EMOJI.ts | 14 +- src/handlers/messages/MESSAGE_UPDATE.ts | 13 +- src/handlers/misc/PRESENCE_UPDATE.ts | 12 +- src/handlers/misc/READY.ts | 5 +- src/handlers/misc/USER_UPDATE.ts | 8 +- src/handlers/roles/GUILD_ROLE_CREATE.ts | 15 +- src/handlers/roles/GUILD_ROLE_DELETE.ts | 16 +- src/handlers/roles/GUILD_ROLE_UPDATE.ts | 15 +- src/handlers/voice/VOICE_SERVER_UPDATE.ts | 6 +- src/handlers/voice/VOICE_STATE_UPDATE.ts | 31 ++-- src/handlers/webhooks/WEBHOOKS_UPDATE.ts | 5 +- src/helpers/channels/category_children.ts | 2 +- .../channel_overwrite_has_permission.ts | 10 +- src/helpers/channels/clone_channel.ts | 13 +- src/helpers/channels/create_channel.ts | 2 +- src/helpers/channels/delete_channel.ts | 4 +- .../channels/delete_channel_overwrite.ts | 6 +- src/helpers/channels/edit_channel.ts | 8 +- .../channels/edit_channel_overwrite.ts | 6 +- src/helpers/channels/follow_channel.ts | 4 +- src/helpers/channels/get_channel.ts | 5 +- src/helpers/channels/get_channel_webhooks.ts | 2 +- src/helpers/channels/get_channels.ts | 2 +- src/helpers/channels/get_pins.ts | 2 +- src/helpers/channels/is_channel_synced.ts | 2 +- src/helpers/channels/start_typing.ts | 2 +- src/helpers/channels/swap_channels.ts | 2 +- .../batch_edit_slash_command_permissions.ts | 2 +- src/helpers/commands/create_slash_command.ts | 2 +- src/helpers/commands/delete_slash_command.ts | 4 +- src/helpers/commands/delete_slash_response.ts | 2 +- .../edit_slash_command_permissions.ts | 4 +- src/helpers/commands/get_slash_command.ts | 2 +- .../commands/get_slash_command_permission.ts | 4 +- .../commands/get_slash_command_permissions.ts | 2 +- src/helpers/commands/get_slash_commands.ts | 2 +- .../commands/send_interaction_response.ts | 4 +- src/helpers/commands/upsert_slash_command.ts | 4 +- src/helpers/commands/upsert_slash_commands.ts | 2 +- .../discovery/add_discovery_subcategory.ts | 2 +- src/helpers/discovery/edit_discovery.ts | 2 +- .../discovery/remove_discovery_subcategory.ts | 2 +- src/helpers/emojis/create_emoji.ts | 22 ++- src/helpers/emojis/delete_emoji.ts | 4 +- src/helpers/emojis/edit_emoji.ts | 4 +- src/helpers/emojis/emoji_url.ts | 2 +- src/helpers/emojis/get_emoji.ts | 4 +- src/helpers/emojis/get_emojis.ts | 5 +- src/helpers/guilds/delete_guild.ts | 2 +- src/helpers/guilds/edit_guild.ts | 2 +- src/helpers/guilds/edit_welcome_screen.ts | 2 +- src/helpers/guilds/edit_widget.ts | 2 +- src/helpers/guilds/get_audit_logs.ts | 2 +- src/helpers/guilds/get_ban.ts | 2 +- src/helpers/guilds/get_bans.ts | 7 +- src/helpers/guilds/get_guild.ts | 8 +- src/helpers/guilds/get_guild_preview.ts | 2 +- src/helpers/guilds/get_prune_count.ts | 2 +- src/helpers/guilds/get_vainty_url.ts | 2 +- src/helpers/guilds/get_voice_regions.ts | 2 +- src/helpers/guilds/get_welcome_screen.ts | 2 +- src/helpers/guilds/get_widget.ts | 2 +- src/helpers/guilds/get_widget_image_url.ts | 2 +- src/helpers/guilds/get_widget_settings.ts | 2 +- src/helpers/guilds/guild_banner_url.ts | 2 +- src/helpers/guilds/guild_icon_url.ts | 2 +- src/helpers/guilds/guild_splash_url.ts | 2 +- src/helpers/guilds/leave_guild.ts | 2 +- src/helpers/guilds/update_bot_voice_state.ts | 2 +- src/helpers/guilds/update_user_voice_state.ts | 4 +- .../integrations/delete_integration.ts | 2 +- src/helpers/integrations/get_integrations.ts | 2 +- src/helpers/invites/create_invite.ts | 2 +- src/helpers/invites/delete_invite.ts | 2 +- src/helpers/invites/get_channel_invites.ts | 2 +- src/helpers/invites/get_invites.ts | 2 +- src/helpers/members/avatar_url.ts | 4 +- src/helpers/members/ban_member.ts | 4 +- src/helpers/members/disconnect_member.ts | 2 +- src/helpers/members/edit_bot_nickname.ts | 2 +- src/helpers/members/edit_member.ts | 14 +- src/helpers/members/fetch_members.ts | 4 +- src/helpers/members/get_member.ts | 4 +- src/helpers/members/get_members.ts | 9 +- src/helpers/members/kick_member.ts | 2 +- src/helpers/members/move_member.ts | 6 +- src/helpers/members/prune_members.ts | 2 +- src/helpers/members/search_members.ts | 4 +- src/helpers/members/send_direct_message.ts | 2 +- src/helpers/members/unban_member.ts | 2 +- src/helpers/messages/add_reaction.ts | 4 +- src/helpers/messages/add_reactions.ts | 4 +- src/helpers/messages/delete_message.ts | 6 +- src/helpers/messages/delete_messages.ts | 2 +- src/helpers/messages/edit_message.ts | 2 +- src/helpers/messages/get_message.ts | 2 +- src/helpers/messages/get_messages.ts | 2 +- src/helpers/messages/get_reactions.ts | 4 +- src/helpers/messages/pin_message.ts | 2 +- src/helpers/messages/publish_message.ts | 2 +- src/helpers/messages/remove_all_reactions.ts | 2 +- src/helpers/messages/remove_reaction.ts | 6 +- src/helpers/messages/remove_reaction_emoji.ts | 4 +- src/helpers/messages/send_message.ts | 2 +- src/helpers/messages/unpin_message.ts | 4 +- src/helpers/misc/get_user.ts | 2 +- src/helpers/roles/add_role.ts | 6 +- src/helpers/roles/create_role.ts | 2 +- src/helpers/roles/delete_role.ts | 2 +- src/helpers/roles/edit_role.ts | 4 +- src/helpers/roles/get_roles.ts | 2 +- src/helpers/roles/remove_role.ts | 6 +- .../templates/create_guild_template.ts | 2 +- .../templates/delete_guild_template.ts | 2 +- src/helpers/templates/edit_guild_template.ts | 2 +- src/helpers/templates/get_guild_templates.ts | 2 +- src/helpers/templates/sync_guild_template.ts | 2 +- src/helpers/webhooks/create_webhook.ts | 2 +- src/helpers/webhooks/delete_webhook.ts | 2 +- .../webhooks/delete_webhook_message.ts | 4 +- .../webhooks/delete_webhook_with_token.ts | 2 +- src/helpers/webhooks/edit_webhook.ts | 4 +- src/helpers/webhooks/edit_webhook_message.ts | 4 +- .../webhooks/edit_webhook_with_token.ts | 2 +- src/helpers/webhooks/execute_webhook.ts | 2 +- src/helpers/webhooks/get_webhook.ts | 2 +- .../webhooks/get_webhook_with_token.ts | 2 +- src/helpers/webhooks/get_webhooks.ts | 2 +- src/rest/run_method.ts | 9 ++ src/structures/channel.ts | 100 +++++++++--- src/structures/guild.ts | 105 ++++++++++--- src/structures/member.ts | 91 ++++++++--- src/structures/message.ts | 107 +++++++++---- src/structures/mod.ts | 2 + src/structures/role.ts | 48 ++++-- src/structures/voice_state.ts | 125 +++++++++++++++ src/types/channels/channel.ts | 4 +- src/types/channels/overwrite.ts | 2 - src/types/discordeno/edit_webhook_message.ts | 2 +- src/types/discordeno/eventHandlers.ts | 26 +-- src/types/guilds/guild.ts | 2 +- src/types/messages/message.ts | 2 +- src/util/bigint.ts | 7 + src/util/constants.ts | 148 +++++++++--------- src/util/loop_object.ts | 39 +++++ src/util/permissions.ts | 70 ++++----- src/ws/ws.ts | 2 +- test.ts | 75 +++++++++ tests/channels/category_children.ts | 3 +- .../channel_overwrite_has_permission.ts | 3 +- tests/channels/clone_channel.ts | 3 +- tests/channels/create_channel.ts | 3 +- tests/channels/delete_channel_overwrite.ts | 3 +- tests/channels/edit_channel_overwrite.ts | 3 +- tests/channels/is_channel_synced.ts | 5 +- tests/channels/swap_channels.ts | 4 +- .../{delete_server.ts => delete_guild.ts} | 0 tests/messages/delete_messages.ts | 2 +- tests/messages/get_messages.ts | 2 +- tests/messages/remove_reaction.ts | 4 +- tests/mod.ts | 3 +- tests/util/loop_object.ts | 52 ++++++ tests/ws/start_bot.ts | 8 +- 186 files changed, 1341 insertions(+), 610 deletions(-) create mode 100644 src/structures/voice_state.ts create mode 100644 src/util/bigint.ts create mode 100644 src/util/loop_object.ts create mode 100644 test.ts rename tests/guilds/{delete_server.ts => delete_guild.ts} (100%) create mode 100644 tests/util/loop_object.ts diff --git a/src/bot.ts b/src/bot.ts index c36939832..f23043674 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -2,12 +2,13 @@ import { getGatewayBot } from "./helpers/misc/get_gateway_bot.ts"; import { rest } from "./rest/rest.ts"; import { EventHandlers } from "./types/discordeno/eventHandlers.ts"; import { DiscordGatewayIntents } from "./types/gateway/gateway_intents.ts"; +import { snowflakeToBigint } from "./util/bigint.ts"; import { baseEndpoints, GATEWAY_VERSION } from "./util/constants.ts"; import { ws } from "./ws/ws.ts"; export let secretKey = ""; -export let botId = ""; -export let applicationId = ""; +export let botId = 0n; +export let applicationId = 0n; export let eventHandlers: EventHandlers = {}; @@ -49,12 +50,12 @@ export function updateEventHandlers(newEventHandlers: EventHandlers) { /** INTERNAL LIB function used to set the bot Id once the READY event is sent by Discord. */ export function setBotId(id: string) { - if (botId !== id) botId = id; + botId = snowflakeToBigint(id); } /** INTERNAL LIB function used to set the application Id once the READY event is sent by Discord. */ export function setApplicationId(id: string) { - if (applicationId !== id) applicationId = id; + applicationId = snowflakeToBigint(id); } // BIG BRAIN BOT STUFF ONLY BELOW THIS diff --git a/src/cache.ts b/src/cache.ts index 317fa7dd0..3beadbb7b 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -10,26 +10,26 @@ import { Collection } from "./util/collection.ts"; export const cache = { isReady: false, /** All of the guild objects the bot has access to, mapped by their Ids */ - guilds: new Collection(), + guilds: new Collection(), /** All of the channel objects the bot has access to, mapped by their Ids */ - channels: new Collection(), + channels: new Collection(), /** All of the message objects the bot has cached since the bot acquired `READY` state, mapped by their Ids */ - messages: new Collection(), + messages: new Collection(), /** All of the member objects that have been cached since the bot acquired `READY` state, mapped by their Ids */ - members: new Collection(), + members: new Collection(), /** All of the unavailable guilds, mapped by their Ids (id, timestamp) */ - unavailableGuilds: new Collection(), + unavailableGuilds: new Collection(), /** All of the presence update objects received in PRESENCE_UPDATE gateway event, mapped by their user Id */ - presences: new Collection(), + presences: new Collection(), fetchAllMembersProcessingRequests: new Collection< string, ( value: - | Collection - | PromiseLike>, + | Collection + | PromiseLike>, ) => void >(), - executedSlashCommands: new Collection(), + executedSlashCommands: new Set(), get emojis() { return new Collection( this.guilds.reduce( @@ -46,11 +46,11 @@ export let cacheHandlers = { return cache[table].clear(); }, /** Deletes 1 item from cache using the key */ - async delete(table: TableName, key: string) { + async delete(table: TableName, key: bigint) { return cache[table].delete(key); }, /** Check if something exists in cache with a key */ - async has(table: TableName, key: string) { + async has(table: TableName, key: bigint) { return cache[table].has(key); }, @@ -80,63 +80,63 @@ export type TableName = function set( table: "guilds", - key: string, + key: bigint, value: DiscordenoGuild, -): Promise>; +): Promise>; function set( table: "channels", - key: string, + key: bigint, value: DiscordenoChannel, -): Promise>; +): Promise>; function set( table: "messages", - key: string, + key: bigint, value: DiscordenoMessage, -): Promise>; +): Promise>; function set( table: "members", - key: string, + key: bigint, value: DiscordenoMember, -): Promise>; +): Promise>; function set( table: "presences", - key: string, + key: bigint, value: PresenceUpdate, -): Promise>; +): Promise>; function set( table: "unavailableGuilds", - key: string, + key: bigint, value: number, -): Promise>; -async function set(table: TableName, key: string, value: any) { +): Promise>; +async function set(table: TableName, key: bigint, value: any) { return cache[table].set(key, value); } function get( table: "guilds", - key: string, + key: bigint, ): Promise; function get( table: "channels", - key: string, + key: bigint, ): Promise; function get( table: "messages", - key: string, + key: bigint, ): Promise; function get( table: "members", - key: string, + key: bigint, ): Promise; function get( table: "presences", - key: string, + key: bigint, ): Promise; function get( table: "unavailableGuilds", - key: string, + key: bigint, ): Promise; -async function get(table: TableName, key: string) { +async function get(table: TableName, key: bigint) { return cache[table].get(key); } @@ -144,68 +144,68 @@ function forEach( table: "guilds", callback: ( value: DiscordenoGuild, - key: string, - map: Map, + key: bigint, + map: Map, ) => unknown, ): void; function forEach( table: "unavailableGuilds", - callback: (value: number, key: string, map: Map) => unknown, + callback: (value: number, key: bigint, map: Map) => unknown, ): void; function forEach( table: "channels", callback: ( value: DiscordenoChannel, - key: string, - map: Map, + key: bigint, + map: Map, ) => unknown, ): void; function forEach( table: "messages", callback: ( value: DiscordenoMessage, - key: string, - map: Map, + key: bigint, + map: Map, ) => unknown, ): void; function forEach( table: "members", callback: ( value: DiscordenoMember, - key: string, - map: Map, + key: bigint, + map: Map, ) => unknown, ): void; function forEach( table: TableName, - callback: (value: any, key: string, map: Map) => unknown, + callback: (value: any, key: bigint, map: Map) => unknown, ) { return cache[table].forEach(callback); } function filter( table: "guilds", - callback: (value: DiscordenoGuild, key: string) => boolean, -): Promise>; + callback: (value: DiscordenoGuild, key: bigint) => boolean, +): Promise>; function filter( table: "unavailableGuilds", - callback: (value: number, key: string) => boolean, -): Promise>; + callback: (value: number, key: bigint) => boolean, +): Promise>; function filter( table: "channels", - callback: (value: DiscordenoChannel, key: string) => boolean, -): Promise>; + callback: (value: DiscordenoChannel, key: bigint) => boolean, +): Promise>; function filter( table: "messages", - callback: (value: DiscordenoMessage, key: string) => boolean, -): Promise>; + callback: (value: DiscordenoMessage, key: bigint) => boolean, +): Promise>; function filter( table: "members", - callback: (value: DiscordenoMember, key: string) => boolean, -): Promise>; + callback: (value: DiscordenoMember, key: bigint) => boolean, +): Promise>; async function filter( table: TableName, - callback: (value: any, key: string) => boolean, + callback: (value: any, key: bigint) => boolean, ) { return cache[table].filter(callback); } diff --git a/src/handlers/channels/CHANNEL_DELETE.ts b/src/handlers/channels/CHANNEL_DELETE.ts index f4c07229f..1b226370b 100644 --- a/src/handlers/channels/CHANNEL_DELETE.ts +++ b/src/handlers/channels/CHANNEL_DELETE.ts @@ -3,21 +3,25 @@ import { cacheHandlers } from "../../cache.ts"; import { Channel } from "../../types/channels/channel.ts"; import { DiscordChannelTypes } from "../../types/channels/channel_types.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleChannelDelete(data: DiscordGatewayPayload) { const payload = data.d as Channel; - const cachedChannel = await cacheHandlers.get("channels", payload.id); + const cachedChannel = await cacheHandlers.get( + "channels", + snowflakeToBigint(payload.id), + ); if (!cachedChannel) return; if ( cachedChannel.type === DiscordChannelTypes.GUILD_VOICE && payload.guildId ) { - const guild = await cacheHandlers.get("guilds", payload.guildId); + const guild = await cacheHandlers.get("guilds", cachedChannel.guildId); if (guild) { return Promise.all(guild.voiceStates.map(async (vs, key) => { - if (vs.channelId !== payload.id) return; + if (vs.channelId !== cachedChannel.id) return; // Since this channel was deleted all voice states for this channel should be deleted guild.voiceStates.delete(key); @@ -30,13 +34,13 @@ export async function handleChannelDelete(data: DiscordGatewayPayload) { } } - await cacheHandlers.delete("channels", payload.id); + await cacheHandlers.delete("channels", snowflakeToBigint(payload.id)); cacheHandlers.forEach("messages", (message) => { eventHandlers.debug?.( "loop", `Running forEach messages loop in CHANNEL_DELTE file.`, ); - if (message.channelId === payload.id) { + if (message.channelId === snowflakeToBigint(payload.id)) { cacheHandlers.delete("messages", message.id); } }); diff --git a/src/handlers/channels/CHANNEL_PINS_UPDATE.ts b/src/handlers/channels/CHANNEL_PINS_UPDATE.ts index 371274096..b5570bc2e 100644 --- a/src/handlers/channels/CHANNEL_PINS_UPDATE.ts +++ b/src/handlers/channels/CHANNEL_PINS_UPDATE.ts @@ -2,15 +2,19 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { ChannelPinsUpdate } from "../../types/channels/channel_pins_update.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleChannelPinsUpdate(data: DiscordGatewayPayload) { const payload = data.d as ChannelPinsUpdate; - const channel = await cacheHandlers.get("channels", payload.channelId); + const channel = await cacheHandlers.get( + "channels", + snowflakeToBigint(payload.channelId), + ); if (!channel) return; const guild = payload.guildId - ? await cacheHandlers.get("guilds", payload.guildId) + ? await cacheHandlers.get("guilds", snowflakeToBigint(payload.guildId)) : undefined; eventHandlers.channelPinsUpdate?.(channel, guild, payload.lastPinTimestamp); diff --git a/src/handlers/channels/CHANNEL_UPDATE.ts b/src/handlers/channels/CHANNEL_UPDATE.ts index 1045545c5..624eaaf70 100644 --- a/src/handlers/channels/CHANNEL_UPDATE.ts +++ b/src/handlers/channels/CHANNEL_UPDATE.ts @@ -3,10 +3,14 @@ import { cacheHandlers } from "../../cache.ts"; import { structures } from "../../structures/mod.ts"; import { Channel } from "../../types/channels/channel.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleChannelUpdate(data: DiscordGatewayPayload) { const payload = data.d as Channel; - const cachedChannel = await cacheHandlers.get("channels", payload.id); + const cachedChannel = await cacheHandlers.get( + "channels", + snowflakeToBigint(payload.id), + ); const discordenoChannel = await structures.createDiscordenoChannel(payload); await cacheHandlers.set("channels", discordenoChannel.id, discordenoChannel); diff --git a/src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts b/src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts index 40ae9f496..bbb1c817d 100644 --- a/src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts +++ b/src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts @@ -2,19 +2,23 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { GuildEmojisUpdate } from "../../types/emojis/guild_emojis_update.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; import { Collection } from "../../util/collection.ts"; export async function handleGuildEmojisUpdate(data: DiscordGatewayPayload) { const payload = data.d as GuildEmojisUpdate; - const guild = await cacheHandlers.get("guilds", payload.guildId); + const guild = await cacheHandlers.get( + "guilds", + snowflakeToBigint(payload.guildId), + ); if (!guild) return; const cachedEmojis = guild.emojis; guild.emojis = new Collection( - payload.emojis.map((emoji) => [emoji.id!, emoji]), + payload.emojis.map((emoji) => [snowflakeToBigint(emoji.id!), emoji]), ); - await cacheHandlers.set("guilds", payload.guildId, guild); + await cacheHandlers.set("guilds", guild.id, guild); eventHandlers.guildEmojisUpdate?.( guild, diff --git a/src/handlers/guilds/GUILD_BAN_ADD.ts b/src/handlers/guilds/GUILD_BAN_ADD.ts index 56df5c0e1..70d233ff0 100644 --- a/src/handlers/guilds/GUILD_BAN_ADD.ts +++ b/src/handlers/guilds/GUILD_BAN_ADD.ts @@ -2,12 +2,19 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { GuildBanAddRemove } from "../../types/guilds/guild_ban_add_remove.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleGuildBanAdd(data: DiscordGatewayPayload) { const payload = data.d as GuildBanAddRemove; - const guild = await cacheHandlers.get("guilds", payload.guildId); + const guild = await cacheHandlers.get( + "guilds", + snowflakeToBigint(payload.guildId), + ); if (!guild) return; - const member = await cacheHandlers.get("members", payload.user.id); + const member = await cacheHandlers.get( + "members", + snowflakeToBigint(payload.user.id), + ); eventHandlers.guildBanAdd?.(guild, payload.user, member); } diff --git a/src/handlers/guilds/GUILD_BAN_REMOVE.ts b/src/handlers/guilds/GUILD_BAN_REMOVE.ts index 5c220588d..eb588bd2c 100644 --- a/src/handlers/guilds/GUILD_BAN_REMOVE.ts +++ b/src/handlers/guilds/GUILD_BAN_REMOVE.ts @@ -2,12 +2,19 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { GuildBanAddRemove } from "../../types/guilds/guild_ban_add_remove.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleGuildBanRemove(data: DiscordGatewayPayload) { const payload = data.d as GuildBanAddRemove; - const guild = await cacheHandlers.get("guilds", payload.guildId); + const guild = await cacheHandlers.get( + "guilds", + snowflakeToBigint(payload.guildId), + ); if (!guild) return; - const member = await cacheHandlers.get("members", payload.user.id); + const member = await cacheHandlers.get( + "members", + snowflakeToBigint(payload.user.id), + ); eventHandlers.guildBanRemove?.(guild, payload.user, member); } diff --git a/src/handlers/guilds/GUILD_CREATE.ts b/src/handlers/guilds/GUILD_CREATE.ts index d3fff22d1..a9cc05791 100644 --- a/src/handlers/guilds/GUILD_CREATE.ts +++ b/src/handlers/guilds/GUILD_CREATE.ts @@ -3,6 +3,7 @@ import { cache, cacheHandlers } from "../../cache.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { Guild } from "../../types/guilds/guild.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; import { ws } from "../../ws/ws.ts"; export async function handleGuildCreate( @@ -11,24 +12,24 @@ export async function handleGuildCreate( ) { const payload = data.d as Guild; // When shards resume they emit GUILD_CREATE again. - if (await cacheHandlers.has("guilds", payload.id)) return; + if (await cacheHandlers.has("guilds", snowflakeToBigint(payload.id))) return; - const discordenoGuild = await structures.createDiscordenoGuild( + const guild = await structures.createDiscordenoGuild( payload, shardId, ); - await cacheHandlers.set("guilds", discordenoGuild.id, discordenoGuild); + await cacheHandlers.set("guilds", guild.id, guild); const shard = ws.shards.get(shardId); - if (shard?.unavailableGuildIds.has(payload.id)) { - await cacheHandlers.delete("unavailableGuilds", payload.id); + if (shard?.unavailableGuildIds.has(guild.id)) { + await cacheHandlers.delete("unavailableGuilds", guild.id); - shard.unavailableGuildIds.delete(payload.id); + shard.unavailableGuildIds.delete(guild.id); - return eventHandlers.guildAvailable?.(discordenoGuild); + return eventHandlers.guildAvailable?.(guild); } - if (!cache.isReady) return eventHandlers.guildLoaded?.(discordenoGuild); - eventHandlers.guildCreate?.(discordenoGuild); + if (!cache.isReady) return eventHandlers.guildLoaded?.(guild); + eventHandlers.guildCreate?.(guild); } diff --git a/src/handlers/guilds/GUILD_DELETE.ts b/src/handlers/guilds/GUILD_DELETE.ts index bf1672a0d..5b32388e8 100644 --- a/src/handlers/guilds/GUILD_DELETE.ts +++ b/src/handlers/guilds/GUILD_DELETE.ts @@ -2,6 +2,7 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { UnavailableGuild } from "../../types/guilds/unavailable_guild.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; import { ws } from "../../ws/ws.ts"; export async function handleGuildDelete( @@ -10,16 +11,19 @@ export async function handleGuildDelete( ) { const payload = data.d as UnavailableGuild; - const guild = await cacheHandlers.get("guilds", payload.id); + const guild = await cacheHandlers.get( + "guilds", + snowflakeToBigint(payload.id), + ); if (!guild) return; - await cacheHandlers.delete("guilds", payload.id); + await cacheHandlers.delete("guilds", guild.id); if (payload.unavailable) { const shard = ws.shards.get(shardId); - if (shard) shard.unavailableGuildIds.add(payload.id); + if (shard) shard.unavailableGuildIds.add(guild.id); - await cacheHandlers.set("unavailableGuilds", payload.id, Date.now()); + await cacheHandlers.set("unavailableGuilds", guild.id, Date.now()); eventHandlers.guildUnavailable?.(guild); } else { @@ -31,7 +35,7 @@ export async function handleGuildDelete( "loop", `1. Running forEach messages loop in CHANNEL_DELTE file.`, ); - if (message.guildId === payload.id) { + if (message.guildId === guild.id) { cacheHandlers.delete("messages", message.id); } }); @@ -41,7 +45,7 @@ export async function handleGuildDelete( "loop", `2. Running forEach channels loop in CHANNEL_DELTE file.`, ); - if (channel.guildId === payload.id) { + if (channel.guildId === guild.id) { cacheHandlers.delete("channels", channel.id); } }); @@ -51,9 +55,9 @@ export async function handleGuildDelete( "loop", `3. Running forEach members loop in CHANNEL_DELTE file.`, ); - if (!member.guilds.has(payload.id)) return; + if (!member.guilds.has(guild.id)) return; - member.guilds.delete(payload.id); + member.guilds.delete(guild.id); if (!member.guilds.size) { return cacheHandlers.delete("members", member.id); diff --git a/src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts b/src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts index 7c28c6520..36b013ec6 100644 --- a/src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts +++ b/src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts @@ -2,13 +2,17 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { GuildIntegrationsUpdate } from "../../types/integration/guild_integrations_update.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleGuildIntegrationsUpdate( data: DiscordGatewayPayload, ) { const payload = data.d as GuildIntegrationsUpdate; - const guild = await cacheHandlers.get("guilds", payload.guildId); + const guild = await cacheHandlers.get( + "guilds", + snowflakeToBigint(payload.guildId), + ); if (!guild) return; eventHandlers.guildIntegrationsUpdate?.(guild); diff --git a/src/handlers/guilds/GUILD_UPDATE.ts b/src/handlers/guilds/GUILD_UPDATE.ts index 607c16e76..9504e9df0 100644 --- a/src/handlers/guilds/GUILD_UPDATE.ts +++ b/src/handlers/guilds/GUILD_UPDATE.ts @@ -3,13 +3,18 @@ import { cacheHandlers } from "../../cache.ts"; import { GuildUpdateChange } from "../../types/discordeno/guild_update_change.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { Guild } from "../../types/guilds/guild.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleGuildUpdate(data: DiscordGatewayPayload) { const payload = data.d as Guild; - const newGuild = await cacheHandlers.get("guilds", payload.id); + const newGuild = await cacheHandlers.get( + "guilds", + snowflakeToBigint(payload.id), + ); if (!newGuild) return; const keysToSkip = [ + "id", "roles", "guildHashes", "guildId", @@ -40,7 +45,7 @@ export async function handleGuildUpdate(data: DiscordGatewayPayload) { } }).filter((change) => change) as GuildUpdateChange[]; - await cacheHandlers.set("guilds", payload.id, newGuild); + await cacheHandlers.set("guilds", newGuild.id, newGuild); eventHandlers.guildUpdate?.(newGuild, changes); } diff --git a/src/handlers/interactions/INTERACTION_CREATE.ts b/src/handlers/interactions/INTERACTION_CREATE.ts index 618cc1bdb..026af104c 100644 --- a/src/handlers/interactions/INTERACTION_CREATE.ts +++ b/src/handlers/interactions/INTERACTION_CREATE.ts @@ -4,13 +4,14 @@ import { structures } from "../../structures/mod.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; import { Interaction } from "../../types/interactions/interaction.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleInteractionCreate(data: DiscordGatewayPayload) { const payload = data.d as Interaction; const discordenoMember = payload.guildId ? await structures.createDiscordenoMember( payload.member as GuildMemberWithUser, - payload.guildId, + snowflakeToBigint(payload.guildId), ) : undefined; if (discordenoMember) { diff --git a/src/handlers/members/GUILD_MEMBERS_CHUNK.ts b/src/handlers/members/GUILD_MEMBERS_CHUNK.ts index 1057b666e..f1b76e556 100644 --- a/src/handlers/members/GUILD_MEMBERS_CHUNK.ts +++ b/src/handlers/members/GUILD_MEMBERS_CHUNK.ts @@ -2,16 +2,19 @@ import { cache, cacheHandlers } from "../../cache.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { GuildMembersChunk } from "../../types/members/guild_members_chunk.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; import { Collection } from "../../util/collection.ts"; export async function handleGuildMembersChunk(data: DiscordGatewayPayload) { const payload = data.d as GuildMembersChunk; + const guildId = snowflakeToBigint(payload.guildId); + const members = await Promise.all( payload.members.map(async (member) => { const discordenoMember = await structures.createDiscordenoMember( member, - payload.guildId, + guildId, ); await cacheHandlers.set("members", discordenoMember.id, discordenoMember); @@ -36,7 +39,7 @@ export async function handleGuildMembersChunk(data: DiscordGatewayPayload) { return resolve( await cacheHandlers.filter( "members", - (m) => m.guilds.has(payload.guildId), + (m) => m.guilds.has(guildId), ), ); } diff --git a/src/handlers/members/GUILD_MEMBER_ADD.ts b/src/handlers/members/GUILD_MEMBER_ADD.ts index 722bce40e..7743d3d75 100644 --- a/src/handlers/members/GUILD_MEMBER_ADD.ts +++ b/src/handlers/members/GUILD_MEMBER_ADD.ts @@ -3,16 +3,20 @@ import { cacheHandlers } from "../../cache.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { GuildMemberAdd } from "../../types/members/guild_member_add.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleGuildMemberAdd(data: DiscordGatewayPayload) { const payload = data.d as GuildMemberAdd; - const guild = await cacheHandlers.get("guilds", payload.guildId); + const guild = await cacheHandlers.get( + "guilds", + snowflakeToBigint(payload.guildId), + ); if (!guild) return; guild.memberCount++; const discordenoMember = await structures.createDiscordenoMember( payload, - payload.guildId, + guild.id, ); await cacheHandlers.set("members", discordenoMember.id, discordenoMember); diff --git a/src/handlers/members/GUILD_MEMBER_REMOVE.ts b/src/handlers/members/GUILD_MEMBER_REMOVE.ts index cbf075a41..9a18461f0 100644 --- a/src/handlers/members/GUILD_MEMBER_REMOVE.ts +++ b/src/handlers/members/GUILD_MEMBER_REMOVE.ts @@ -2,14 +2,21 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { GuildMemberRemove } from "../../types/members/guild_member_remove.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleGuildMemberRemove(data: DiscordGatewayPayload) { const payload = data.d as GuildMemberRemove; - const guild = await cacheHandlers.get("guilds", payload.guildId); + const guild = await cacheHandlers.get( + "guilds", + snowflakeToBigint(payload.guildId), + ); if (!guild) return; guild.memberCount--; - const member = await cacheHandlers.get("members", payload.user.id); + const member = await cacheHandlers.get( + "members", + snowflakeToBigint(payload.user.id), + ); eventHandlers.guildMemberRemove?.(guild, payload.user, member); member?.guilds.delete(guild.id); diff --git a/src/handlers/members/GUILD_MEMBER_UPDATE.ts b/src/handlers/members/GUILD_MEMBER_UPDATE.ts index 6bcde3886..05c4f5a38 100644 --- a/src/handlers/members/GUILD_MEMBER_UPDATE.ts +++ b/src/handlers/members/GUILD_MEMBER_UPDATE.ts @@ -3,14 +3,21 @@ import { cacheHandlers } from "../../cache.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { GuildMemberUpdate } from "../../types/members/guild_member_update.ts"; +import { bigintToSnowflake, snowflakeToBigint } from "../../util/bigint.ts"; export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) { const payload = data.d as GuildMemberUpdate; - const guild = await cacheHandlers.get("guilds", payload.guildId); + const guild = await cacheHandlers.get( + "guilds", + snowflakeToBigint(payload.guildId), + ); if (!guild) return; - const cachedMember = await cacheHandlers.get("members", payload.user.id); - const guildMember = cachedMember?.guilds.get(payload.guildId); + const cachedMember = await cacheHandlers.get( + "members", + snowflakeToBigint(payload.user.id), + ); + const guildMember = cachedMember?.guilds.get(guild.id); const newMemberData = { ...payload, @@ -23,7 +30,7 @@ export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) { }; const discordenoMember = await structures.createDiscordenoMember( newMemberData, - payload.guildId, + guild.id, ); await cacheHandlers.set("members", discordenoMember.id, discordenoMember); @@ -48,7 +55,7 @@ export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) { "loop", `1. Running forEach loop in GUILD_MEMBER_UPDATE file.`, ); - if (!payload.roles.includes(id)) { + if (!payload.roles.includes(bigintToSnowflake(id))) { eventHandlers.roleLost?.(guild, discordenoMember, id); } }); @@ -58,8 +65,12 @@ export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) { "loop", `2. Running forEach loop in GUILD_MEMBER_UPDATE file.`, ); - if (!roleIds.includes(id)) { - eventHandlers.roleGained?.(guild, discordenoMember, id); + if (!roleIds.includes(snowflakeToBigint(id))) { + eventHandlers.roleGained?.( + guild, + discordenoMember, + snowflakeToBigint(id), + ); } }); } diff --git a/src/handlers/messages/MESSAGE_CREATE.ts b/src/handlers/messages/MESSAGE_CREATE.ts index 3a3c9080d..51d6856cc 100644 --- a/src/handlers/messages/MESSAGE_CREATE.ts +++ b/src/handlers/messages/MESSAGE_CREATE.ts @@ -4,14 +4,18 @@ import { structures } from "../../structures/mod.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; import { Message } from "../../types/messages/message.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleMessageCreate(data: DiscordGatewayPayload) { const payload = data.d as Message; - const channel = await cacheHandlers.get("channels", payload.channelId); - if (channel) channel.lastMessageId = payload.id; + const channel = await cacheHandlers.get( + "channels", + snowflakeToBigint(payload.channelId), + ); + if (channel) channel.lastMessageId = snowflakeToBigint(payload.id); const guild = payload.guildId - ? await cacheHandlers.get("guilds", payload.guildId) + ? await cacheHandlers.get("guilds", snowflakeToBigint(payload.guildId)) : undefined; if (payload.member && guild) { @@ -34,7 +38,7 @@ export async function handleMessageCreate(data: DiscordGatewayPayload) { return cacheHandlers.set( "members", - mention.id, + snowflakeToBigint(mention.id), discordenoMember, ); } @@ -45,7 +49,7 @@ export async function handleMessageCreate(data: DiscordGatewayPayload) { data.d as Message, ); // Cache the message - await cacheHandlers.set("messages", payload.id, message); + await cacheHandlers.set("messages", snowflakeToBigint(payload.id), message); eventHandlers.messageCreate?.(message); } diff --git a/src/handlers/messages/MESSAGE_DELETE.ts b/src/handlers/messages/MESSAGE_DELETE.ts index f8bdc5e40..078d6cfb2 100644 --- a/src/handlers/messages/MESSAGE_DELETE.ts +++ b/src/handlers/messages/MESSAGE_DELETE.ts @@ -2,16 +2,20 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { MessageDelete } from "../../types/messages/message_delete.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleMessageDelete(data: DiscordGatewayPayload) { const payload = data.d as MessageDelete; - const channel = await cacheHandlers.get("channels", payload.channelId); + const channel = await cacheHandlers.get( + "channels", + snowflakeToBigint(payload.channelId), + ); if (!channel) return; eventHandlers.messageDelete?.( { id: payload.id, channel }, - await cacheHandlers.get("messages", payload.id), + await cacheHandlers.get("messages", snowflakeToBigint(payload.id)), ); - await cacheHandlers.delete("messages", payload.id); + await cacheHandlers.delete("messages", snowflakeToBigint(payload.id)); } diff --git a/src/handlers/messages/MESSAGE_DELETE_BULK.ts b/src/handlers/messages/MESSAGE_DELETE_BULK.ts index 058932208..f5b5ad680 100644 --- a/src/handlers/messages/MESSAGE_DELETE_BULK.ts +++ b/src/handlers/messages/MESSAGE_DELETE_BULK.ts @@ -2,17 +2,21 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { MessageDeleteBulk } from "../../types/messages/message_delete_bulk.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleMessageDeleteBulk(data: DiscordGatewayPayload) { const payload = data.d as MessageDeleteBulk; - const channel = await cacheHandlers.get("channels", payload.channelId); + const channel = await cacheHandlers.get( + "channels", + snowflakeToBigint(payload.channelId), + ); if (!channel) return; return Promise.all(payload.ids.map(async (id) => { eventHandlers.messageDelete?.( { id, channel }, - await cacheHandlers.get("messages", id), + await cacheHandlers.get("messages", snowflakeToBigint(id)), ); - await cacheHandlers.delete("messages", id); + await cacheHandlers.delete("messages", snowflakeToBigint(id)); })); } diff --git a/src/handlers/messages/MESSAGE_REACTION_ADD.ts b/src/handlers/messages/MESSAGE_REACTION_ADD.ts index 9ba917f7c..ec6871a73 100644 --- a/src/handlers/messages/MESSAGE_REACTION_ADD.ts +++ b/src/handlers/messages/MESSAGE_REACTION_ADD.ts @@ -5,11 +5,15 @@ import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { MessageReactionAdd, } from "../../types/messages/message_reaction_add.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; import { snakeKeysToCamelCase } from "../../util/utils.ts"; export async function handleMessageReactionAdd(data: DiscordGatewayPayload) { const payload = data.d as MessageReactionAdd; - const message = await cacheHandlers.get("messages", payload.messageId); + const message = await cacheHandlers.get( + "messages", + snowflakeToBigint(payload.messageId), + ); if (message) { const reactionExisted = message.reactions?.find( @@ -22,7 +26,7 @@ export async function handleMessageReactionAdd(data: DiscordGatewayPayload) { else { const newReaction = { count: 1, - me: payload.userId === botId, + me: snowflakeToBigint(payload.userId) === botId, emoji: { ...payload.emoji, id: payload.emoji.id || undefined }, }; message.reactions = message.reactions @@ -30,11 +34,18 @@ export async function handleMessageReactionAdd(data: DiscordGatewayPayload) { : [newReaction]; } - await cacheHandlers.set("messages", payload.messageId, message); + await cacheHandlers.set( + "messages", + snowflakeToBigint(payload.messageId), + message, + ); } if (payload.member && payload.guildId) { - const guild = await cacheHandlers.get("guilds", payload.guildId); + const guild = await cacheHandlers.get( + "guilds", + snowflakeToBigint(payload.guildId), + ); if (guild) { const discordenoMember = await structures.createDiscordenoMember( payload.member, diff --git a/src/handlers/messages/MESSAGE_REACTION_REMOVE.ts b/src/handlers/messages/MESSAGE_REACTION_REMOVE.ts index 9d947f8e3..652baa592 100644 --- a/src/handlers/messages/MESSAGE_REACTION_REMOVE.ts +++ b/src/handlers/messages/MESSAGE_REACTION_REMOVE.ts @@ -4,12 +4,16 @@ import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { MessageReactionRemove, } from "../../types/messages/message_reaction_remove.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleMessageReactionRemove( data: DiscordGatewayPayload, ) { const payload = data.d as MessageReactionRemove; - const message = await cacheHandlers.get("messages", payload.messageId); + const message = await cacheHandlers.get( + "messages", + snowflakeToBigint(payload.messageId), + ); if (message) { const reaction = message.reactions?.find((reaction) => @@ -25,7 +29,7 @@ export async function handleMessageReactionRemove( } if (!message.reactions?.length) message.reactions = undefined; - await cacheHandlers.set("messages", payload.messageId, message); + await cacheHandlers.set("messages", message.id, message); } } diff --git a/src/handlers/messages/MESSAGE_REACTION_REMOVE_ALL.ts b/src/handlers/messages/MESSAGE_REACTION_REMOVE_ALL.ts index 328f7c369..0cb0088ed 100644 --- a/src/handlers/messages/MESSAGE_REACTION_REMOVE_ALL.ts +++ b/src/handlers/messages/MESSAGE_REACTION_REMOVE_ALL.ts @@ -4,17 +4,25 @@ import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { MessageReactionRemoveAll, } from "../../types/messages/message_reaction_remove_all.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleMessageReactionRemoveAll( data: DiscordGatewayPayload, ) { const payload = data.d as MessageReactionRemoveAll; - const message = await cacheHandlers.get("messages", payload.messageId); + const message = await cacheHandlers.get( + "messages", + snowflakeToBigint(payload.messageId), + ); if (message?.reactions) { message.reactions = undefined; - await cacheHandlers.set("messages", payload.messageId, message); + await cacheHandlers.set( + "messages", + snowflakeToBigint(payload.messageId), + message, + ); } eventHandlers.reactionRemoveAll?.( diff --git a/src/handlers/messages/MESSAGE_REACTION_REMOVE_EMOJI.ts b/src/handlers/messages/MESSAGE_REACTION_REMOVE_EMOJI.ts index 34e42b0ca..43ca252ef 100644 --- a/src/handlers/messages/MESSAGE_REACTION_REMOVE_EMOJI.ts +++ b/src/handlers/messages/MESSAGE_REACTION_REMOVE_EMOJI.ts @@ -2,12 +2,16 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { MessageReactionRemoveEmoji } from "../../types/messages/message_reaction_remove_emoji.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleMessageReactionRemoveEmoji( data: DiscordGatewayPayload, ) { const payload = data.d as MessageReactionRemoveEmoji; - const message = await cacheHandlers.get("messages", payload.messageId); + const message = await cacheHandlers.get( + "messages", + snowflakeToBigint(payload.messageId), + ); if (message?.reactions) { message.reactions = message.reactions.filter( @@ -21,13 +25,13 @@ export async function handleMessageReactionRemoveEmoji( if (!message.reactions.length) message.reactions = undefined; - await cacheHandlers.set("messages", payload.messageId, message); + await cacheHandlers.set("messages", message.id, message); } eventHandlers.reactionRemoveEmoji?.( payload.emoji, - payload.messageId, - payload.channelId, - payload.guildId, + snowflakeToBigint(payload.messageId), + snowflakeToBigint(payload.channelId), + payload.guildId ? snowflakeToBigint(payload.guildId) : undefined, ); } diff --git a/src/handlers/messages/MESSAGE_UPDATE.ts b/src/handlers/messages/MESSAGE_UPDATE.ts index 390746e04..648aeec06 100644 --- a/src/handlers/messages/MESSAGE_UPDATE.ts +++ b/src/handlers/messages/MESSAGE_UPDATE.ts @@ -3,13 +3,20 @@ import { cacheHandlers } from "../../cache.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { Message } from "../../types/messages/message.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleMessageUpdate(data: DiscordGatewayPayload) { const payload = data.d as Message; - const channel = await cacheHandlers.get("channels", payload.channelId); + const channel = await cacheHandlers.get( + "channels", + snowflakeToBigint(payload.channelId), + ); if (!channel) return; - const oldMessage = await cacheHandlers.get("messages", payload.id); + const oldMessage = await cacheHandlers.get( + "messages", + snowflakeToBigint(payload.id), + ); if (!oldMessage) return; // Messages with embeds can trigger update but they wont have edited_timestamp @@ -22,7 +29,7 @@ export async function handleMessageUpdate(data: DiscordGatewayPayload) { const message = await structures.createDiscordenoMessage(payload); - await cacheHandlers.set("messages", payload.id, message); + await cacheHandlers.set("messages", snowflakeToBigint(payload.id), message); eventHandlers.messageUpdate?.(message, oldMessage); } diff --git a/src/handlers/misc/PRESENCE_UPDATE.ts b/src/handlers/misc/PRESENCE_UPDATE.ts index 1e8d94657..c770dc8b4 100644 --- a/src/handlers/misc/PRESENCE_UPDATE.ts +++ b/src/handlers/misc/PRESENCE_UPDATE.ts @@ -2,12 +2,20 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { PresenceUpdate } from "../../types/misc/presence_update.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handlePresenceUpdate(data: DiscordGatewayPayload) { const payload = data.d as PresenceUpdate; - const oldPresence = await cacheHandlers.get("presences", payload.user.id); - await cacheHandlers.set("presences", payload.user.id, payload); + const oldPresence = await cacheHandlers.get( + "presences", + snowflakeToBigint(payload.user.id), + ); + await cacheHandlers.set( + "presences", + snowflakeToBigint(payload.user.id), + payload, + ); eventHandlers.presenceUpdate?.(payload, oldPresence); } diff --git a/src/handlers/misc/READY.ts b/src/handlers/misc/READY.ts index 204ed07f2..782e88f29 100644 --- a/src/handlers/misc/READY.ts +++ b/src/handlers/misc/READY.ts @@ -5,6 +5,7 @@ import { structures } from "../../structures/mod.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { Ready } from "../../types/gateway/ready.ts"; import { GuildMemberWithUser } from "../../types/mod.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; import { ws } from "../../ws/ws.ts"; export function handleReady( @@ -29,7 +30,9 @@ export function handleReady( // Set ready to false just to go sure shard.ready = false; // All guilds are unavailable at first - shard.unavailableGuildIds = new Set(payload.guilds.map((g) => g.id)); + shard.unavailableGuildIds = new Set( + payload.guilds.map((g) => snowflakeToBigint(g.id)), + ); // Start ready check in 2 seconds setTimeout(async () => { diff --git a/src/handlers/misc/USER_UPDATE.ts b/src/handlers/misc/USER_UPDATE.ts index 5ed05a74b..02297cce9 100644 --- a/src/handlers/misc/USER_UPDATE.ts +++ b/src/handlers/misc/USER_UPDATE.ts @@ -2,11 +2,15 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { User } from "../../types/users/user.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleUserUpdate(data: DiscordGatewayPayload) { const userData = data.d as User; - const member = await cacheHandlers.get("members", userData.id); + const member = await cacheHandlers.get( + "members", + snowflakeToBigint(userData.id), + ); if (!member) return; Object.entries(userData).forEach(([key, value]) => { @@ -18,7 +22,7 @@ export async function handleUserUpdate(data: DiscordGatewayPayload) { if (member[key] !== value) return member[key] = value; }); - await cacheHandlers.set("members", userData.id, member); + await cacheHandlers.set("members", snowflakeToBigint(userData.id), member); eventHandlers.botUpdate?.(userData); } diff --git a/src/handlers/roles/GUILD_ROLE_CREATE.ts b/src/handlers/roles/GUILD_ROLE_CREATE.ts index 8798e530f..acdc40c0b 100644 --- a/src/handlers/roles/GUILD_ROLE_CREATE.ts +++ b/src/handlers/roles/GUILD_ROLE_CREATE.ts @@ -3,15 +3,22 @@ import { cacheHandlers } from "../../cache.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { GuildRoleCreate } from "../../types/mod.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleGuildRoleCreate(data: DiscordGatewayPayload) { const payload = data.d as GuildRoleCreate; - const guild = await cacheHandlers.get("guilds", payload.guildId); + const guild = await cacheHandlers.get( + "guilds", + snowflakeToBigint(payload.guildId), + ); if (!guild) return; - const role = await structures.createDiscordenoRole(payload); - guild.roles = guild.roles.set(payload.role.id, role); - await cacheHandlers.set("guilds", payload.guildId, guild); + const role = await structures.createDiscordenoRole({ + ...payload, + guildId: guild.id, + }); + guild.roles = guild.roles.set(snowflakeToBigint(payload.role.id), role); + await cacheHandlers.set("guilds", guild.id, guild); eventHandlers.roleCreate?.(guild, role); } diff --git a/src/handlers/roles/GUILD_ROLE_DELETE.ts b/src/handlers/roles/GUILD_ROLE_DELETE.ts index ade6eff2a..8fd35f5e1 100644 --- a/src/handlers/roles/GUILD_ROLE_DELETE.ts +++ b/src/handlers/roles/GUILD_ROLE_DELETE.ts @@ -2,14 +2,20 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { GuildRoleDelete } from "../../types/guilds/guild_role_delete.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleGuildRoleDelete(data: DiscordGatewayPayload) { const payload = data.d as GuildRoleDelete; - const guild = await cacheHandlers.get("guilds", payload.guildId); + const guild = await cacheHandlers.get( + "guilds", + snowflakeToBigint(payload.guildId), + ); if (!guild) return; - const cachedRole = guild.roles.get(payload.roleId)!; - guild.roles.delete(payload.roleId); + const roleId = snowflakeToBigint(payload.roleId); + + const cachedRole = guild.roles.get(roleId)!; + guild.roles.delete(roleId); if (cachedRole) eventHandlers.roleDelete?.(guild, cachedRole); @@ -28,9 +34,9 @@ export async function handleGuildRoleDelete(data: DiscordGatewayPayload) { `2. Running forEach loop in CHANNEL_DELTE file.`, ); // Member does not have this role - if (!g.roles.includes(payload.roleId)) return; + if (!g.roles.includes(roleId)) return; // Remove this role from the members cache - g.roles = g.roles.filter((id) => id !== payload.roleId); + g.roles = g.roles.filter((id) => id !== roleId); cacheHandlers.set("members", member.id, member); }); }); diff --git a/src/handlers/roles/GUILD_ROLE_UPDATE.ts b/src/handlers/roles/GUILD_ROLE_UPDATE.ts index 2ad390925..ae9c6e6d1 100644 --- a/src/handlers/roles/GUILD_ROLE_UPDATE.ts +++ b/src/handlers/roles/GUILD_ROLE_UPDATE.ts @@ -3,17 +3,24 @@ import { cacheHandlers } from "../../cache.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { GuildRoleUpdate } from "../../types/mod.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleGuildRoleUpdate(data: DiscordGatewayPayload) { const payload = data.d as GuildRoleUpdate; - const guild = await cacheHandlers.get("guilds", payload.guildId); + const guild = await cacheHandlers.get( + "guilds", + snowflakeToBigint(payload.guildId), + ); if (!guild) return; - const cachedRole = guild.roles.get(payload.role.id); + const cachedRole = guild.roles.get(snowflakeToBigint(payload.role.id)); if (!cachedRole) return; - const role = await structures.createDiscordenoRole(payload); - guild.roles.set(payload.role.id, role); + const role = await structures.createDiscordenoRole({ + ...payload, + guildId: guild.id, + }); + guild.roles.set(snowflakeToBigint(payload.role.id), role); await cacheHandlers.set("guilds", guild.id, guild); eventHandlers.roleUpdate?.(guild, role, cachedRole); diff --git a/src/handlers/voice/VOICE_SERVER_UPDATE.ts b/src/handlers/voice/VOICE_SERVER_UPDATE.ts index 9edb0052d..3f6128a52 100644 --- a/src/handlers/voice/VOICE_SERVER_UPDATE.ts +++ b/src/handlers/voice/VOICE_SERVER_UPDATE.ts @@ -2,11 +2,15 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { VoiceServerUpdate } from "../../types/voice/voice_server_update.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleVoiceServerUpdate(data: DiscordGatewayPayload) { const payload = data.d as VoiceServerUpdate; - const guild = await cacheHandlers.get("guilds", payload.guildId); + const guild = await cacheHandlers.get( + "guilds", + snowflakeToBigint(payload.guildId), + ); if (!guild) return; eventHandlers.voiceServerUpdate?.(payload, guild); diff --git a/src/handlers/voice/VOICE_STATE_UPDATE.ts b/src/handlers/voice/VOICE_STATE_UPDATE.ts index 127d9619f..e358eb3b6 100644 --- a/src/handlers/voice/VOICE_STATE_UPDATE.ts +++ b/src/handlers/voice/VOICE_STATE_UPDATE.ts @@ -3,13 +3,16 @@ import { cacheHandlers } from "../../cache.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { VoiceState } from "../../types/voice/voice_state.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleVoiceStateUpdate(data: DiscordGatewayPayload) { const payload = data.d as VoiceState; - if (!payload.guildId) return; - const guild = await cacheHandlers.get("guilds", payload.guildId); + const guild = await cacheHandlers.get( + "guilds", + snowflakeToBigint(payload.guildId), + ); if (!guild) return; const member = payload.member @@ -17,34 +20,40 @@ export async function handleVoiceStateUpdate(data: DiscordGatewayPayload) { payload.member, guild.id, ) - : await cacheHandlers.get("members", payload.userId); + : await cacheHandlers.get("members", snowflakeToBigint(payload.userId)); if (!member) return; // No cached state before so lets make one for em - const cachedState = guild.voiceStates.get(payload.userId); + const cachedState = guild.voiceStates.get(snowflakeToBigint(payload.userId)); guild.voiceStates.set( - payload.userId, - payload, + snowflakeToBigint(payload.userId), + await structures.createDiscordenoVoiceState(guild.id, payload), ); - await cacheHandlers.set("guilds", payload.guildId, guild); + await cacheHandlers.set("guilds", guild.id, guild); - if (cachedState?.channelId !== payload.channelId) { + if ( + cachedState?.channelId !== + (payload.channelId ? snowflakeToBigint(payload.channelId) : null) + ) { // Either joined or moved channels if (payload.channelId) { if (cachedState?.channelId) { // Was in a channel before eventHandlers.voiceChannelSwitch?.( member, - payload.channelId, + snowflakeToBigint(payload.channelId), cachedState.channelId, ); } else { // Was not in a channel before so user just joined - eventHandlers.voiceChannelJoin?.(member, payload.channelId); + eventHandlers.voiceChannelJoin?.( + member, + snowflakeToBigint(payload.channelId), + ); } } // Left the channel else if (cachedState?.channelId) { - guild.voiceStates.delete(payload.userId); + guild.voiceStates.delete(snowflakeToBigint(payload.userId)); eventHandlers.voiceChannelLeave?.(member, cachedState.channelId); } } diff --git a/src/handlers/webhooks/WEBHOOKS_UPDATE.ts b/src/handlers/webhooks/WEBHOOKS_UPDATE.ts index fef9ac28c..110a6761d 100644 --- a/src/handlers/webhooks/WEBHOOKS_UPDATE.ts +++ b/src/handlers/webhooks/WEBHOOKS_UPDATE.ts @@ -1,11 +1,12 @@ import { eventHandlers } from "../../bot.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { WebhookUpdate } from "../../types/webhooks/webhooks_update.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; export function handleWebhooksUpdate(data: DiscordGatewayPayload) { const options = data.d as WebhookUpdate; eventHandlers.webhooksUpdate?.( - options.channelId, - options.guildId, + snowflakeToBigint(options.channelId), + snowflakeToBigint(options.guildId), ); } diff --git a/src/helpers/channels/category_children.ts b/src/helpers/channels/category_children.ts index 4b1a83b84..4ca9a74f8 100644 --- a/src/helpers/channels/category_children.ts +++ b/src/helpers/channels/category_children.ts @@ -1,7 +1,7 @@ import { cacheHandlers } from "../../cache.ts"; /** Gets an array of all the channels ids that are the children of this category. */ -export function categoryChildren(id: string) { +export function categoryChildren(id: bigint) { return cacheHandlers.filter( "channels", (channel) => channel.parentId === id, diff --git a/src/helpers/channels/channel_overwrite_has_permission.ts b/src/helpers/channels/channel_overwrite_has_permission.ts index cbf4cb650..bcf6b3407 100644 --- a/src/helpers/channels/channel_overwrite_has_permission.ts +++ b/src/helpers/channels/channel_overwrite_has_permission.ts @@ -4,9 +4,13 @@ import { PermissionStrings } from "../../types/permissions/permission_strings.ts /** Checks if a channel overwrite for a user id or a role id has permission in this channel */ export function channelOverwriteHasPermission( - guildId: string, - id: string, - overwrites: DiscordOverwrite[], + guildId: bigint, + id: bigint, + overwrites: (Omit & { + id: bigint; + allow: bigint; + deny: bigint; + })[], permissions: PermissionStrings[], ) { const overwrite = overwrites.find((perm) => perm.id === id) || diff --git a/src/helpers/channels/clone_channel.ts b/src/helpers/channels/clone_channel.ts index e84e039e0..200189a32 100644 --- a/src/helpers/channels/clone_channel.ts +++ b/src/helpers/channels/clone_channel.ts @@ -2,11 +2,12 @@ import { cacheHandlers } from "../../cache.ts"; import { DiscordChannelTypes } from "../../types/channels/channel_types.ts"; import { CreateGuildChannel } from "../../types/guilds/create_guild_channel.ts"; import { Errors } from "../../types/misc/errors.ts"; +import { bigintToSnowflake } from "../../util/bigint.ts"; import { calculatePermissions } from "../../util/permissions.ts"; import { createChannel } from "./create_channel.ts"; /** Create a copy of a channel */ -export async function cloneChannel(channelId: string, reason?: string) { +export async function cloneChannel(channelId: bigint, reason?: string) { const channelToClone = await cacheHandlers.get("channels", channelId); //Return undefined if channel is not cached if (!channelToClone) throw new Error(Errors.CHANNEL_NOT_FOUND); @@ -23,14 +24,16 @@ export async function cloneChannel(channelId: string, reason?: string) { ...channelToClone, name: channelToClone.name!, topic: channelToClone.topic || undefined, - parentId: channelToClone.parentId || undefined, + parentId: channelToClone.parentId + ? bigintToSnowflake(channelToClone.parentId) + : undefined, permissionOverwrites: channelToClone.permissionOverwrites.map(( overwrite, ) => ({ - id: overwrite.id, + id: overwrite.id.toString(), type: overwrite.type, - allow: calculatePermissions(overwrite.allow), - deny: calculatePermissions(overwrite.deny), + allow: calculatePermissions(overwrite.allow.toString()), + deny: calculatePermissions(overwrite.deny.toString()), })), }; diff --git a/src/helpers/channels/create_channel.ts b/src/helpers/channels/create_channel.ts index 9d675ed60..316362399 100644 --- a/src/helpers/channels/create_channel.ts +++ b/src/helpers/channels/create_channel.ts @@ -18,7 +18,7 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts"; /** Create a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */ export async function createChannel( - guildId: string, + guildId: bigint, options?: CreateGuildChannel, reason?: string, ) { diff --git a/src/helpers/channels/delete_channel.ts b/src/helpers/channels/delete_channel.ts index d934c8944..b8588c7b0 100644 --- a/src/helpers/channels/delete_channel.ts +++ b/src/helpers/channels/delete_channel.ts @@ -6,8 +6,8 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; /** Delete a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */ export async function deleteChannel( - guildId: string, - channelId: string, + guildId: bigint, + channelId: bigint, reason?: string, ): Promise { await requireBotGuildPermissions(guildId, ["MANAGE_CHANNELS"]); diff --git a/src/helpers/channels/delete_channel_overwrite.ts b/src/helpers/channels/delete_channel_overwrite.ts index ea92593cb..3eecfb7fa 100644 --- a/src/helpers/channels/delete_channel_overwrite.ts +++ b/src/helpers/channels/delete_channel_overwrite.ts @@ -4,9 +4,9 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; /** Delete the channel permission overwrites for a user or role in this channel. Requires `MANAGE_ROLES` permission. */ export async function deleteChannelOverwrite( - guildId: string, - channelId: string, - overwriteId: string, + guildId: bigint, + channelId: bigint, + overwriteId: bigint, ): Promise { await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); diff --git a/src/helpers/channels/edit_channel.ts b/src/helpers/channels/edit_channel.ts index dfb064c7d..26a40fdfa 100644 --- a/src/helpers/channels/edit_channel.ts +++ b/src/helpers/channels/edit_channel.ts @@ -10,7 +10,7 @@ import { /** Update a channel's settings. Requires the `MANAGE_CHANNELS` permission for the guild. */ export async function editChannel( - channelId: string, + channelId: bigint, options: ModifyChannel, reason?: string, ) { @@ -72,14 +72,14 @@ export async function editChannel( interface EditChannelRequest { amount: number; timestamp: number; - channelId: string; + channelId: bigint; items: { - channelId: string; + channelId: bigint; options: ModifyChannel; }[]; } -const editChannelNameTopicQueue = new Map(); +const editChannelNameTopicQueue = new Map(); let editChannelProcessing = false; function processEditChannelQueue() { diff --git a/src/helpers/channels/edit_channel_overwrite.ts b/src/helpers/channels/edit_channel_overwrite.ts index 17f271528..056cd6fc4 100644 --- a/src/helpers/channels/edit_channel_overwrite.ts +++ b/src/helpers/channels/edit_channel_overwrite.ts @@ -8,9 +8,9 @@ import { /** Edit the channel permission overwrites for a user or role in this channel. Requires `MANAGE_ROLES` permission. */ export async function editChannelOverwrite( - guildId: string, - channelId: string, - overwriteId: string, + guildId: bigint, + channelId: bigint, + overwriteId: bigint, options: Omit, ): Promise { await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); diff --git a/src/helpers/channels/follow_channel.ts b/src/helpers/channels/follow_channel.ts index 550bf9d0f..6ef4ed0e7 100644 --- a/src/helpers/channels/follow_channel.ts +++ b/src/helpers/channels/follow_channel.ts @@ -5,8 +5,8 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts"; /** Follow a News Channel to send messages to a target channel. Requires the `MANAGE_WEBHOOKS` permission in the target channel. Returns the webhook id. */ export async function followChannel( - sourceChannelId: string, - targetChannelId: string, + sourceChannelId: bigint, + targetChannelId: bigint, ) { await requireBotChannelPermissions(targetChannelId, ["MANAGE_WEBHOOKS"]); diff --git a/src/helpers/channels/get_channel.ts b/src/helpers/channels/get_channel.ts index 9c27334aa..122f075c8 100644 --- a/src/helpers/channels/get_channel.ts +++ b/src/helpers/channels/get_channel.ts @@ -2,13 +2,14 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { Channel } from "../../types/channels/channel.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; import { endpoints } from "../../util/constants.ts"; /** Fetches a single channel object from the api. * * ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your channels will be cached in your guild.** */ -export async function getChannel(channelId: string, addToCache = true) { +export async function getChannel(channelId: bigint, addToCache = true) { const result = await rest.runMethod( "get", endpoints.CHANNEL_BASE(channelId), @@ -16,7 +17,7 @@ export async function getChannel(channelId: string, addToCache = true) { const discordenoChannel = await structures.createDiscordenoChannel( result, - result.guildId, + result.guildId ? snowflakeToBigint(result.guildId) : undefined, ); if (addToCache) { await cacheHandlers.set( diff --git a/src/helpers/channels/get_channel_webhooks.ts b/src/helpers/channels/get_channel_webhooks.ts index 69fcc7825..d3752ff97 100644 --- a/src/helpers/channels/get_channel_webhooks.ts +++ b/src/helpers/channels/get_channel_webhooks.ts @@ -5,7 +5,7 @@ import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; /** Gets the webhooks for this channel. Requires MANAGE_WEBHOOKS */ -export async function getChannelWebhooks(channelId: string) { +export async function getChannelWebhooks(channelId: bigint) { await requireBotChannelPermissions(channelId, ["MANAGE_WEBHOOKS"]); const result = await rest.runMethod( diff --git a/src/helpers/channels/get_channels.ts b/src/helpers/channels/get_channels.ts index c0271fb41..681601cd1 100644 --- a/src/helpers/channels/get_channels.ts +++ b/src/helpers/channels/get_channels.ts @@ -9,7 +9,7 @@ import { endpoints } from "../../util/constants.ts"; * * ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your channels will be cached in your guild.** */ -export async function getChannels(guildId: string, addToCache = true) { +export async function getChannels(guildId: bigint, addToCache = true) { const result = await rest.runMethod( "get", endpoints.GUILD_CHANNELS(guildId), diff --git a/src/helpers/channels/get_pins.ts b/src/helpers/channels/get_pins.ts index 18b878b03..dd4d26954 100644 --- a/src/helpers/channels/get_pins.ts +++ b/src/helpers/channels/get_pins.ts @@ -4,7 +4,7 @@ import { Message } from "../../types/messages/message.ts"; import { endpoints } from "../../util/constants.ts"; /** Get pinned messages in this channel. */ -export async function getPins(channelId: string) { +export async function getPins(channelId: bigint) { const result = await rest.runMethod( "get", endpoints.CHANNEL_PINS(channelId), diff --git a/src/helpers/channels/is_channel_synced.ts b/src/helpers/channels/is_channel_synced.ts index 4f2dd0e0a..ea55aeaa4 100644 --- a/src/helpers/channels/is_channel_synced.ts +++ b/src/helpers/channels/is_channel_synced.ts @@ -1,7 +1,7 @@ import { cacheHandlers } from "../../cache.ts"; /** Checks whether a channel is synchronized with its parent/category channel or not. */ -export async function isChannelSynced(channelId: string) { +export async function isChannelSynced(channelId: bigint) { const channel = await cacheHandlers.get("channels", channelId); if (!channel?.parentId) return false; diff --git a/src/helpers/channels/start_typing.ts b/src/helpers/channels/start_typing.ts index 013ad46e2..91ef100f9 100644 --- a/src/helpers/channels/start_typing.ts +++ b/src/helpers/channels/start_typing.ts @@ -10,7 +10,7 @@ import { botHasChannelPermissions } from "../../util/permissions.ts"; * However, if a bot is responding to a command and expects the computation to take a few seconds, * this endpoint may be called to let the user know that the bot is processing their message. */ -export async function startTyping(channelId: string) { +export async function startTyping(channelId: bigint) { const channel = await cacheHandlers.get("channels", channelId); // If the channel is cached, we can do extra checks/safety if (channel) { diff --git a/src/helpers/channels/swap_channels.ts b/src/helpers/channels/swap_channels.ts index c55b903d3..21dddd139 100644 --- a/src/helpers/channels/swap_channels.ts +++ b/src/helpers/channels/swap_channels.ts @@ -4,7 +4,7 @@ import { endpoints } from "../../util/constants.ts"; /** Modify the positions of channels on the guild. Requires MANAGE_CHANNELS permisison. */ export async function swapChannels( - guildId: string, + guildId: bigint, channelPositions: ModifyGuildChannelPositions[], ) { if (channelPositions.length < 2) { diff --git a/src/helpers/commands/batch_edit_slash_command_permissions.ts b/src/helpers/commands/batch_edit_slash_command_permissions.ts index 514b546b7..139ee5981 100644 --- a/src/helpers/commands/batch_edit_slash_command_permissions.ts +++ b/src/helpers/commands/batch_edit_slash_command_permissions.ts @@ -6,7 +6,7 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts"; /** Batch edits permissions for all commands in a guild. Takes an array of partial GuildApplicationCommandPermissions objects including `id` and `permissions`. */ export async function batchEditSlashCommandPermissions( - guildId: string, + guildId: bigint, options: { id: string; permissions: ApplicationCommandPermissions[] }[], ) { return await rest.runMethod( diff --git a/src/helpers/commands/create_slash_command.ts b/src/helpers/commands/create_slash_command.ts index c756570e5..9a6f1f36d 100644 --- a/src/helpers/commands/create_slash_command.ts +++ b/src/helpers/commands/create_slash_command.ts @@ -21,7 +21,7 @@ import { */ export async function createSlashCommand( options: CreateGlobalApplicationCommand, - guildId?: string, + guildId?: bigint, ) { validateSlashCommands([options], true); diff --git a/src/helpers/commands/delete_slash_command.ts b/src/helpers/commands/delete_slash_command.ts index 9f4c889d7..0468ad3e5 100644 --- a/src/helpers/commands/delete_slash_command.ts +++ b/src/helpers/commands/delete_slash_command.ts @@ -4,8 +4,8 @@ import { endpoints } from "../../util/constants.ts"; /** Deletes a slash command. */ export async function deleteSlashCommand( - id: string, - guildId?: string, + id: bigint, + guildId?: bigint, ) { return await rest.runMethod( "delete", diff --git a/src/helpers/commands/delete_slash_response.ts b/src/helpers/commands/delete_slash_response.ts index c0972f1cf..7e6d7d991 100644 --- a/src/helpers/commands/delete_slash_response.ts +++ b/src/helpers/commands/delete_slash_response.ts @@ -5,7 +5,7 @@ import { endpoints } from "../../util/constants.ts"; /** To delete your response to a slash command. If a message id is not provided, it will default to deleting the original response. */ export async function deleteSlashResponse( token: string, - messageId?: string, + messageId?: bigint, ) { return await rest.runMethod( "delete", diff --git a/src/helpers/commands/edit_slash_command_permissions.ts b/src/helpers/commands/edit_slash_command_permissions.ts index 1ea764d8a..743780b45 100644 --- a/src/helpers/commands/edit_slash_command_permissions.ts +++ b/src/helpers/commands/edit_slash_command_permissions.ts @@ -6,8 +6,8 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts"; /** Edits command permissions for a specific command for your application in a guild. */ export async function editSlashCommandPermissions( - guildId: string, - commandId: string, + guildId: bigint, + commandId: bigint, options: ApplicationCommandPermissions[], ) { return await rest.runMethod( diff --git a/src/helpers/commands/get_slash_command.ts b/src/helpers/commands/get_slash_command.ts index d207c577b..2c0f9be01 100644 --- a/src/helpers/commands/get_slash_command.ts +++ b/src/helpers/commands/get_slash_command.ts @@ -4,7 +4,7 @@ import { ApplicationCommand } from "../../types/interactions/application_command import { endpoints } from "../../util/constants.ts"; /** Fetchs the global command for the given Id. If a guildId is provided, the guild command will be fetched. */ -export async function getSlashCommand(commandId: string, guildId?: string) { +export async function getSlashCommand(commandId: bigint, guildId?: bigint) { return await rest.runMethod( "get", guildId diff --git a/src/helpers/commands/get_slash_command_permission.ts b/src/helpers/commands/get_slash_command_permission.ts index f34362b9f..ead639b36 100644 --- a/src/helpers/commands/get_slash_command_permission.ts +++ b/src/helpers/commands/get_slash_command_permission.ts @@ -5,8 +5,8 @@ import { endpoints } from "../../util/constants.ts"; /** Fetches command permissions for a specific command for your application in a guild. Returns a GuildApplicationCommandPermissions object. */ export async function getSlashCommandPermission( - guildId: string, - commandId: string, + guildId: bigint, + commandId: bigint, ) { return await rest.runMethod( "get", diff --git a/src/helpers/commands/get_slash_command_permissions.ts b/src/helpers/commands/get_slash_command_permissions.ts index 4d69204bf..821642c8d 100644 --- a/src/helpers/commands/get_slash_command_permissions.ts +++ b/src/helpers/commands/get_slash_command_permissions.ts @@ -4,7 +4,7 @@ import { GuildApplicationCommandPermissions } from "../../types/interactions/gui import { endpoints } from "../../util/constants.ts"; /** Fetches command permissions for all commands for your application in a guild. Returns an array of GuildApplicationCommandPermissions objects. */ -export async function getSlashCommandPermissions(guildId: string) { +export async function getSlashCommandPermissions(guildId: bigint) { return await rest.runMethod( "get", endpoints.COMMANDS_PERMISSIONS(applicationId, guildId), diff --git a/src/helpers/commands/get_slash_commands.ts b/src/helpers/commands/get_slash_commands.ts index 4b4de42d1..bdac9a9bc 100644 --- a/src/helpers/commands/get_slash_commands.ts +++ b/src/helpers/commands/get_slash_commands.ts @@ -5,7 +5,7 @@ import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; /** Fetch all of the global commands for your application. */ -export async function getSlashCommands(guildId?: string) { +export async function getSlashCommands(guildId?: bigint) { const result = await rest.runMethod( "get", guildId diff --git a/src/helpers/commands/send_interaction_response.ts b/src/helpers/commands/send_interaction_response.ts index 3bb2132cb..6200c6641 100644 --- a/src/helpers/commands/send_interaction_response.ts +++ b/src/helpers/commands/send_interaction_response.ts @@ -11,7 +11,7 @@ import { endpoints } from "../../util/constants.ts"; * NOTE: By default we will suppress mentions. To enable mentions, just pass any mentions object. */ export async function sendInteractionResponse( - id: string, + id: bigint, token: string, options: DiscordenoInteractionResponse, ) { @@ -27,7 +27,7 @@ export async function sendInteractionResponse( } // Expire in 15 minutes - cache.executedSlashCommands.set(token, id); + cache.executedSlashCommands.add(token); setTimeout( () => { eventHandlers.debug?.( diff --git a/src/helpers/commands/upsert_slash_command.ts b/src/helpers/commands/upsert_slash_command.ts index 2fb71ae7c..d0211400d 100644 --- a/src/helpers/commands/upsert_slash_command.ts +++ b/src/helpers/commands/upsert_slash_command.ts @@ -9,9 +9,9 @@ import { validateSlashCommands } from "../../util/utils.ts"; * Edit an existing slash command. If this command did not exist, it will create it. */ export async function upsertSlashCommand( - commandId: string, + commandId: bigint, options: EditGlobalApplicationCommand, - guildId?: string, + guildId?: bigint, ) { validateSlashCommands([options]); diff --git a/src/helpers/commands/upsert_slash_commands.ts b/src/helpers/commands/upsert_slash_commands.ts index bf2b78343..3be28f765 100644 --- a/src/helpers/commands/upsert_slash_commands.ts +++ b/src/helpers/commands/upsert_slash_commands.ts @@ -12,7 +12,7 @@ import { validateSlashCommands } from "../../util/utils.ts"; */ export async function upsertSlashCommands( options: EditGlobalApplicationCommand[], - guildId?: string, + guildId?: bigint, ) { validateSlashCommands(options); diff --git a/src/helpers/discovery/add_discovery_subcategory.ts b/src/helpers/discovery/add_discovery_subcategory.ts index 93a124c91..3341f394c 100644 --- a/src/helpers/discovery/add_discovery_subcategory.ts +++ b/src/helpers/discovery/add_discovery_subcategory.ts @@ -7,7 +7,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; /** Add a discovery subcategory to the guild. Requires the `MANAGE_GUILD` permission. */ export async function addDiscoverySubcategory( - guildId: string, + guildId: bigint, categoryId: number, ) { await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); diff --git a/src/helpers/discovery/edit_discovery.ts b/src/helpers/discovery/edit_discovery.ts index 9976e04cd..e94c7a60b 100644 --- a/src/helpers/discovery/edit_discovery.ts +++ b/src/helpers/discovery/edit_discovery.ts @@ -7,7 +7,7 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts"; /** Modify the discovery metadata for the guild. Requires the MANAGE_GUILD permission. Returns the updated discovery metadata object on success. */ export async function editDiscovery( - guildId: string, + guildId: bigint, data: ModifyGuildDiscoveryMetadata, ) { await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); diff --git a/src/helpers/discovery/remove_discovery_subcategory.ts b/src/helpers/discovery/remove_discovery_subcategory.ts index 610254319..4e291e4bd 100644 --- a/src/helpers/discovery/remove_discovery_subcategory.ts +++ b/src/helpers/discovery/remove_discovery_subcategory.ts @@ -4,7 +4,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; /** Removes a discovery subcategory from the guild. Requires the MANAGE_GUILD permission. Returns a 204 No Content on success. */ export async function removeDiscoverySubcategory( - guildId: string, + guildId: bigint, categoryId: number, ) { await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); diff --git a/src/helpers/emojis/create_emoji.ts b/src/helpers/emojis/create_emoji.ts index 2b55f7ec4..504bdd299 100644 --- a/src/helpers/emojis/create_emoji.ts +++ b/src/helpers/emojis/create_emoji.ts @@ -1,13 +1,14 @@ import { rest } from "../../rest/rest.ts"; import { CreateGuildEmoji } from "../../types/emojis/create_guild_emoji.ts"; import { 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"; /** 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: string, + guildId: bigint, name: string, image: string, options: CreateGuildEmoji, @@ -18,9 +19,18 @@ export async function createEmoji( image = await urlToBase64(image); } - return await rest.runMethod("post", endpoints.GUILD_EMOJIS(guildId), { - ...options, - name, - image, - }); + const emoji = await rest.runMethod( + "post", + endpoints.GUILD_EMOJIS(guildId), + { + ...options, + name, + image, + }, + ); + + return { + ...emoji, + id: snowflakeToBigint(emoji.id!), + }; } diff --git a/src/helpers/emojis/delete_emoji.ts b/src/helpers/emojis/delete_emoji.ts index 40b43eaa3..5c1824e4e 100644 --- a/src/helpers/emojis/delete_emoji.ts +++ b/src/helpers/emojis/delete_emoji.ts @@ -4,8 +4,8 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; /** Delete the given emoji. Requires the MANAGE_EMOJIS permission. Returns 204 No Content on success. */ export async function deleteEmoji( - guildId: string, - id: string, + guildId: bigint, + id: bigint, reason?: string, ) { await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]); diff --git a/src/helpers/emojis/edit_emoji.ts b/src/helpers/emojis/edit_emoji.ts index 28ee8e15a..5d2a0f8ed 100644 --- a/src/helpers/emojis/edit_emoji.ts +++ b/src/helpers/emojis/edit_emoji.ts @@ -6,8 +6,8 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; /** Modify the given emoji. Requires the MANAGE_EMOJIS permission. */ export async function editEmoji( - guildId: string, - id: string, + guildId: bigint, + id: bigint, options: ModifyGuildEmoji, ) { await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]); diff --git a/src/helpers/emojis/emoji_url.ts b/src/helpers/emojis/emoji_url.ts index 75360f838..0c61c311c 100644 --- a/src/helpers/emojis/emoji_url.ts +++ b/src/helpers/emojis/emoji_url.ts @@ -1,4 +1,4 @@ /** Creates a url to the emoji from the Discord CDN. */ -export function emojiURL(id: string, animated = false) { +export function emojiURL(id: bigint, animated = false) { return `https://cdn.discordapp.com/emojis/${id}.${animated ? "gif" : "png"}`; } diff --git a/src/helpers/emojis/get_emoji.ts b/src/helpers/emojis/get_emoji.ts index 09f2a3cdd..d66ac2aa1 100644 --- a/src/helpers/emojis/get_emoji.ts +++ b/src/helpers/emojis/get_emoji.ts @@ -10,8 +10,8 @@ import { endpoints } from "../../util/constants.ts"; * ⚠️ **If you need this, you are probably doing something wrong. Always use cache.guilds.get()?.emojis */ export async function getEmoji( - guildId: string, - emojiId: string, + guildId: bigint, + emojiId: bigint, addToCache = true, ) { const result = await rest.runMethod( diff --git a/src/helpers/emojis/get_emojis.ts b/src/helpers/emojis/get_emojis.ts index da1d8cfa1..c0e56b65f 100644 --- a/src/helpers/emojis/get_emojis.ts +++ b/src/helpers/emojis/get_emojis.ts @@ -3,6 +3,7 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { Emoji } from "../../types/emojis/emoji.ts"; import { Errors } from "../../types/misc/errors.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; @@ -11,7 +12,7 @@ import { endpoints } from "../../util/constants.ts"; * * ⚠️ **If you need this, you are probably doing something wrong. Always use cache.guilds.get()?.emojis */ -export async function getEmojis(guildId: string, addToCache = true) { +export async function getEmojis(guildId: bigint, addToCache = true) { const result = await rest.runMethod( "get", endpoints.GUILD_EMOJIS(guildId), @@ -26,7 +27,7 @@ export async function getEmojis(guildId: string, addToCache = true) { "loop", `Running forEach loop in get_emojis file.`, ); - guild.emojis.set(emoji.id!, emoji); + guild.emojis.set(snowflakeToBigint(emoji.id!), emoji); }); await cacheHandlers.set("guilds", guildId, guild); diff --git a/src/helpers/guilds/delete_guild.ts b/src/helpers/guilds/delete_guild.ts index 496ac3088..771aecf66 100644 --- a/src/helpers/guilds/delete_guild.ts +++ b/src/helpers/guilds/delete_guild.ts @@ -2,7 +2,7 @@ import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.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: string) { +export async function deleteGuild(guildId: bigint) { return await rest.runMethod( "delete", endpoints.GUILDS_BASE(guildId), diff --git a/src/helpers/guilds/edit_guild.ts b/src/helpers/guilds/edit_guild.ts index e17206c00..212419486 100644 --- a/src/helpers/guilds/edit_guild.ts +++ b/src/helpers/guilds/edit_guild.ts @@ -9,7 +9,7 @@ import { 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: string, options: ModifyGuild) { +export async function editGuild(guildId: bigint, options: ModifyGuild) { await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); if (options.icon && !options.icon.startsWith("data:image/")) { diff --git a/src/helpers/guilds/edit_welcome_screen.ts b/src/helpers/guilds/edit_welcome_screen.ts index ae2dae039..284f1fb96 100644 --- a/src/helpers/guilds/edit_welcome_screen.ts +++ b/src/helpers/guilds/edit_welcome_screen.ts @@ -5,7 +5,7 @@ import { endpoints } from "../../util/constants.ts"; import { camelKeysToSnakeCase } from "../../util/utils.ts"; export async function editWelcomeScreen( - guildId: string, + guildId: bigint, options: ModifyGuildWelcomeScreen, ) { return await rest.runMethod( diff --git a/src/helpers/guilds/edit_widget.ts b/src/helpers/guilds/edit_widget.ts index 9259cf32d..8a27129b3 100644 --- a/src/helpers/guilds/edit_widget.ts +++ b/src/helpers/guilds/edit_widget.ts @@ -5,7 +5,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; /** Modify a guild widget object for the guild. Requires the MANAGE_GUILD permission. */ export async function editWidget( - guildId: string, + guildId: bigint, enabled: boolean, channelId?: string | null, ) { diff --git a/src/helpers/guilds/get_audit_logs.ts b/src/helpers/guilds/get_audit_logs.ts index 95b5b3aae..babcc0354 100644 --- a/src/helpers/guilds/get_audit_logs.ts +++ b/src/helpers/guilds/get_audit_logs.ts @@ -7,7 +7,7 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts"; /** Returns the audit logs for the guild. Requires VIEW AUDIT LOGS permission */ export async function getAuditLogs( - guildId: string, + guildId: bigint, options: GetGuildAuditLog, ) { await requireBotGuildPermissions(guildId, ["VIEW_AUDIT_LOG"]); diff --git a/src/helpers/guilds/get_ban.ts b/src/helpers/guilds/get_ban.ts index 3fddcd1a8..db70fc796 100644 --- a/src/helpers/guilds/get_ban.ts +++ b/src/helpers/guilds/get_ban.ts @@ -4,7 +4,7 @@ import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.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: string, memberId: string) { +export async function getBan(guildId: bigint, memberId: bigint) { await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]); return await rest.runMethod( diff --git a/src/helpers/guilds/get_bans.ts b/src/helpers/guilds/get_bans.ts index c9497f8b4..ba939dfb8 100644 --- a/src/helpers/guilds/get_bans.ts +++ b/src/helpers/guilds/get_bans.ts @@ -1,11 +1,12 @@ import { rest } from "../../rest/rest.ts"; import { Ban } from "../../types/guilds/ban.ts"; +import { snowflakeToBigint } from "../../util/bigint.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: string) { +export async function getBans(guildId: bigint) { await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]); const results = await rest.runMethod( @@ -13,7 +14,7 @@ export async function getBans(guildId: string) { endpoints.GUILD_BANS(guildId), ); - return new Collection( - results.map((res) => [res.user.id, res]), + return new Collection( + results.map((res) => [snowflakeToBigint(res.user.id), res]), ); } diff --git a/src/helpers/guilds/get_guild.ts b/src/helpers/guilds/get_guild.ts index 6e9dd06d3..0a809bbf2 100644 --- a/src/helpers/guilds/get_guild.ts +++ b/src/helpers/guilds/get_guild.ts @@ -13,7 +13,7 @@ import { ws } from "../../ws/ws.ts"; * So it does not cache the guild, you must do it manually. * */ export async function getGuild( - guildId: string, + guildId: bigint, options: { counts?: boolean; addToCache?: boolean } = { counts: true, addToCache: true, @@ -27,14 +27,14 @@ export async function getGuild( }, ); - const structure = await structures.createDiscordenoGuild( + const guild = await structures.createDiscordenoGuild( result, Number((BigInt(guildId) >> 22n) % BigInt(ws.botGatewayData.shards)), ); if (options.addToCache) { - await cacheHandlers.set("guilds", guildId, structure); + await cacheHandlers.set("guilds", guild.id, guild); } - return structure; + return guild; } diff --git a/src/helpers/guilds/get_guild_preview.ts b/src/helpers/guilds/get_guild_preview.ts index 40873cf0f..b5024f2b8 100644 --- a/src/helpers/guilds/get_guild_preview.ts +++ b/src/helpers/guilds/get_guild_preview.ts @@ -3,7 +3,7 @@ import { GuildPreview } from "../../types/guilds/guild_preview.ts"; import { endpoints } from "../../util/constants.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: string) { +export async function getGuildPreview(guildId: bigint) { return await rest.runMethod( "get", endpoints.GUILD_PREVIEW(guildId), diff --git a/src/helpers/guilds/get_prune_count.ts b/src/helpers/guilds/get_prune_count.ts index 12b35b418..27f1691cc 100644 --- a/src/helpers/guilds/get_prune_count.ts +++ b/src/helpers/guilds/get_prune_count.ts @@ -7,7 +7,7 @@ import { camelKeysToSnakeCase } from "../../util/utils.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: string, + guildId: bigint, options?: GetGuildPruneCountQuery, ) { if (options?.days && options.days < 1) throw new Error(Errors.PRUNE_MIN_DAYS); diff --git a/src/helpers/guilds/get_vainty_url.ts b/src/helpers/guilds/get_vainty_url.ts index 0dee86af7..c14719b30 100644 --- a/src/helpers/guilds/get_vainty_url.ts +++ b/src/helpers/guilds/get_vainty_url.ts @@ -3,7 +3,7 @@ import { InviteMetadata } from "../../types/invites/invite_metadata.ts"; import { endpoints } from "../../util/constants.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: string) { +export async function getVanityURL(guildId: bigint) { return await rest.runMethod< (Partial & Pick) | { code: null; diff --git a/src/helpers/guilds/get_voice_regions.ts b/src/helpers/guilds/get_voice_regions.ts index 6ed926e52..ad1598ce5 100644 --- a/src/helpers/guilds/get_voice_regions.ts +++ b/src/helpers/guilds/get_voice_regions.ts @@ -4,7 +4,7 @@ import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.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: string) { +export async function getVoiceRegions(guildId: bigint) { const result = await rest.runMethod( "get", endpoints.GUILD_REGIONS(guildId), diff --git a/src/helpers/guilds/get_welcome_screen.ts b/src/helpers/guilds/get_welcome_screen.ts index 36950e3eb..f30b8e9c7 100644 --- a/src/helpers/guilds/get_welcome_screen.ts +++ b/src/helpers/guilds/get_welcome_screen.ts @@ -2,7 +2,7 @@ import { rest } from "../../rest/rest.ts"; import { WelcomeScreen } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; -export async function getWelcomeScreen(guildId: string) { +export async function getWelcomeScreen(guildId: bigint) { return await rest.runMethod( "get", endpoints.GUILD_WELCOME_SCREEN(guildId), diff --git a/src/helpers/guilds/get_widget.ts b/src/helpers/guilds/get_widget.ts index d98034f7e..0be0e4991 100644 --- a/src/helpers/guilds/get_widget.ts +++ b/src/helpers/guilds/get_widget.ts @@ -5,7 +5,7 @@ import { Errors } from "../../types/misc/errors.ts"; import { endpoints } from "../../util/constants.ts"; /** Returns the widget for the guild. */ -export async function getWidget(guildId: string, options?: { force: boolean }) { +export async function getWidget(guildId: bigint, options?: { force: boolean }) { if (!options?.force) { const guild = await cacheHandlers.get("guilds", guildId); if (!guild) throw new Error(Errors.GUILD_NOT_FOUND); diff --git a/src/helpers/guilds/get_widget_image_url.ts b/src/helpers/guilds/get_widget_image_url.ts index f552a2326..ede9e97ff 100644 --- a/src/helpers/guilds/get_widget_image_url.ts +++ b/src/helpers/guilds/get_widget_image_url.ts @@ -5,7 +5,7 @@ import { endpoints } from "../../util/constants.ts"; /** Returns the widget image URL for the guild. */ export async function getWidgetImageURL( - guildId: string, + guildId: bigint, options?: GetGuildWidgetImageQuery & { force?: boolean }, ) { if (!options?.force) { diff --git a/src/helpers/guilds/get_widget_settings.ts b/src/helpers/guilds/get_widget_settings.ts index 960fb83ec..e8a106816 100644 --- a/src/helpers/guilds/get_widget_settings.ts +++ b/src/helpers/guilds/get_widget_settings.ts @@ -4,7 +4,7 @@ import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; /** Returns the guild widget object. Requires the MANAGE_GUILD permission. */ -export async function getWidgetSettings(guildId: string) { +export async function getWidgetSettings(guildId: bigint) { await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); return await rest.runMethod( diff --git a/src/helpers/guilds/guild_banner_url.ts b/src/helpers/guilds/guild_banner_url.ts index db027d15b..030d2cab6 100644 --- a/src/helpers/guilds/guild_banner_url.ts +++ b/src/helpers/guilds/guild_banner_url.ts @@ -5,7 +5,7 @@ import { formatImageURL } from "../../util/utils.ts"; /** The full URL of the banner from Discords CDN. Undefined if no banner is set. */ export function guildBannerURL( - id: string, + id: bigint, banner?: string, size: DiscordImageSize = 128, format?: DiscordImageFormat, diff --git a/src/helpers/guilds/guild_icon_url.ts b/src/helpers/guilds/guild_icon_url.ts index b1e02e6f2..09982fec3 100644 --- a/src/helpers/guilds/guild_icon_url.ts +++ b/src/helpers/guilds/guild_icon_url.ts @@ -5,7 +5,7 @@ import { formatImageURL } from "../../util/utils.ts"; /** The full URL of the icon from Discords CDN. Undefined when no icon is set. */ export function guildIconURL( - id: string, + id: bigint, icon?: string, size: DiscordImageSize = 128, format?: DiscordImageFormat, diff --git a/src/helpers/guilds/guild_splash_url.ts b/src/helpers/guilds/guild_splash_url.ts index 9409a0e99..83d734a07 100644 --- a/src/helpers/guilds/guild_splash_url.ts +++ b/src/helpers/guilds/guild_splash_url.ts @@ -5,7 +5,7 @@ import { formatImageURL } from "../../util/utils.ts"; /** The full URL of the splash from Discords CDN. Undefined if no splash is set. */ export function guildSplashURL( - id: string, + id: bigint, splash?: string, size: DiscordImageSize = 128, format?: DiscordImageFormat, diff --git a/src/helpers/guilds/leave_guild.ts b/src/helpers/guilds/leave_guild.ts index 9552ffe1a..c6602ece6 100644 --- a/src/helpers/guilds/leave_guild.ts +++ b/src/helpers/guilds/leave_guild.ts @@ -2,7 +2,7 @@ import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; /** Leave a guild */ -export async function leaveGuild(guildId: string) { +export async function leaveGuild(guildId: bigint) { return await rest.runMethod( "delete", endpoints.GUILD_LEAVE(guildId), diff --git a/src/helpers/guilds/update_bot_voice_state.ts b/src/helpers/guilds/update_bot_voice_state.ts index 5fcf0849c..e75d5ce9c 100644 --- a/src/helpers/guilds/update_bot_voice_state.ts +++ b/src/helpers/guilds/update_bot_voice_state.ts @@ -16,7 +16,7 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts"; * - You are able to set `request_to_speak_timestamp` to any present or future time. */ export function updateBotVoiceState( - guildId: string, + guildId: bigint, data: UpdateSelfVoiceState, ) { const payload = camelKeysToSnakeCase(data); diff --git a/src/helpers/guilds/update_user_voice_state.ts b/src/helpers/guilds/update_user_voice_state.ts index 30b87630f..88708ad10 100644 --- a/src/helpers/guilds/update_user_voice_state.ts +++ b/src/helpers/guilds/update_user_voice_state.ts @@ -16,8 +16,8 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts"; * - When suppressed, the user will have their `request_to_speak_timestamp` removed. */ export function updateVoiceState( - guildId: string, - userId: string, + guildId: bigint, + userId: bigint, data: UpdateOthersVoiceState, ) { const payload = camelKeysToSnakeCase(data); diff --git a/src/helpers/integrations/delete_integration.ts b/src/helpers/integrations/delete_integration.ts index cd92ab5e1..2c935cae9 100644 --- a/src/helpers/integrations/delete_integration.ts +++ b/src/helpers/integrations/delete_integration.ts @@ -3,7 +3,7 @@ import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; /** Delete the attached integration object for the guild with this id. Requires MANAGE_GUILD permission. */ -export async function deleteIntegration(guildId: string, id: string) { +export async function deleteIntegration(guildId: bigint, id: bigint) { await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); return await rest.runMethod( diff --git a/src/helpers/integrations/get_integrations.ts b/src/helpers/integrations/get_integrations.ts index f8c54d80d..96fd2110c 100644 --- a/src/helpers/integrations/get_integrations.ts +++ b/src/helpers/integrations/get_integrations.ts @@ -4,7 +4,7 @@ import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; /** Returns a list of integrations for the guild. Requires the MANAGE_GUILD permission. */ -export async function getIntegrations(guildId: string) { +export async function getIntegrations(guildId: bigint) { await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); return await rest.runMethod( diff --git a/src/helpers/invites/create_invite.ts b/src/helpers/invites/create_invite.ts index 0edab07ba..6761d9048 100644 --- a/src/helpers/invites/create_invite.ts +++ b/src/helpers/invites/create_invite.ts @@ -7,7 +7,7 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts"; /** Creates a new invite for this channel. Requires CREATE_INSTANT_INVITE */ export async function createInvite( - channelId: string, + channelId: bigint, options: CreateChannelInvite, ) { await requireBotChannelPermissions(channelId, ["CREATE_INSTANT_INVITE"]); diff --git a/src/helpers/invites/delete_invite.ts b/src/helpers/invites/delete_invite.ts index 0891c89ed..130cd2488 100644 --- a/src/helpers/invites/delete_invite.ts +++ b/src/helpers/invites/delete_invite.ts @@ -9,7 +9,7 @@ import { } from "../../util/permissions.ts"; /** Deletes an invite for the given code. Requires `MANAGE_CHANNELS` or `MANAGE_GUILD` permission */ -export async function deleteInvite(channelId: string, inviteCode: string) { +export async function deleteInvite(channelId: bigint, inviteCode: string) { const channel = await cacheHandlers.get("channels", channelId); if (!channel) throw new Error(Errors.CHANNEL_NOT_FOUND); diff --git a/src/helpers/invites/get_channel_invites.ts b/src/helpers/invites/get_channel_invites.ts index 4c9ce95c6..ecd27a6d5 100644 --- a/src/helpers/invites/get_channel_invites.ts +++ b/src/helpers/invites/get_channel_invites.ts @@ -5,7 +5,7 @@ import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; /** Gets the invites for this channel. Requires MANAGE_CHANNEL */ -export async function getChannelInvites(channelId: string) { +export async function getChannelInvites(channelId: bigint) { await requireBotChannelPermissions(channelId, ["MANAGE_CHANNELS"]); const result = await rest.runMethod( diff --git a/src/helpers/invites/get_invites.ts b/src/helpers/invites/get_invites.ts index c4a72e7d6..0ad0fda87 100644 --- a/src/helpers/invites/get_invites.ts +++ b/src/helpers/invites/get_invites.ts @@ -5,7 +5,7 @@ import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; /** Get all the invites for this guild. Requires MANAGE_GUILD permission */ -export async function getInvites(guildId: string) { +export async function getInvites(guildId: bigint) { await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); const result = await rest.runMethod( diff --git a/src/helpers/members/avatar_url.ts b/src/helpers/members/avatar_url.ts index 3bbc160de..64a136370 100644 --- a/src/helpers/members/avatar_url.ts +++ b/src/helpers/members/avatar_url.ts @@ -5,8 +5,8 @@ import { formatImageURL } from "../../util/utils.ts"; /** The users custom avatar or the default avatar if you don't have a member object. */ export function avatarURL( - userId: string, - discriminator: string, + userId: bigint, + discriminator: bigint, avatar?: string | null, size: DiscordImageSize = 128, format?: DiscordImageFormat, diff --git a/src/helpers/members/ban_member.ts b/src/helpers/members/ban_member.ts index c1257cf08..57215ba59 100644 --- a/src/helpers/members/ban_member.ts +++ b/src/helpers/members/ban_member.ts @@ -6,8 +6,8 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts"; /** Ban a user from the guild and optionally delete previous messages sent by the user. Requires the BAN_MEMBERS permission. */ export async function ban( - guildId: string, - id: string, + guildId: bigint, + id: bigint, options: CreateGuildBan, ) { await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]); diff --git a/src/helpers/members/disconnect_member.ts b/src/helpers/members/disconnect_member.ts index 5c6c3a92e..a1d4b0b9c 100644 --- a/src/helpers/members/disconnect_member.ts +++ b/src/helpers/members/disconnect_member.ts @@ -1,6 +1,6 @@ import { editMember } from "./edit_member.ts"; /** Kicks a member from a voice channel */ -export function disconnectMember(guildId: string, memberId: string) { +export function disconnectMember(guildId: bigint, memberId: bigint) { return editMember(guildId, memberId, { channelId: null }); } diff --git a/src/helpers/members/edit_bot_nickname.ts b/src/helpers/members/edit_bot_nickname.ts index f9b41bb3c..8601ee554 100644 --- a/src/helpers/members/edit_bot_nickname.ts +++ b/src/helpers/members/edit_bot_nickname.ts @@ -4,7 +4,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; /** Edit the nickname of the bot in this guild */ export async function editBotNickname( - guildId: string, + guildId: bigint, nickname: string | null, ) { await requireBotGuildPermissions(guildId, ["CHANGE_NICKNAME"]); diff --git a/src/helpers/members/edit_member.ts b/src/helpers/members/edit_member.ts index 73b3e6b6c..b9ad4efea 100644 --- a/src/helpers/members/edit_member.ts +++ b/src/helpers/members/edit_member.ts @@ -5,6 +5,7 @@ import { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; import { Errors } from "../../types/misc/errors.ts"; import { ModifyGuildMember } from "../../types/mod.ts"; import { PermissionStrings } from "../../types/permissions/permission_strings.ts"; +import { bigintToSnowflake } from "../../util/bigint.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions, @@ -14,9 +15,9 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts"; /** Edit the member */ export async function editMember( - guildId: string, - memberId: string, - options: ModifyGuildMember, + guildId: bigint, + memberId: bigint, + options: Omit & { channelId?: bigint | null }, ) { const requiredPerms: Set = new Set(); @@ -72,7 +73,12 @@ export async function editMember( const result = await rest.runMethod( "patch", endpoints.GUILD_MEMBER(guildId, memberId), - camelKeysToSnakeCase(options), + camelKeysToSnakeCase({ + ...options, + channelId: options.channelId + ? bigintToSnowflake(options.channelId) + : undefined, + }) as ModifyGuildMember, ); const member = await structures.createDiscordenoMember( diff --git a/src/helpers/members/fetch_members.ts b/src/helpers/members/fetch_members.ts index aee4ed00c..eca4c7720 100644 --- a/src/helpers/members/fetch_members.ts +++ b/src/helpers/members/fetch_members.ts @@ -17,7 +17,7 @@ import { ws } from "../../ws/ws.ts"; * GW(this function): 120/m(PER shard) rate limit. Meaning if you have 8 shards your limit is now 960/m. */ export function fetchMembers( - guildId: string, + guildId: bigint, shardId: number, options?: Omit, ) { @@ -49,5 +49,5 @@ export function fetchMembers( nonce, }, }); - }) as Promise>; + }) as Promise>; } diff --git a/src/helpers/members/get_member.ts b/src/helpers/members/get_member.ts index 8605fbe4c..4949f3165 100644 --- a/src/helpers/members/get_member.ts +++ b/src/helpers/members/get_member.ts @@ -9,8 +9,8 @@ import { endpoints } from "../../util/constants.ts"; * ⚠️ **ADVANCED USE ONLY: Your members will be cached in your guild most likely. Only use this when you are absolutely sure the member is not cached.** */ export async function getMember( - guildId: string, - id: string, + guildId: bigint, + id: bigint, options?: { force?: boolean }, ) { const guild = await cacheHandlers.get("guilds", guildId); diff --git a/src/helpers/members/get_members.ts b/src/helpers/members/get_members.ts index 202c4a70d..9e0b10a02 100644 --- a/src/helpers/members/get_members.ts +++ b/src/helpers/members/get_members.ts @@ -7,6 +7,7 @@ import { DiscordGatewayIntents } from "../../types/gateway/gateway_intents.ts"; import { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; import { ListGuildMembers } from "../../types/guilds/list_guild_members.ts"; import { Errors } from "../../types/misc/errors.ts"; +import { bigintToSnowflake } from "../../util/bigint.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; import { ws } from "../../ws/ws.ts"; @@ -20,7 +21,7 @@ import { ws } from "../../ws/ws.ts"; * GW(fetchMembers): 120/m(PER shard) rate limit. Meaning if you have 8 shards your limit is 960/m. */ export async function getMembers( - guildId: string, + guildId: bigint, options?: ListGuildMembers & { addToCache?: boolean }, ) { if (!(ws.identifyPayload.intents && DiscordGatewayIntents.GUILD_MEMBERS)) { @@ -30,7 +31,7 @@ export async function getMembers( const guild = await cacheHandlers.get("guilds", guildId); if (!guild) throw new Error(Errors.GUILD_NOT_FOUND); - const members = new Collection(); + const members = new Collection(); let membersLeft = options?.limit ?? guild.memberCount; let loops = 1; @@ -88,7 +89,9 @@ export async function getMembers( options = { limit: options?.limit, - after: discordenoMembers[discordenoMembers.length - 1].id, + after: bigintToSnowflake( + discordenoMembers[discordenoMembers.length - 1].id, + ), }; membersLeft -= 1000; diff --git a/src/helpers/members/kick_member.ts b/src/helpers/members/kick_member.ts index 8dbefc72e..4b1151574 100644 --- a/src/helpers/members/kick_member.ts +++ b/src/helpers/members/kick_member.ts @@ -8,7 +8,7 @@ import { } from "../../util/permissions.ts"; /** Kick a member from the server */ -export async function kick(guildId: string, memberId: string, reason?: string) { +export async function kick(guildId: bigint, memberId: bigint, reason?: string) { const botsHighestRole = await highestRole(guildId, botId); const membersHighestRole = await highestRole(guildId, memberId); if ( diff --git a/src/helpers/members/move_member.ts b/src/helpers/members/move_member.ts index 678092454..5cc810f5e 100644 --- a/src/helpers/members/move_member.ts +++ b/src/helpers/members/move_member.ts @@ -7,9 +7,9 @@ import { editMember } from "./edit_member.ts"; * @param channelId id of channel to move user to (if they are connected to voice) */ export function moveMember( - guildId: string, - memberId: string, - channelId: string, + guildId: bigint, + memberId: bigint, + channelId: bigint, ) { return editMember(guildId, memberId, { channelId }); } diff --git a/src/helpers/members/prune_members.ts b/src/helpers/members/prune_members.ts index ae8fc190c..0ee5010fb 100644 --- a/src/helpers/members/prune_members.ts +++ b/src/helpers/members/prune_members.ts @@ -11,7 +11,7 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts"; * By default, prune will not remove users with roles. You can optionally include specific roles in your prune by providing the roles (resolved to include_roles internally) parameter. Any inactive user that has a subset of the provided role(s) will be included in the prune and users with additional roles will not. */ export async function pruneMembers( - guildId: string, + guildId: bigint, options: BeginGuildPrune, ) { if (options.days && options.days < 1) throw new Error(Errors.PRUNE_MIN_DAYS); diff --git a/src/helpers/members/search_members.ts b/src/helpers/members/search_members.ts index 12202aba2..b57745f1d 100644 --- a/src/helpers/members/search_members.ts +++ b/src/helpers/members/search_members.ts @@ -13,7 +13,7 @@ import { endpoints } from "../../util/constants.ts"; * @param query Query string to match username(s) and nickname(s) against */ export async function searchMembers( - guildId: string, + guildId: bigint, query: string, options?: Omit & { cache?: boolean }, ) { @@ -45,7 +45,7 @@ export async function searchMembers( return discordenoMember; })); - return new Collection( + return new Collection( members.map((member) => [member.id, member]), ); } diff --git a/src/helpers/members/send_direct_message.ts b/src/helpers/members/send_direct_message.ts index ce01eaeda..4aae8e391 100644 --- a/src/helpers/members/send_direct_message.ts +++ b/src/helpers/members/send_direct_message.ts @@ -8,7 +8,7 @@ import { sendMessage } from "../messages/send_message.ts"; /** Send a message to a users DM. Note: this takes 2 API calls. 1 is to fetch the users dm channel. 2 is to send a message to that channel. */ export async function sendDirectMessage( - memberId: string, + memberId: bigint, content: string | CreateMessage, ) { let dmChannel = await cacheHandlers.get("channels", memberId); diff --git a/src/helpers/members/unban_member.ts b/src/helpers/members/unban_member.ts index a6c429fb8..b3b36e960 100644 --- a/src/helpers/members/unban_member.ts +++ b/src/helpers/members/unban_member.ts @@ -3,7 +3,7 @@ import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; /** Remove the ban for a user. Requires BAN_MEMBERS permission */ -export async function unban(guildId: string, id: string) { +export async function unban(guildId: bigint, id: bigint) { await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]); return await rest.runMethod( diff --git a/src/helpers/messages/add_reaction.ts b/src/helpers/messages/add_reaction.ts index 6c2fe402b..6e15e82ea 100644 --- a/src/helpers/messages/add_reaction.ts +++ b/src/helpers/messages/add_reaction.ts @@ -4,8 +4,8 @@ import { requireBotChannelPermissions } from "../../util/permissions.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( - channelId: string, - messageId: string, + channelId: bigint, + messageId: bigint, reaction: string, ) { await requireBotChannelPermissions(channelId, [ diff --git a/src/helpers/messages/add_reactions.ts b/src/helpers/messages/add_reactions.ts index 6a619c63e..e03a47ba3 100644 --- a/src/helpers/messages/add_reactions.ts +++ b/src/helpers/messages/add_reactions.ts @@ -3,8 +3,8 @@ 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 */ export async function addReactions( - channelId: string, - messageId: string, + channelId: bigint, + messageId: bigint, reactions: string[], ordered = false, ) { diff --git a/src/helpers/messages/delete_message.ts b/src/helpers/messages/delete_message.ts index 9b84ae248..92cb0eca4 100644 --- a/src/helpers/messages/delete_message.ts +++ b/src/helpers/messages/delete_message.ts @@ -7,14 +7,14 @@ import { delay } from "../../util/utils.ts"; /** Delete a message with the channel id and message id only. */ export async function deleteMessage( - channelId: string, - messageId: string, + channelId: bigint, + messageId: bigint, reason?: string, delayMilliseconds = 0, ) { const message = await cacheHandlers.get("messages", messageId); - if (message && message.author.id !== botId) { + if (message && message.authorId !== botId) { await requireBotChannelPermissions(message.channelId, ["MANAGE_MESSAGES"]); } diff --git a/src/helpers/messages/delete_messages.ts b/src/helpers/messages/delete_messages.ts index 5ff274215..1b5f1912e 100644 --- a/src/helpers/messages/delete_messages.ts +++ b/src/helpers/messages/delete_messages.ts @@ -5,7 +5,7 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts"; /** Delete messages from the channel. 2-100. Requires the MANAGE_MESSAGES permission */ export async function deleteMessages( - channelId: string, + channelId: bigint, ids: string[], reason?: string, ) { diff --git a/src/helpers/messages/edit_message.ts b/src/helpers/messages/edit_message.ts index 860aa7616..e45bc4577 100644 --- a/src/helpers/messages/edit_message.ts +++ b/src/helpers/messages/edit_message.ts @@ -14,7 +14,7 @@ export async function editMessage( message: DiscordenoMessage, content: string | EditMessage, ) { - if (message.author.id !== botId) { + if (message.authorId !== botId) { throw "You can only edit a message that was sent by the bot."; } diff --git a/src/helpers/messages/get_message.ts b/src/helpers/messages/get_message.ts index fc3f00cf6..7779a9d67 100644 --- a/src/helpers/messages/get_message.ts +++ b/src/helpers/messages/get_message.ts @@ -6,7 +6,7 @@ import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; /** Fetch a single message from the server. Requires VIEW_CHANNEL and READ_MESSAGE_HISTORY */ -export async function getMessage(channelId: string, id: string) { +export async function getMessage(channelId: bigint, id: bigint) { if (await cacheHandlers.has("channels", channelId)) { await requireBotChannelPermissions(channelId, [ "VIEW_CHANNEL", diff --git a/src/helpers/messages/get_messages.ts b/src/helpers/messages/get_messages.ts index 1429b495b..f12e4eb0c 100644 --- a/src/helpers/messages/get_messages.ts +++ b/src/helpers/messages/get_messages.ts @@ -12,7 +12,7 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts"; /** Fetches between 2-100 messages. Requires VIEW_CHANNEL and READ_MESSAGE_HISTORY */ export async function getMessages( - channelId: string, + channelId: bigint, options?: | GetMessagesAfter | GetMessagesBefore diff --git a/src/helpers/messages/get_reactions.ts b/src/helpers/messages/get_reactions.ts index bf10d2d6d..04ee9806e 100644 --- a/src/helpers/messages/get_reactions.ts +++ b/src/helpers/messages/get_reactions.ts @@ -6,8 +6,8 @@ import { endpoints } from "../../util/constants.ts"; /** Get a list of users that reacted with this emoji. */ export async function getReactions( - channelId: string, - messageId: string, + channelId: bigint, + messageId: bigint, reaction: string, options?: GetReactions, ) { diff --git a/src/helpers/messages/pin_message.ts b/src/helpers/messages/pin_message.ts index f96cac8f0..859e0c946 100644 --- a/src/helpers/messages/pin_message.ts +++ b/src/helpers/messages/pin_message.ts @@ -3,7 +3,7 @@ import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; /** Pin a message in a channel. Requires MANAGE_MESSAGES. Max pins allowed in a channel = 50. */ -export async function pin(channelId: string, messageId: string) { +export async function pin(channelId: bigint, messageId: bigint) { await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]); return await rest.runMethod( diff --git a/src/helpers/messages/publish_message.ts b/src/helpers/messages/publish_message.ts index 7d9d2ca17..5c60a38bf 100644 --- a/src/helpers/messages/publish_message.ts +++ b/src/helpers/messages/publish_message.ts @@ -4,7 +4,7 @@ import { Message } from "../../types/messages/message.ts"; import { endpoints } from "../../util/constants.ts"; /** Crosspost a message in a News Channel to following channels. */ -export async function publishMessage(channelId: string, messageId: string) { +export async function publishMessage(channelId: bigint, messageId: bigint) { const data = await rest.runMethod( "post", endpoints.CHANNEL_MESSAGE_CROSSPOST(channelId, messageId), diff --git a/src/helpers/messages/remove_all_reactions.ts b/src/helpers/messages/remove_all_reactions.ts index a97b81d9e..be0c3f6f5 100644 --- a/src/helpers/messages/remove_all_reactions.ts +++ b/src/helpers/messages/remove_all_reactions.ts @@ -3,7 +3,7 @@ import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; /** Removes all reactions for all emojis on this message. */ -export async function removeAllReactions(channelId: string, messageId: string) { +export async function removeAllReactions(channelId: bigint, messageId: bigint) { await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]); return await rest.runMethod( diff --git a/src/helpers/messages/remove_reaction.ts b/src/helpers/messages/remove_reaction.ts index 36866d010..cbfd16558 100644 --- a/src/helpers/messages/remove_reaction.ts +++ b/src/helpers/messages/remove_reaction.ts @@ -4,10 +4,10 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts"; /** Removes a reaction from the given user on this message, defaults to bot. Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. */ export async function removeReaction( - channelId: string, - messageId: string, + channelId: bigint, + messageId: bigint, reaction: string, - options?: { userId?: string }, + options?: { userId?: bigint }, ) { if (options?.userId) { await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]); diff --git a/src/helpers/messages/remove_reaction_emoji.ts b/src/helpers/messages/remove_reaction_emoji.ts index 85a68a0be..f87a5f7bd 100644 --- a/src/helpers/messages/remove_reaction_emoji.ts +++ b/src/helpers/messages/remove_reaction_emoji.ts @@ -4,8 +4,8 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts"; /** Removes all reactions for a single emoji on this message. Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. */ export async function removeReactionEmoji( - channelId: string, - messageId: string, + channelId: bigint, + messageId: bigint, reaction: string, ) { await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]); diff --git a/src/helpers/messages/send_message.ts b/src/helpers/messages/send_message.ts index 87dd3eb20..0dd952d6e 100644 --- a/src/helpers/messages/send_message.ts +++ b/src/helpers/messages/send_message.ts @@ -17,7 +17,7 @@ import { isButton } from "../type_guards/is_button.ts"; /** Send a message to the channel. Requires SEND_MESSAGES permission. */ export async function sendMessage( - channelId: string, + channelId: bigint, content: string | CreateMessage, ) { if (typeof content === "string") content = { content }; diff --git a/src/helpers/messages/unpin_message.ts b/src/helpers/messages/unpin_message.ts index 1af948620..4e3d0940b 100644 --- a/src/helpers/messages/unpin_message.ts +++ b/src/helpers/messages/unpin_message.ts @@ -4,8 +4,8 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts"; /** Unpin a message in a channel. Requires MANAGE_MESSAGES. */ export async function unpin( - channelId: string, - messageId: string, + channelId: bigint, + messageId: bigint, ): Promise { await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]); diff --git a/src/helpers/misc/get_user.ts b/src/helpers/misc/get_user.ts index 9913acddc..0c1517c91 100644 --- a/src/helpers/misc/get_user.ts +++ b/src/helpers/misc/get_user.ts @@ -3,6 +3,6 @@ import { User } from "../../types/users/user.ts"; import { endpoints } from "../../util/constants.ts"; /** This function will return the raw user payload in the rare cases you need to fetch a user directly from the API. */ -export async function getUser(userId: string) { +export async function getUser(userId: bigint) { return await rest.runMethod("get", endpoints.USER(userId)); } diff --git a/src/helpers/roles/add_role.ts b/src/helpers/roles/add_role.ts index 6bf738ede..b207ad9c8 100644 --- a/src/helpers/roles/add_role.ts +++ b/src/helpers/roles/add_role.ts @@ -9,9 +9,9 @@ import { /** Add a role to the member */ export async function addRole( - guildId: string, - memberId: string, - roleId: string, + guildId: bigint, + memberId: bigint, + roleId: bigint, reason?: string, ) { const isHigherRolePosition = await isHigherPosition( diff --git a/src/helpers/roles/create_role.ts b/src/helpers/roles/create_role.ts index 9f81b3911..363809489 100644 --- a/src/helpers/roles/create_role.ts +++ b/src/helpers/roles/create_role.ts @@ -11,7 +11,7 @@ import { /** Create a new role for the guild. Requires the MANAGE_ROLES permission. */ export async function createRole( - guildId: string, + guildId: bigint, options: CreateGuildRole, reason?: string, ) { diff --git a/src/helpers/roles/delete_role.ts b/src/helpers/roles/delete_role.ts index f9d134545..78d0943dd 100644 --- a/src/helpers/roles/delete_role.ts +++ b/src/helpers/roles/delete_role.ts @@ -3,7 +3,7 @@ import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; /** Delete a guild role. Requires the MANAGE_ROLES permission. */ -export async function deleteRole(guildId: string, id: string) { +export async function deleteRole(guildId: bigint, id: bigint) { await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); return await rest.runMethod( diff --git a/src/helpers/roles/edit_role.ts b/src/helpers/roles/edit_role.ts index b3c6e8784..ad178d063 100644 --- a/src/helpers/roles/edit_role.ts +++ b/src/helpers/roles/edit_role.ts @@ -9,8 +9,8 @@ import { /** Edit a guild role. Requires the MANAGE_ROLES permission. */ export async function editRole( - guildId: string, - id: string, + guildId: bigint, + id: bigint, options: CreateGuildRole, ) { await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); diff --git a/src/helpers/roles/get_roles.ts b/src/helpers/roles/get_roles.ts index ace6fe351..b65dbf882 100644 --- a/src/helpers/roles/get_roles.ts +++ b/src/helpers/roles/get_roles.ts @@ -8,7 +8,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; * * ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your roles will be cached in your guild.** */ -export async function getRoles(guildId: string) { +export async function getRoles(guildId: bigint) { await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); const result = await rest.runMethod( diff --git a/src/helpers/roles/remove_role.ts b/src/helpers/roles/remove_role.ts index 5a98501ef..645cd990f 100644 --- a/src/helpers/roles/remove_role.ts +++ b/src/helpers/roles/remove_role.ts @@ -9,9 +9,9 @@ import { /** Remove a role from the member */ export async function removeRole( - guildId: string, - memberId: string, - roleId: string, + guildId: bigint, + memberId: bigint, + roleId: bigint, reason?: string, ) { const isHigherRolePosition = await isHigherPosition( diff --git a/src/helpers/templates/create_guild_template.ts b/src/helpers/templates/create_guild_template.ts index a66d8f069..b6d54feed 100644 --- a/src/helpers/templates/create_guild_template.ts +++ b/src/helpers/templates/create_guild_template.ts @@ -10,7 +10,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; * @param description description for the template (0-120 characters */ export async function createGuildTemplate( - guildId: string, + guildId: bigint, data: Template, ) { await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); diff --git a/src/helpers/templates/delete_guild_template.ts b/src/helpers/templates/delete_guild_template.ts index a587fde2c..4cacb22e7 100644 --- a/src/helpers/templates/delete_guild_template.ts +++ b/src/helpers/templates/delete_guild_template.ts @@ -8,7 +8,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; * Requires the `MANAGE_GUILD` permission. */ export async function deleteGuildTemplate( - guildId: string, + guildId: bigint, templateCode: string, ) { await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); diff --git a/src/helpers/templates/edit_guild_template.ts b/src/helpers/templates/edit_guild_template.ts index fc90ad2ad..d35779cbd 100644 --- a/src/helpers/templates/edit_guild_template.ts +++ b/src/helpers/templates/edit_guild_template.ts @@ -9,7 +9,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; * Requires the `MANAGE_GUILD` permission. */ export async function editGuildTemplate( - guildId: string, + guildId: bigint, templateCode: string, data: ModifyGuildTemplate, ) { diff --git a/src/helpers/templates/get_guild_templates.ts b/src/helpers/templates/get_guild_templates.ts index b94f08115..30ba5be5f 100644 --- a/src/helpers/templates/get_guild_templates.ts +++ b/src/helpers/templates/get_guild_templates.ts @@ -8,7 +8,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; * Returns an array of templates. * Requires the `MANAGE_GUILD` permission. */ -export async function getGuildTemplates(guildId: string) { +export async function getGuildTemplates(guildId: bigint) { await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); const templates = await rest.runMethod( diff --git a/src/helpers/templates/sync_guild_template.ts b/src/helpers/templates/sync_guild_template.ts index 19ab2e070..235952321 100644 --- a/src/helpers/templates/sync_guild_template.ts +++ b/src/helpers/templates/sync_guild_template.ts @@ -7,7 +7,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; * Syncs the template to the guild's current state. * Requires the `MANAGE_GUILD` permission. */ -export async function syncGuildTemplate(guildId: string, templateCode: string) { +export async function syncGuildTemplate(guildId: bigint, templateCode: string) { await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); return await rest.runMethod