From 0670dd1ef96d7172d4c0e8a79b24999cc762be97 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Fri, 30 Apr 2021 22:10:24 +0200 Subject: [PATCH 001/424] add: new channel types --- src/types/channels/channel_types.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/types/channels/channel_types.ts b/src/types/channels/channel_types.ts index e7a47deab..e7cf521c6 100644 --- a/src/types/channels/channel_types.ts +++ b/src/types/channels/channel_types.ts @@ -1,19 +1,25 @@ /** https://discord.com/developers/docs/resources/channel#channel-object-channel-types */ export enum DiscordChannelTypes { /** A text channel within a server */ - GUILD_TEXT, + GuildText, /** A direct message between users */ - DM, + Dm, /** A voice channel within a server */ - GUILD_VOICE, + GuildVoice, /** A direct message between multiple users */ - GROUP_DM, + GroupDm, /** An organizational category that contains up to 50 channels */ - GUILD_CATEGORY, + GuildCategory, /** A channel that users can follow and crosspost into their own server */ - GUILD_NEWS, + GuildNews, /** A channel in which game developers can sell their game on Discord */ - GUILD_STORE, + GuildStore, + /** A temporary sub-channel within a GUILD_NEWS channel */ + GuildNewsThread = 10, + /** A temporary sub-channel within a GUILD_TEXT channel */ + GuildPublicThread, + /** A temporary sub-channel within a GUILD_TEXT channel that is only viewable by those invited and those with the MANAGE_THREADS permission */ + GuildPivateThread, /** A voice channel for hosting events with an audience */ GUILD_STAGE_VOICE = 13, } From 84d5f8635fbc094ccb0b64ca455482eefe5b83d1 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Fri, 30 Apr 2021 22:44:18 +0200 Subject: [PATCH 002/424] new message types --- src/types/messages/message_types.ts | 41 +++++++++++++++-------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/types/messages/message_types.ts b/src/types/messages/message_types.ts index ba4c6a58a..29fc92fb5 100644 --- a/src/types/messages/message_types.ts +++ b/src/types/messages/message_types.ts @@ -1,23 +1,24 @@ /** https://discord.com/developers/docs/resources/channel#message-object-message-types */ export enum DiscordMessageTypes { - DEFAULT, - RECIPIENT_ADD, - RECIPIENT_REMOVE, - CALL, - CHANNEL_NAME_CHANGE, - CHANNEL_ICON_CHANGE, - CHANNEL_PINNED_MESSAGE, - GUILD_MEMBER_JOIN, - USER_PREMIUM_GUILD_SUBSCRIPTION, - USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1, - USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2, - USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3, - CHANNEL_FOLLOW_ADD, - GUILD_DISCOVERY_DISQUALIFIED = 14, - GUILD_DISCOVERY_REQUALIFIED, - GUILD_DISCOVERY_GRACE_PERIOD_INITIAL_WARNING, - GUILD_DISCOVERY_GRACE_PERIOD_FINAL_WARNING, - REPLY = 19, - APPLICATION_COMMAND, - GUILD_INVITE_REMINDER = 22, + Default, + RecipientAdd, + RecipientRemove, + Call, + ChannelNameChange, + ChannelIconChange, + ChannelPinnedMessage, + GuildMemberJoin, + UserPremiumGuildSubscription, + UserPremiumGuildSubscriptionTier1, + UserPremiumGuildSubscriptionTier2, + UserPremiumGuildSubscriptionTier3, + ChannelFollowAdd, + GuildDiscoveryDisqualified = 14, + GuildDiscoveryRequalified, + GuildDiscoveryGracePeriodInitialWarning, + GuildDiscoveryGracePeriodFinalWarning, + ThreadCreated, + Reply = 19, + ApplicationCommand, + GuildInviteReminder = 22, } From 2a31b245e6306f0aae2245c511504b800c57be1b Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Fri, 30 Apr 2021 23:01:08 +0200 Subject: [PATCH 003/424] add: new message flags --- src/types/messages/message_flags.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/types/messages/message_flags.ts b/src/types/messages/message_flags.ts index 4f55463d9..f9c149dbe 100644 --- a/src/types/messages/message_flags.ts +++ b/src/types/messages/message_flags.ts @@ -1,17 +1,19 @@ /** https://discord.com/developers/docs/resources/channel#message-object-message-flags */ export enum DiscordMessageFlags { /** This message has been published to subscribed channels (via Channel Following) */ - CROSSPOSTED = 1 << 0, + Crossposted = 1 << 0, /** This message originated from a message in another channel (via Channel Following) */ - IS_CROSSPOST = 1 << 1, + IsCrosspost = 1 << 1, /** Do not include any embeds when serializing this message */ - SUPPRESS_EMBEDS = 1 << 2, + SuppressEmbeeds = 1 << 2, /** The source message for this crosspost has been deleted (via Channel Following) */ - SOURCE_MESSAGE_DELETED = 1 << 3, + SourceMessageDeleted = 1 << 3, /** This message came from the urgent message system */ - URGENT = 1 << 4, + Urgent = 1 << 4, + /** This message has an associated thread, with the same id as the message */ + HasThread = 1 << 5, /** This message is only visible to the user who invoked the Interaction */ - EMPHERAL = 1 << 6, + Empheral = 1 << 6, /** This message is an Interaction Response and the bot is "thinking" */ - LOADING = 1 << 7, + Loading = 1 << 7, } From 399914826630c78063a745c43b1cf44d0536614d Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Fri, 30 Apr 2021 23:01:17 +0200 Subject: [PATCH 004/424] add: ThreadMember --- src/types/messages/thread_member.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/types/messages/thread_member.ts diff --git a/src/types/messages/thread_member.ts b/src/types/messages/thread_member.ts new file mode 100644 index 000000000..2b3d1b54a --- /dev/null +++ b/src/types/messages/thread_member.ts @@ -0,0 +1,10 @@ +export interface ThreadMember { + /** The id of the thread */ + id: string; + /** The id of the user */ + userId: string; + /** The time the current user last joined the thread */ + joinTimestamp: string; + /** Any user-thread settings, currently only used for notifications */ + flags: number; +} From 653ef1faab7588419aab831cff61f57eb4ee90ec Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Fri, 30 Apr 2021 23:01:28 +0200 Subject: [PATCH 005/424] add: ThreadMetadata --- src/types/messages/thread_metadata.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/types/messages/thread_metadata.ts diff --git a/src/types/messages/thread_metadata.ts b/src/types/messages/thread_metadata.ts new file mode 100644 index 000000000..ce8f40e56 --- /dev/null +++ b/src/types/messages/thread_metadata.ts @@ -0,0 +1,12 @@ +export interface ThreadMetadata { + /** Whether the thread is archived */ + archived: boolean; + /** Id of the user that last archived or unarchived the thread */ + archiverId?: string; + /** Duration in minutes to automatically archive the thread after recent activity */ + autoArchiveDuration: 60 | 1440 | 4320 | 10080; + /** Timestamp when the thread's archive status was last changed, used for calculating recent activity */ + archiveTimestamp: string; + /** When a thread is locked, only users with `MANAGE_THREADS` can unarchive it */ + locked?: boolean; +} From bd52c0f571fb1b93b4145fb8dcc22d393a292f5e Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Fri, 30 Apr 2021 23:01:40 +0200 Subject: [PATCH 006/424] add: thread param --- src/types/messages/message.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/types/messages/message.ts b/src/types/messages/message.ts index c00b23d62..f25f257a4 100644 --- a/src/types/messages/message.ts +++ b/src/types/messages/message.ts @@ -1,3 +1,4 @@ +import { Channel } from "../channels/channel.ts"; import { ChannelMention } from "../channels/channel_mention.ts"; import { Embed } from "../embeds/embed.ts"; import { GuildMember } from "../guilds/guild_member.ts"; @@ -11,6 +12,7 @@ import { MessageReference } from "./message_reference.ts"; import { MessageSticker } from "./message_sticker.ts"; import { DiscordMessageTypes } from "./message_types.ts"; import { DiscordReaction } from "./reaction.ts"; +import { ThreadMember } from "./thread_member.ts"; export interface Message { /** id of the message */ @@ -82,6 +84,8 @@ export interface Message { referencedMessage?: Message; /** Sent if the message is a response to an Interaction */ interaction?: MessageInteraction; + /** The thread that was started from this message, includes thread member object */ + thread?: Omit & { member: ThreadMember }; } /** https://discord.com/developers/docs/resources/channel#message-object */ From 111dde1020b4f4c8a1f67d8782240e31aacf00ed Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Fri, 30 Apr 2021 23:01:51 +0200 Subject: [PATCH 007/424] add: thread params --- src/types/channels/channel.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/types/channels/channel.ts b/src/types/channels/channel.ts index 9361bbeb3..a4cffce5d 100644 --- a/src/types/channels/channel.ts +++ b/src/types/channels/channel.ts @@ -1,3 +1,5 @@ +import { ThreadMember } from "../messages/thread_member.ts"; +import { ThreadMetadata } from "../messages/thread_metadata.ts"; import { User } from "../users/user.ts"; import { SnakeCasedPropertiesDeep } from "../util.ts"; import { DiscordChannelTypes } from "./channel_types.ts"; @@ -33,11 +35,11 @@ export interface Channel { recipients?: User[]; /** Icon hash */ icon?: string | null; - /** id of the DM creator */ + /** Id of the creator of the group DM or thread */ ownerId?: string; /** Application id of the group DM creator if it is bot-created */ applicationId?: string; - /** Id of the parent category for a channel (each parent category can contain up to 50 channels) */ + /** For guild channels: Id of the parent category for a channel (each parent category can contain up to 50 channels), for threads: id of the text channel this thread was created */ parentId?: string | null; /** When the last pinned message was pinned. This may be null in events such as GUILD_CREATE when a message is not pinned. */ lastPinTimestamp?: string | null; @@ -45,6 +47,14 @@ export interface Channel { rtcRegion?: string | null; /** The camera video quality mode of the voice channel, 1 when not present */ videoQualityMode?: DiscordVideoQualityModes; + /** An approximate count of messages in a thread, stops counting at 50 */ + messageCount?: number; + /** An approximate count of users in a thread, stops counting at 50 */ + memberCount?: number; + /** Thread-specifig fields not needed by other channels */ + threadMetadata?: ThreadMetadata; + /** Thread member object for the current user, if they have joined the thread, only included on certain API endpoints */ + member?: ThreadMember; } /** https://discord.com/developers/docs/resources/channel#channel-object */ From b2fbfeb08e59e45769b57a02c009f6d69b0dbc0c Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 1 May 2021 11:13:23 +0200 Subject: [PATCH 008/424] add: ListActiveThreads --- src/types/channels/list_active_threads.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/types/channels/list_active_threads.ts diff --git a/src/types/channels/list_active_threads.ts b/src/types/channels/list_active_threads.ts new file mode 100644 index 000000000..da542f7f7 --- /dev/null +++ b/src/types/channels/list_active_threads.ts @@ -0,0 +1,11 @@ +import { ThreadMember } from "../messages/thread_member.ts"; +import { Channel } from "./channel.ts"; + +export interface ListActiveThreads { + /** The active threads */ + threads: Channel[]; + /** A thread member object for each returned thread the current user has joined */ + members: ThreadMember[]; + /** Whether there are potentially additional threads that could be returned on subsequent call */ + hasMore: boolean; +} From c5eb08f9af22da24eae10057adaafb0a5e72dfe9 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 1 May 2021 11:13:31 +0200 Subject: [PATCH 009/424] add: ModifyThread --- src/types/channels/modify_thread.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/types/channels/modify_thread.ts diff --git a/src/types/channels/modify_thread.ts b/src/types/channels/modify_thread.ts new file mode 100644 index 000000000..629aea0c7 --- /dev/null +++ b/src/types/channels/modify_thread.ts @@ -0,0 +1,12 @@ +export interface ModifyThread { + /** 2-100 character thread name */ + name?: string; + /** Whether the thread is archived */ + archived?: boolean; + /** Duration in minutes to automatically archive the thread after recent activity */ + autoArchiveDuration?: 60 | 1440 | 4320 | 10080; + /** When a thread is locked, only users with `MANAGE_THREADS` can unarchive it */ + locked?: boolean; + /** Amount of seconds a user has to wait before sending another message (0-21600); bots, as well as users with the permission `MANAGE_MESSAGES`, `MANAGE_THREAD` or `MANAGE_CHANNEL` are unaffected */ + rateLimitPerUser?: number; +} From f9a516d503ac6711d88f1ce74e49d8a318a83de5 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 1 May 2021 11:13:39 +0200 Subject: [PATCH 010/424] add: StartThread --- src/types/channels/start_thread.ts | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/types/channels/start_thread.ts diff --git a/src/types/channels/start_thread.ts b/src/types/channels/start_thread.ts new file mode 100644 index 000000000..a1cf60381 --- /dev/null +++ b/src/types/channels/start_thread.ts @@ -0,0 +1,6 @@ +export interface StartThread { + /** 2-100 character thread name */ + name: string; + /** Duration in minutes to automatically archive the thread after recent activity */ + autoArchiveDuration: 60 | 1440 | 4320 | 10080; +} From dc2a3eb9f00d021b951d2f458d02207026e65309 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 1 May 2021 11:18:16 +0200 Subject: [PATCH 011/424] add: ListPublicArchivedThreads --- src/types/channels/list_public_archived_threads.ts | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/types/channels/list_public_archived_threads.ts diff --git a/src/types/channels/list_public_archived_threads.ts b/src/types/channels/list_public_archived_threads.ts new file mode 100644 index 000000000..fe5eae590 --- /dev/null +++ b/src/types/channels/list_public_archived_threads.ts @@ -0,0 +1,7 @@ +export interface ListPublicArchivedThreads { + // TODO: convert unix to ISO9601 timestamp + /** Returns threads before this timestamp. UNIX or ISO8601 timestamp */ + before?: number | string; + /** Optional maximum number of threads to return */ + limit?: number; +} From 3396f7ddc847f25d5254993054b29986dde47c96 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 1 May 2021 11:19:55 +0200 Subject: [PATCH 012/424] add: threads prop --- src/types/guilds/guild.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/types/guilds/guild.ts b/src/types/guilds/guild.ts index c346f9f22..e60d96b86 100644 --- a/src/types/guilds/guild.ts +++ b/src/types/guilds/guild.ts @@ -79,6 +79,9 @@ export interface Guild { members?: GuildMember[]; /** Channels in the guild */ channels?: Channel[]; + // TODO: check if need to omit + /** All active threads in the guild that the current user has permission to view */ + threads?: Channel[]; /** Presences of the members in the guild, will only include non-offline members if the size is greater than large threshold */ presences?: Partial[]; /** The maximum number of presences for the guild (the default value, currently 25000, is in effect when null is returned) */ From 0c875f155ebc44a5ffd3d9a31a025a43d495e5b8 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 1 May 2021 11:20:42 +0200 Subject: [PATCH 013/424] chore: bump API_VERSION to v9 --- src/util/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/constants.ts b/src/util/constants.ts index eed6df6f1..f0ee88935 100644 --- a/src/util/constants.ts +++ b/src/util/constants.ts @@ -2,7 +2,7 @@ export const BASE_URL = "https://discord.com/api"; /** https://discord.com/developers/docs/reference#api-versioning-api-versions */ -export const API_VERSION = 8; +export const API_VERSION = 9; /** https://discord.com/developers/docs/topics/gateway#gateways-gateway-versions */ export const GATEWAY_VERSION = 8; From f0e9bc86b2da2b068e1ea786df0df74cdcfc523e Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 1 May 2021 11:20:52 +0200 Subject: [PATCH 014/424] full dd version string is better --- src/util/constants.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/util/constants.ts b/src/util/constants.ts index f0ee88935..072e42d4a 100644 --- a/src/util/constants.ts +++ b/src/util/constants.ts @@ -7,8 +7,9 @@ export const API_VERSION = 9; /** https://discord.com/developers/docs/topics/gateway#gateways-gateway-versions */ export const GATEWAY_VERSION = 8; +// TODO: update this version /** https://github.com/discordeno/discordeno/releases */ -export const DISCORDENO_VERSION = 11; +export const DISCORDENO_VERSION = "v11.0.0"; /** https://discord.com/developers/docs/reference#user-agent */ export const USER_AGENT = From 7b1128a010df3eebcd68ebcbca5b93eb55bb1681 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 1 May 2021 11:44:53 +0200 Subject: [PATCH 015/424] add: docs link todo comment --- src/types/channels/list_active_threads.ts | 1 + src/types/channels/list_public_archived_threads.ts | 1 + src/types/channels/modify_thread.ts | 1 + src/types/channels/start_thread.ts | 1 + 4 files changed, 4 insertions(+) diff --git a/src/types/channels/list_active_threads.ts b/src/types/channels/list_active_threads.ts index da542f7f7..2651360f0 100644 --- a/src/types/channels/list_active_threads.ts +++ b/src/types/channels/list_active_threads.ts @@ -1,6 +1,7 @@ import { ThreadMember } from "../messages/thread_member.ts"; import { Channel } from "./channel.ts"; +// TODO: add docs link export interface ListActiveThreads { /** The active threads */ threads: Channel[]; diff --git a/src/types/channels/list_public_archived_threads.ts b/src/types/channels/list_public_archived_threads.ts index fe5eae590..95a7a2a0a 100644 --- a/src/types/channels/list_public_archived_threads.ts +++ b/src/types/channels/list_public_archived_threads.ts @@ -1,3 +1,4 @@ +// TODO: add docs link export interface ListPublicArchivedThreads { // TODO: convert unix to ISO9601 timestamp /** Returns threads before this timestamp. UNIX or ISO8601 timestamp */ diff --git a/src/types/channels/modify_thread.ts b/src/types/channels/modify_thread.ts index 629aea0c7..d261cab1d 100644 --- a/src/types/channels/modify_thread.ts +++ b/src/types/channels/modify_thread.ts @@ -1,3 +1,4 @@ +// TODO: add docs link export interface ModifyThread { /** 2-100 character thread name */ name?: string; diff --git a/src/types/channels/start_thread.ts b/src/types/channels/start_thread.ts index a1cf60381..10a5c0b02 100644 --- a/src/types/channels/start_thread.ts +++ b/src/types/channels/start_thread.ts @@ -1,3 +1,4 @@ +// TODO: add docs link export interface StartThread { /** 2-100 character thread name */ name: string; From 6cd229dcef92e31b0bd18afb8e2fe131b6f2f0d7 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 1 May 2021 11:53:18 +0200 Subject: [PATCH 016/424] add: ThreadListSync --- src/types/channels/thread_list_sync.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/types/channels/thread_list_sync.ts diff --git a/src/types/channels/thread_list_sync.ts b/src/types/channels/thread_list_sync.ts new file mode 100644 index 000000000..c5fa334d4 --- /dev/null +++ b/src/types/channels/thread_list_sync.ts @@ -0,0 +1,15 @@ +import { ThreadMember } from "../messages/thread_member.ts"; +import { Channel } from "./channel.ts"; + +// TODO: add docs link +export interface ThreadListSync { + /** The id of the guild */ + guildId: string; + /** The parent channel ids whose threads are being synced. If omitted, then threads were synced for the entire guild. This array may contain channelIds that have no active threads as well, so you know to clear that data */ + channelIds?: string[]; + // TODO: check if need to omit + /** All active threads in the given channels that the current user can access */ + threads: Channel[]; + /** All thread member objects from the synced threads for the current user, indicating which threads the current user has been added to */ + members: ThreadMember[]; +} From 3a5745143793b513ef8887444c40955c367f5e67 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 1 May 2021 11:53:27 +0200 Subject: [PATCH 017/424] add: new thread error codes --- src/types/codes/json_error_codes.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/types/codes/json_error_codes.ts b/src/types/codes/json_error_codes.ts index 69fb660f9..39c24c1a2 100644 --- a/src/types/codes/json_error_codes.ts +++ b/src/types/codes/json_error_codes.ts @@ -78,6 +78,10 @@ export enum DiscordJsonErrorCodes { InvalidApiVersionProvided = 50041, CannotDeleteAChannelRequiredForCommunityGuilds = 50074, InvalidStickerSent = 50081, + TriedToPerformAnOperationOnAnArchivedThreadSuchAsEditingAMessageOrAddingAUserToTheThread = + 50083, + InvalidThreadNotificationSettings, + BeforeValueIsEarlierThanTheThreadCreationDate, ReqctionWasBlocked = 90001, ApiResourceIsCurrentlyOverloadedTryAgainALittleLater = 130000, } From b889b518adc4554db02b98de46a6d900483837aa Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 1 May 2021 11:53:37 +0200 Subject: [PATCH 018/424] add: missing twofactor error code --- src/types/codes/json_error_codes.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/types/codes/json_error_codes.ts b/src/types/codes/json_error_codes.ts index 39c24c1a2..906828b3d 100644 --- a/src/types/codes/json_error_codes.ts +++ b/src/types/codes/json_error_codes.ts @@ -82,6 +82,7 @@ export enum DiscordJsonErrorCodes { 50083, InvalidThreadNotificationSettings, BeforeValueIsEarlierThanTheThreadCreationDate, + TwoFactorIsRequiredForThisOperation = 60003, ReqctionWasBlocked = 90001, ApiResourceIsCurrentlyOverloadedTryAgainALittleLater = 130000, } From 58edfac3b6851f0dcce9b3364b85ca322bac4160 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 1 May 2021 16:03:41 +0200 Subject: [PATCH 019/424] add: new thread perms --- src/types/permissions/bitwise_permission_flags.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/types/permissions/bitwise_permission_flags.ts b/src/types/permissions/bitwise_permission_flags.ts index cd539e5d0..c76891e99 100644 --- a/src/types/permissions/bitwise_permission_flags.ts +++ b/src/types/permissions/bitwise_permission_flags.ts @@ -65,7 +65,13 @@ export enum DiscordBitwisePermissionFlags { /** Allows members to use slash commands in text channels */ USE_SLASH_COMMANDS = 0x80000000, /** Allows for requesting to speak in stage channels. */ - REQUEST_TO_SPEAK = 0x100000000, + REQUEST_TO_SPEAK = 0x100000001, + /** Allows for deleting and archiving threads, and viewing all private threads */ + MANAGE_THREADS = 0x0400000000, + /** Allows for creating and participating in threads */ + USE_PUBLIC_THREADS = 0x0800000000, + /** Allows for creating and participating in private threads */ + USE_PRIVATE_THREADS = 0x1000000000, } export type BitwisePermissions = DiscordBitwisePermissionFlags; From bd11f3fcd0b3c10d17769261f1a4b74e81beb6a6 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 1 May 2021 16:06:55 +0200 Subject: [PATCH 020/424] change: gateway version --- src/util/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/constants.ts b/src/util/constants.ts index 072e42d4a..9e65c1929 100644 --- a/src/util/constants.ts +++ b/src/util/constants.ts @@ -5,7 +5,7 @@ export const BASE_URL = "https://discord.com/api"; export const API_VERSION = 9; /** https://discord.com/developers/docs/topics/gateway#gateways-gateway-versions */ -export const GATEWAY_VERSION = 8; +export const GATEWAY_VERSION = 9; // TODO: update this version /** https://github.com/discordeno/discordeno/releases */ From c80abf344ba9a53d150a781b11d6a5d6b448b185 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 1 May 2021 16:07:31 +0200 Subject: [PATCH 021/424] add: ThreadMembersUpdate --- src/types/channels/thread_members_update.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/types/channels/thread_members_update.ts diff --git a/src/types/channels/thread_members_update.ts b/src/types/channels/thread_members_update.ts new file mode 100644 index 000000000..8d3331683 --- /dev/null +++ b/src/types/channels/thread_members_update.ts @@ -0,0 +1,15 @@ +import { ThreadMember } from "../messages/thread_member.ts"; + +// TODO: add docs link +export interface ThreadMembersUpdate { + /** The id of the thread */ + id: string; + /** The id of the guild */ + guildId: string; + /** The approximate number of members in the thread, capped at 50 */ + memberCount: number; + /** The users who were added to the thread */ + addedMembers?: ThreadMember[]; + /** The id of the users who were removed from the thread */ + removedMemberIds?: string[]; +} From 642cf58bae72809dbb25fe73b39816e47710e1dc Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 1 May 2021 16:08:07 +0200 Subject: [PATCH 022/424] remove: v for dd version --- src/util/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/constants.ts b/src/util/constants.ts index 9e65c1929..90bb371ec 100644 --- a/src/util/constants.ts +++ b/src/util/constants.ts @@ -9,7 +9,7 @@ export const GATEWAY_VERSION = 9; // TODO: update this version /** https://github.com/discordeno/discordeno/releases */ -export const DISCORDENO_VERSION = "v11.0.0"; +export const DISCORDENO_VERSION = "11.0.0"; /** https://discord.com/developers/docs/reference#user-agent */ export const USER_AGENT = From cff1b61af5496e877edeb579b59b8b4c968726b9 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 1 May 2021 18:35:19 +0200 Subject: [PATCH 023/424] fix channel permission thing --- src/helpers/channels/clone_channel.ts | 4 +-- src/helpers/channels/create_channel.ts | 22 +++++---------- src/helpers/channels/edit_channel.ts | 13 +++++++-- src/util/permissions.ts | 38 ++++++++++++++++++-------- 4 files changed, 46 insertions(+), 31 deletions(-) diff --git a/src/helpers/channels/clone_channel.ts b/src/helpers/channels/clone_channel.ts index e84e039e0..d523572cf 100644 --- a/src/helpers/channels/clone_channel.ts +++ b/src/helpers/channels/clone_channel.ts @@ -13,8 +13,8 @@ export async function cloneChannel(channelId: string, reason?: string) { //Check for DM channel if ( - channelToClone.type === DiscordChannelTypes.DM || - channelToClone.type === DiscordChannelTypes.GROUP_DM + channelToClone.type === DiscordChannelTypes.Dm || + channelToClone.type === DiscordChannelTypes.GroupDm ) { throw new Error(Errors.CHANNEL_NOT_IN_GUILD); } diff --git a/src/helpers/channels/create_channel.ts b/src/helpers/channels/create_channel.ts index 9d675ed60..699881c5a 100644 --- a/src/helpers/channels/create_channel.ts +++ b/src/helpers/channels/create_channel.ts @@ -1,4 +1,3 @@ -import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; @@ -8,11 +7,10 @@ import { CreateGuildChannel, DiscordCreateGuildChannel, } from "../../types/guilds/create_guild_channel.ts"; -import { PermissionStrings } from "../../types/permissions/permission_strings.ts"; import { endpoints } from "../../util/constants.ts"; import { calculateBits, - requireBotGuildPermissions, + requireOverwritePermissions, } from "../../util/permissions.ts"; import { camelKeysToSnakeCase } from "../../util/utils.ts"; @@ -22,18 +20,12 @@ export async function createChannel( options?: CreateGuildChannel, reason?: string, ) { - const requiredPerms: Set = new Set(["MANAGE_CHANNELS"]); - - options?.permissionOverwrites?.forEach((overwrite) => { - eventHandlers.debug?.( - "loop", - `Running forEach loop in create_channel file.`, + if (options?.permissionOverwrites) { + await requireOverwritePermissions( + guildId, + options.permissionOverwrites, ); - overwrite.allow.forEach(requiredPerms.add, requiredPerms); - overwrite.deny.forEach(requiredPerms.add, requiredPerms); - }); - - await requireBotGuildPermissions(guildId, [...requiredPerms]); + } // BITRATES ARE IN THOUSANDS SO IF USER PROVIDES 32 WE CONVERT TO 32000 if (options?.bitrate && options.bitrate < 1000) options.bitrate *= 1000; @@ -48,7 +40,7 @@ export async function createChannel( allow: calculateBits(perm.allow), deny: calculateBits(perm.deny), })), - type: options?.type || DiscordChannelTypes.GUILD_TEXT, + type: options?.type || DiscordChannelTypes.GuildText, reason, }, ); diff --git a/src/helpers/channels/edit_channel.ts b/src/helpers/channels/edit_channel.ts index dfb064c7d..89b95f2ae 100644 --- a/src/helpers/channels/edit_channel.ts +++ b/src/helpers/channels/edit_channel.ts @@ -1,20 +1,27 @@ import { eventHandlers } from "../../bot.ts"; +import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { ModifyChannel } from "../../types/channels/modify_channel.ts"; import { Channel } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { calculateBits, - requireBotChannelPermissions, + requireOverwritePermissions, } from "../../util/permissions.ts"; - +//TODO: implement DM group channel edit /** Update a channel's settings. Requires the `MANAGE_CHANNELS` permission for the guild. */ export async function editChannel( channelId: string, options: ModifyChannel, reason?: string, ) { - await requireBotChannelPermissions(channelId, ["MANAGE_CHANNELS"]); + const channel = await cacheHandlers.get("channels", channelId); + if (channel?.guildId) { + await requireOverwritePermissions( + channel.guildId, + options.permissionOverwrites || [], + ); + } if (options.name || options.topic) { const request = editChannelNameTopicQueue.get(channelId); diff --git a/src/util/permissions.ts b/src/util/permissions.ts index 90e187562..2a2bf61b5 100644 --- a/src/util/permissions.ts +++ b/src/util/permissions.ts @@ -4,6 +4,7 @@ import { DiscordenoChannel } from "../structures/channel.ts"; import { DiscordenoGuild } from "../structures/guild.ts"; import { DiscordenoMember } from "../structures/member.ts"; import { DiscordenoRole } from "../structures/role.ts"; +import { Overwrite } from "../types/channels/overwrite.ts"; import { Errors } from "../types/misc/errors.ts"; import { DiscordBitwisePermissionFlags } from "../types/permissions/bitwise_permission_flags.ts"; import { PermissionStrings } from "../types/permissions/permission_strings.ts"; @@ -28,11 +29,6 @@ async function getCached( ? // @ts-ignore TS is wrong here await cacheHandlers.get(table, key) : key; - if (!cached || typeof cached === "string") { - throw new Error( - Errors[`${table.slice(0, -1).toUpperCase()}_NOT_FOUND` as Errors], - ); - } return typeof cached === "string" ? undefined : cached; } @@ -50,7 +46,7 @@ export async function calculateBasePermissions( let permissions = 0n; // Calculate the role permissions bits, @everyone role is not in memberRoleIds so we need to pass guildId manualy permissions |= [...(member.guilds.get(guild.id)?.roles || []), guild.id] - .map((id) => (guild as DiscordenoGuild).roles.get(id)?.permissions) + .map((id) => guild.roles.get(id)?.permissions) // Removes any edge case undefined .filter((perm) => perm) .reduce((bits, perms) => { @@ -76,7 +72,7 @@ export async function calculateChannelOverwrites( const member = await getCached("members", memberOrId); - if (!member) return "8"; + if (!channel || !member) return "8"; // Get all the role permissions this member already has let permissions = BigInt( @@ -84,7 +80,7 @@ export async function calculateChannelOverwrites( ); // First calculate @everyone overwrites since these have the lowest priority - const overwriteEveryone = channel?.permissionOverwrites?.find( + const overwriteEveryone = channel.permissionOverwrites.find( (overwrite) => overwrite.id === (channel as DiscordenoChannel).guildId, ); if (overwriteEveryone) { @@ -93,7 +89,7 @@ export async function calculateChannelOverwrites( permissions |= BigInt(overwriteEveryone.allow); } - const overwrites = channel?.permissionOverwrites; + const overwrites = channel.permissionOverwrites; // In order to calculate the role permissions correctly we need to temporarily save the allowed and denied permissions let allow = 0n; @@ -111,8 +107,8 @@ export async function calculateChannelOverwrites( permissions |= allow; // Third calculate member specific overwrites since these have the highest priority - const overwriteMember = overwrites?.find( - (overwrite) => overwrite.id === (member as DiscordenoMember).id, + const overwriteMember = overwrites.find( + (overwrite) => overwrite.id === member.id, ); if (overwriteMember) { permissions &= ~BigInt(overwriteMember.deny); @@ -290,6 +286,26 @@ export function calculateBits(permissions: PermissionStrings[]) { .toString(); } +/** Internal function to check if the bot has the permissions to set these overwrites */ +export async function requireOverwritePermissions( + guildOrId: string | DiscordenoGuild, + overwrites: Overwrite[], +) { + let requiredPerms: Set = new Set(["MANAGE_CHANNELS"]); + + overwrites?.forEach((overwrite) => { + overwrite.allow.forEach(requiredPerms.add, requiredPerms); + overwrite.deny.forEach(requiredPerms.add, requiredPerms); + }); + + // MANAGE_ROLES permission can only be set by administrators + if (requiredPerms.has("MANAGE_ROLES")) { + requiredPerms = new Set(["ADMINISTRATOR"]); + } + + await requireGuildPermissions(guildOrId, botId, [...requiredPerms]); +} + /** Gets the highest role from the member in this guild */ export async function highestRole( guildOrId: string | DiscordenoGuild, From 8032133ad44f0b8fa71601d1952a4d7ef104bfec Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 1 May 2021 18:35:27 +0200 Subject: [PATCH 024/424] Update permissions.ts --- src/util/permissions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/permissions.ts b/src/util/permissions.ts index 2a2bf61b5..c7290c0b5 100644 --- a/src/util/permissions.ts +++ b/src/util/permissions.ts @@ -81,7 +81,7 @@ export async function calculateChannelOverwrites( // First calculate @everyone overwrites since these have the lowest priority const overwriteEveryone = channel.permissionOverwrites.find( - (overwrite) => overwrite.id === (channel as DiscordenoChannel).guildId, + (overwrite) => overwrite.id === channel.guildId, ); if (overwriteEveryone) { // First remove denied permissions since denied < allowed From 51095db12fe9180d63ae101ebfab98be9334211d Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 1 May 2021 18:39:20 +0200 Subject: [PATCH 025/424] fix my renaming thing --- src/handlers/channels/CHANNEL_DELETE.ts | 2 +- src/helpers/channels/start_typing.ts | 6 +++--- src/helpers/messages/send_message.ts | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/handlers/channels/CHANNEL_DELETE.ts b/src/handlers/channels/CHANNEL_DELETE.ts index f4c07229f..8da02b9a0 100644 --- a/src/handlers/channels/CHANNEL_DELETE.ts +++ b/src/handlers/channels/CHANNEL_DELETE.ts @@ -11,7 +11,7 @@ export async function handleChannelDelete(data: DiscordGatewayPayload) { if (!cachedChannel) return; if ( - cachedChannel.type === DiscordChannelTypes.GUILD_VOICE && payload.guildId + cachedChannel.type === DiscordChannelTypes.GuildVoice && payload.guildId ) { const guild = await cacheHandlers.get("guilds", payload.guildId); diff --git a/src/helpers/channels/start_typing.ts b/src/helpers/channels/start_typing.ts index 013ad46e2..4bd2b5163 100644 --- a/src/helpers/channels/start_typing.ts +++ b/src/helpers/channels/start_typing.ts @@ -16,9 +16,9 @@ export async function startTyping(channelId: string) { if (channel) { if ( ![ - DiscordChannelTypes.DM, - DiscordChannelTypes.GUILD_NEWS, - DiscordChannelTypes.GUILD_TEXT, + DiscordChannelTypes.Dm, + DiscordChannelTypes.GuildNews, + DiscordChannelTypes.GuildText, ].includes(channel.type) ) { throw new Error(Errors.CHANNEL_NOT_TEXT_BASED); diff --git a/src/helpers/messages/send_message.ts b/src/helpers/messages/send_message.ts index 87dd3eb20..716d079d5 100644 --- a/src/helpers/messages/send_message.ts +++ b/src/helpers/messages/send_message.ts @@ -26,9 +26,9 @@ export async function sendMessage( if (channel) { if ( ![ - DiscordChannelTypes.DM, - DiscordChannelTypes.GUILD_NEWS, - DiscordChannelTypes.GUILD_TEXT, + DiscordChannelTypes.Dm, + DiscordChannelTypes.GuildNews, + DiscordChannelTypes.GuildText, ].includes(channel.type) ) { throw new Error(Errors.CHANNEL_NOT_TEXT_BASED); From eda4895da32d2d4366b47a4711dd5255dd17e0f4 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 1 May 2021 18:42:46 +0200 Subject: [PATCH 026/424] more fixxes --- src/types/channels/channel_types.ts | 2 +- tests/channels/category_children.ts | 6 ++--- .../channel_overwrite_has_permission.ts | 2 +- tests/channels/clone_channel.ts | 8 +++--- tests/channels/create_channel.ts | 26 +++++++++---------- tests/channels/delete_channel_overwrite.ts | 2 +- tests/channels/edit_channel_overwrite.ts | 2 +- tests/channels/is_channel_synced.ts | 10 +++---- 8 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/types/channels/channel_types.ts b/src/types/channels/channel_types.ts index 7c0b9247d..26a3ce5e4 100644 --- a/src/types/channels/channel_types.ts +++ b/src/types/channels/channel_types.ts @@ -21,7 +21,7 @@ export enum DiscordChannelTypes { /** A temporary sub-channel within a GUILD_TEXT channel that is only viewable by those invited and those with the MANAGE_THREADS permission */ GuildPivateThread, /** A voice channel for hosting events with an audience */ - GUILD_STAGE_VOICE = 13, + GuildStageVoice = 13, } export type ChannelTypes = DiscordChannelTypes; diff --git a/tests/channels/category_children.ts b/tests/channels/category_children.ts index 1c5b6d555..78901d894 100644 --- a/tests/channels/category_children.ts +++ b/tests/channels/category_children.ts @@ -1,16 +1,16 @@ -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; -import { assertExists } from "../deps.ts"; import { cache } from "../../src/cache.ts"; import { categoryChildren, createChannel } from "../../src/helpers/mod.ts"; import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts"; +import { assertExists } from "../deps.ts"; import { delayUntil } from "../util/delay_until.ts"; +import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; Deno.test({ name: "[channel] category channel ids", async fn() { const category = await createChannel(tempData.guildId, { name: "Discordeno-test", - type: DiscordChannelTypes.GUILD_CATEGORY, + type: DiscordChannelTypes.GuildCategory, }); // Assertions diff --git a/tests/channels/channel_overwrite_has_permission.ts b/tests/channels/channel_overwrite_has_permission.ts index 55319ac60..d8d9dd367 100644 --- a/tests/channels/channel_overwrite_has_permission.ts +++ b/tests/channels/channel_overwrite_has_permission.ts @@ -15,7 +15,7 @@ async function ifItFailsBlameWolf(options: CreateGuildChannel, _save = false) { // Assertions assertExists(channel); - assertEquals(channel.type, options.type || DiscordChannelTypes.GUILD_TEXT); + assertEquals(channel.type, options.type || DiscordChannelTypes.GuildText); // Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed await delayUntil(10000, () => cache.channels.has(channel.id)); diff --git a/tests/channels/clone_channel.ts b/tests/channels/clone_channel.ts index 4708d6687..ca639abb6 100644 --- a/tests/channels/clone_channel.ts +++ b/tests/channels/clone_channel.ts @@ -61,7 +61,7 @@ Deno.test({ await ifItFailsBlameWolf( { name: "Discordeno-clone-test", - type: DiscordChannelTypes.GUILD_CATEGORY, + type: DiscordChannelTypes.GuildCategory, }, false, ); @@ -75,7 +75,7 @@ Deno.test({ await ifItFailsBlameWolf( { name: "Discordeno-clone-test", - type: DiscordChannelTypes.GUILD_VOICE, + type: DiscordChannelTypes.GuildVoice, }, false, ); @@ -89,7 +89,7 @@ Deno.test({ await ifItFailsBlameWolf( { name: "discordeno-clone-test", - type: DiscordChannelTypes.GUILD_VOICE, + type: DiscordChannelTypes.GuildVoice, bitrate: 32000, }, false, @@ -104,7 +104,7 @@ Deno.test({ await ifItFailsBlameWolf( { name: "Discordeno-clone-test", - type: DiscordChannelTypes.GUILD_VOICE, + type: DiscordChannelTypes.GuildVoice, userLimit: 32, }, false, diff --git a/tests/channels/create_channel.ts b/tests/channels/create_channel.ts index 02c952fb4..f01fd7b31 100644 --- a/tests/channels/create_channel.ts +++ b/tests/channels/create_channel.ts @@ -1,19 +1,19 @@ -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; -import { assertEquals, assertExists } from "../deps.ts"; -import { cache } from "../../src/cache.ts"; -import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts"; -import { CreateGuildChannel } from "../../src/types/guilds/create_guild_channel.ts"; -import { createChannel } from "../../src/helpers/channels/create_channel.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts"; import { botId } from "../../src/bot.ts"; +import { cache } from "../../src/cache.ts"; +import { createChannel } from "../../src/helpers/channels/create_channel.ts"; +import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts"; +import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts"; +import { CreateGuildChannel } from "../../src/types/guilds/create_guild_channel.ts"; +import { assertEquals, assertExists } from "../deps.ts"; +import { delayUntil } from "../util/delay_until.ts"; +import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) { const channel = await createChannel(tempData.guildId, options); // Assertions assertExists(channel); - assertEquals(channel.type, options.type || DiscordChannelTypes.GUILD_TEXT); + assertEquals(channel.type, options.type || DiscordChannelTypes.GuildText); if (save) tempData.channelId = channel.id; @@ -60,7 +60,7 @@ Deno.test({ await ifItFailsBlameWolf( { name: "Discordeno-test", - type: DiscordChannelTypes.GUILD_CATEGORY, + type: DiscordChannelTypes.GuildCategory, }, true, ); @@ -90,7 +90,7 @@ Deno.test({ await ifItFailsBlameWolf( { name: "Discordeno-test", - type: DiscordChannelTypes.GUILD_VOICE, + type: DiscordChannelTypes.GuildVoice, }, true, ); @@ -104,7 +104,7 @@ Deno.test({ await ifItFailsBlameWolf( { name: "discordeno-test", - type: DiscordChannelTypes.GUILD_VOICE, + type: DiscordChannelTypes.GuildVoice, bitrate: 32000, }, true, @@ -119,7 +119,7 @@ Deno.test({ await ifItFailsBlameWolf( { name: "Discordeno-test", - type: DiscordChannelTypes.GUILD_VOICE, + type: DiscordChannelTypes.GuildVoice, userLimit: 32, }, true, diff --git a/tests/channels/delete_channel_overwrite.ts b/tests/channels/delete_channel_overwrite.ts index acf63c7a9..8b5b4f02a 100644 --- a/tests/channels/delete_channel_overwrite.ts +++ b/tests/channels/delete_channel_overwrite.ts @@ -14,7 +14,7 @@ async function ifItFailsBlameWolf(options: CreateGuildChannel, _save = false) { // Assertions assertExists(channel); - assertEquals(channel.type, options.type || DiscordChannelTypes.GUILD_TEXT); + assertEquals(channel.type, options.type || DiscordChannelTypes.GuildText); // Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed await delayUntil(10000, () => cache.channels.has(channel.id)); diff --git a/tests/channels/edit_channel_overwrite.ts b/tests/channels/edit_channel_overwrite.ts index f8a9ad241..1ed56a038 100644 --- a/tests/channels/edit_channel_overwrite.ts +++ b/tests/channels/edit_channel_overwrite.ts @@ -16,7 +16,7 @@ async function ifItFailsBlameWolf(options: CreateGuildChannel, _save = false) { // Assertions assertExists(channel); - assertEquals(channel.type, options.type || DiscordChannelTypes.GUILD_TEXT); + assertEquals(channel.type, options.type || DiscordChannelTypes.GuildText); // Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed await delayUntil(10000, () => cache.channels.has(channel.id)); diff --git a/tests/channels/is_channel_synced.ts b/tests/channels/is_channel_synced.ts index eac621f6a..78f9c30a7 100644 --- a/tests/channels/is_channel_synced.ts +++ b/tests/channels/is_channel_synced.ts @@ -1,19 +1,19 @@ +import { botId } from "../../src/bot.ts"; import { cache } from "../../src/cache.ts"; import { createChannel } from "../../src/helpers/channels/create_channel.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { assertEquals, assertExists } from "../deps.ts"; import { isChannelSynced } from "../../src/helpers/channels/is_channel_synced.ts"; import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts"; -import { botId } from "../../src/bot.ts"; import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts"; +import { assertEquals, assertExists } from "../deps.ts"; +import { delayUntil } from "../util/delay_until.ts"; +import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; Deno.test({ name: "[channel] is channel synced.", async fn() { const category = await createChannel(tempData.guildId, { name: "synced-category", - type: DiscordChannelTypes.GUILD_CATEGORY, + type: DiscordChannelTypes.GuildCategory, permissionOverwrites: [ { id: botId, From 152654bd448c2b7c9cfd6f729d3982f62bc4333f Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 1 May 2021 18:48:40 +0200 Subject: [PATCH 027/424] only run coverage report for main branch --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cfbb40471..ac5e2dbe1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,8 +23,10 @@ jobs: if: ${{ github.event_name == 'pull_request' && github.event.action == 'labeled' && github.event.label.name == 'run-tests' }} run: DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} deno test --unstable --coverage=coverage --allow-net tests/mod.ts - name: Create coverage report + if: github.ref == 'refs/heads/main' run: deno --unstable coverage ./coverage --lcov > coverage.lcov - name: Collect and upload the coverage report + if: github.ref == 'refs/heads/main' uses: codecov/codecov-action@v1.0.10 with: file: ./coverage.lcov From 9e6620a171c0ddc3025d9f9567c28d248a5f0816 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 1 May 2021 20:37:23 +0100 Subject: [PATCH 028/424] fix(types): file param is optional --- src/types/webhooks/edit_webhook_message.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/webhooks/edit_webhook_message.ts b/src/types/webhooks/edit_webhook_message.ts index 4076c5cb8..6317c70fe 100644 --- a/src/types/webhooks/edit_webhook_message.ts +++ b/src/types/webhooks/edit_webhook_message.ts @@ -10,7 +10,7 @@ export interface EditWebhookMessage { /** Embedded `rich` content */ embeds?: Embed[] | null; /** The contents of the file being sent/edited */ - file: FileContent | FileContent[]; + file?: FileContent | FileContent[]; /** Allowed mentions for the message */ allowedMentions?: AllowedMentions | null; /** Attached files to keep */ From b0758e7094671e08e57c473d823f17e073073233 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 1 May 2021 22:38:41 +0200 Subject: [PATCH 029/424] Update permissions.ts --- src/util/permissions.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/permissions.ts b/src/util/permissions.ts index c7290c0b5..44ca9dd7a 100644 --- a/src/util/permissions.ts +++ b/src/util/permissions.ts @@ -80,7 +80,7 @@ export async function calculateChannelOverwrites( ); // First calculate @everyone overwrites since these have the lowest priority - const overwriteEveryone = channel.permissionOverwrites.find( + const overwriteEveryone = channel.permissionOverwrites?.find( (overwrite) => overwrite.id === channel.guildId, ); if (overwriteEveryone) { @@ -107,7 +107,7 @@ export async function calculateChannelOverwrites( permissions |= allow; // Third calculate member specific overwrites since these have the highest priority - const overwriteMember = overwrites.find( + const overwriteMember = overwrites?.find( (overwrite) => overwrite.id === member.id, ); if (overwriteMember) { From 9cd6b963da4f3c1730fe8150a25a7f96f87f5a8b Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 1 May 2021 22:38:49 +0200 Subject: [PATCH 030/424] add: hasOwnProperty --- src/util/utils.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/util/utils.ts b/src/util/utils.ts index 6a2b9a240..0b64e826f 100644 --- a/src/util/utils.ts +++ b/src/util/utils.ts @@ -204,3 +204,13 @@ export function validateSlashCommands( } } } + +// Typescript is not so good as we developers so we need this little utility function to help it out +// Taken from https://fettblog.eu/typescript-hasownproperty/ +/** TS save way to check if a property exists in an object */ +export function hasOwnProperty( + obj: T, + prop: Y, +): obj is T & Record { + return obj.hasOwnProperty(prop); +} From d60ccae805741363c804aa77dfef38b5ecd07cb6 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 1 May 2021 23:35:43 +0200 Subject: [PATCH 031/424] fix(types): channel.permissionOverwrites can be undefined --- src/helpers/channels/clone_channel.ts | 2 +- src/structures/channel.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/helpers/channels/clone_channel.ts b/src/helpers/channels/clone_channel.ts index d523572cf..d881a5373 100644 --- a/src/helpers/channels/clone_channel.ts +++ b/src/helpers/channels/clone_channel.ts @@ -24,7 +24,7 @@ export async function cloneChannel(channelId: string, reason?: string) { name: channelToClone.name!, topic: channelToClone.topic || undefined, parentId: channelToClone.parentId || undefined, - permissionOverwrites: channelToClone.permissionOverwrites.map(( + permissionOverwrites: channelToClone.permissionOverwrites?.map(( overwrite, ) => ({ id: overwrite.id, diff --git a/src/structures/channel.ts b/src/structures/channel.ts index b71bfc596..b20da7122 100644 --- a/src/structures/channel.ts +++ b/src/structures/channel.ts @@ -109,7 +109,7 @@ export async function createDiscordenoChannel( export interface DiscordenoChannel extends Omit { - permissionOverwrites: DiscordOverwrite[]; + permissionOverwrites?: DiscordOverwrite[]; guildId: string; // GETTERS From 8840ed5662886a8393545096a922017ee4edb2b7 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 1 May 2021 23:36:17 +0200 Subject: [PATCH 032/424] changed: moved thread types to channel/threads --- .../channels/{ => threads}/list_active_threads.ts | 0 .../{ => threads}/list_public_archived_threads.ts | 0 src/types/channels/{ => threads}/modify_thread.ts | 0 src/types/channels/{ => threads}/start_thread.ts | 0 .../channels/{ => threads}/thread_list_sync.ts | 0 src/types/channels/threads/thread_member.ts | 10 ++++++++++ .../channels/{ => threads}/thread_members_update.ts | 0 src/types/channels/threads/thread_metadata.ts | 13 +++++++++++++ 8 files changed, 23 insertions(+) rename src/types/channels/{ => threads}/list_active_threads.ts (100%) rename src/types/channels/{ => threads}/list_public_archived_threads.ts (100%) rename src/types/channels/{ => threads}/modify_thread.ts (100%) rename src/types/channels/{ => threads}/start_thread.ts (100%) rename src/types/channels/{ => threads}/thread_list_sync.ts (100%) create mode 100644 src/types/channels/threads/thread_member.ts rename src/types/channels/{ => threads}/thread_members_update.ts (100%) create mode 100644 src/types/channels/threads/thread_metadata.ts diff --git a/src/types/channels/list_active_threads.ts b/src/types/channels/threads/list_active_threads.ts similarity index 100% rename from src/types/channels/list_active_threads.ts rename to src/types/channels/threads/list_active_threads.ts diff --git a/src/types/channels/list_public_archived_threads.ts b/src/types/channels/threads/list_public_archived_threads.ts similarity index 100% rename from src/types/channels/list_public_archived_threads.ts rename to src/types/channels/threads/list_public_archived_threads.ts diff --git a/src/types/channels/modify_thread.ts b/src/types/channels/threads/modify_thread.ts similarity index 100% rename from src/types/channels/modify_thread.ts rename to src/types/channels/threads/modify_thread.ts diff --git a/src/types/channels/start_thread.ts b/src/types/channels/threads/start_thread.ts similarity index 100% rename from src/types/channels/start_thread.ts rename to src/types/channels/threads/start_thread.ts diff --git a/src/types/channels/thread_list_sync.ts b/src/types/channels/threads/thread_list_sync.ts similarity index 100% rename from src/types/channels/thread_list_sync.ts rename to src/types/channels/threads/thread_list_sync.ts diff --git a/src/types/channels/threads/thread_member.ts b/src/types/channels/threads/thread_member.ts new file mode 100644 index 000000000..2b3d1b54a --- /dev/null +++ b/src/types/channels/threads/thread_member.ts @@ -0,0 +1,10 @@ +export interface ThreadMember { + /** The id of the thread */ + id: string; + /** The id of the user */ + userId: string; + /** The time the current user last joined the thread */ + joinTimestamp: string; + /** Any user-thread settings, currently only used for notifications */ + flags: number; +} diff --git a/src/types/channels/thread_members_update.ts b/src/types/channels/threads/thread_members_update.ts similarity index 100% rename from src/types/channels/thread_members_update.ts rename to src/types/channels/threads/thread_members_update.ts diff --git a/src/types/channels/threads/thread_metadata.ts b/src/types/channels/threads/thread_metadata.ts new file mode 100644 index 000000000..ea67fd966 --- /dev/null +++ b/src/types/channels/threads/thread_metadata.ts @@ -0,0 +1,13 @@ +export interface ThreadMetadata { + /** Whether the thread is archived */ + archived: boolean; + /** Id of the user that last archived or unarchived the thread */ + archiverId?: string; + /** Duration in minutes to automatically archive the thread after recent activity */ + autoArchiveDuration: 60 | 1440 | 4320 | 10080; + // TODO(threads): channel struct should convert this to a unixx + /** Timestamp when the thread's archive status was last changed, used for calculating recent activity */ + archiveTimestamp: string; + /** When a thread is locked, only users with `MANAGE_THREADS` can unarchive it */ + locked?: boolean; +} From 478952d9ebe4094c7d9dddb726c3b9860c176e77 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 1 May 2021 23:36:59 +0200 Subject: [PATCH 033/424] fix(helpers/messages): sendMessage add new thread types to channel type check --- src/helpers/messages/send_message.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/helpers/messages/send_message.ts b/src/helpers/messages/send_message.ts index 716d079d5..b05d5d424 100644 --- a/src/helpers/messages/send_message.ts +++ b/src/helpers/messages/send_message.ts @@ -29,6 +29,9 @@ export async function sendMessage( DiscordChannelTypes.Dm, DiscordChannelTypes.GuildNews, DiscordChannelTypes.GuildText, + DiscordChannelTypes.GuildPublicThread, + DiscordChannelTypes.GuildPivateThread, + DiscordChannelTypes.GuildNewsThread, ].includes(channel.type) ) { throw new Error(Errors.CHANNEL_NOT_TEXT_BASED); From 8fa98b49706e7a8e8cc585f391932883b01aaeed Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 1 May 2021 23:37:05 +0200 Subject: [PATCH 034/424] Update channel.ts --- src/types/channels/channel.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/types/channels/channel.ts b/src/types/channels/channel.ts index 15caecb29..9277d7366 100644 --- a/src/types/channels/channel.ts +++ b/src/types/channels/channel.ts @@ -1,8 +1,8 @@ -import { ThreadMember } from "../messages/thread_member.ts"; -import { ThreadMetadata } from "../messages/thread_metadata.ts"; import { User } from "../users/user.ts"; import { DiscordChannelTypes } from "./channel_types.ts"; import { Overwrite } from "./overwrite.ts"; +import { ThreadMember } from "./threads/thread_member.ts"; +import { ThreadMetadata } from "./threads/thread_metadata.ts"; import { DiscordVideoQualityModes } from "./video_quality_modes.ts"; /** https://discord.com/developers/docs/resources/channel#channel-object */ @@ -47,6 +47,7 @@ export interface Channel { rtcRegion?: string | null; /** The camera video quality mode of the voice channel, 1 when not present */ videoQualityMode?: DiscordVideoQualityModes; + // TODO(threads): consider a ThreadChannel object /** An approximate count of messages in a thread, stops counting at 50 */ messageCount?: number; /** An approximate count of users in a thread, stops counting at 50 */ From 8a974511c94c4c6cd3461ed9894c57ca8e5ab7a1 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 1 May 2021 23:37:10 +0200 Subject: [PATCH 035/424] fmt --- src/types/messages/message.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/messages/message.ts b/src/types/messages/message.ts index de3956f0a..1cb9d416a 100644 --- a/src/types/messages/message.ts +++ b/src/types/messages/message.ts @@ -1,5 +1,6 @@ import { Channel } from "../channels/channel.ts"; import { ChannelMention } from "../channels/channel_mention.ts"; +import { ThreadMember } from "../channels/threads/thread_member.ts"; import { Embed } from "../embeds/embed.ts"; import { GuildMember } from "../guilds/guild_member.ts"; import { MessageInteraction } from "../interactions/message_interaction.ts"; @@ -12,7 +13,6 @@ import { MessageReference } from "./message_reference.ts"; import { MessageSticker } from "./message_sticker.ts"; import { DiscordMessageTypes } from "./message_types.ts"; import { Reaction } from "./reaction.ts"; -import { ThreadMember } from "./thread_member.ts"; /** https://discord.com/developers/docs/resources/channel#message-object */ export interface Message { From 95fdb6b064173cda675b9dabcef6b92e2a558677 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 1 May 2021 23:37:19 +0200 Subject: [PATCH 036/424] idk --- src/types/messages/thread_member.ts | 10 ---------- src/types/messages/thread_metadata.ts | 12 ------------ 2 files changed, 22 deletions(-) delete mode 100644 src/types/messages/thread_member.ts delete mode 100644 src/types/messages/thread_metadata.ts diff --git a/src/types/messages/thread_member.ts b/src/types/messages/thread_member.ts deleted file mode 100644 index 2b3d1b54a..000000000 --- a/src/types/messages/thread_member.ts +++ /dev/null @@ -1,10 +0,0 @@ -export interface ThreadMember { - /** The id of the thread */ - id: string; - /** The id of the user */ - userId: string; - /** The time the current user last joined the thread */ - joinTimestamp: string; - /** Any user-thread settings, currently only used for notifications */ - flags: number; -} diff --git a/src/types/messages/thread_metadata.ts b/src/types/messages/thread_metadata.ts deleted file mode 100644 index ce8f40e56..000000000 --- a/src/types/messages/thread_metadata.ts +++ /dev/null @@ -1,12 +0,0 @@ -export interface ThreadMetadata { - /** Whether the thread is archived */ - archived: boolean; - /** Id of the user that last archived or unarchived the thread */ - archiverId?: string; - /** Duration in minutes to automatically archive the thread after recent activity */ - autoArchiveDuration: 60 | 1440 | 4320 | 10080; - /** Timestamp when the thread's archive status was last changed, used for calculating recent activity */ - archiveTimestamp: string; - /** When a thread is locked, only users with `MANAGE_THREADS` can unarchive it */ - locked?: boolean; -} From 9ff0c2c6933b6a49f0c24b759ad0cfe5d88b4abd Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 1 May 2021 23:37:26 +0200 Subject: [PATCH 037/424] Update utils.ts --- src/util/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/utils.ts b/src/util/utils.ts index 0b64e826f..d2c0a016d 100644 --- a/src/util/utils.ts +++ b/src/util/utils.ts @@ -208,7 +208,7 @@ export function validateSlashCommands( // Typescript is not so good as we developers so we need this little utility function to help it out // Taken from https://fettblog.eu/typescript-hasownproperty/ /** TS save way to check if a property exists in an object */ -export function hasOwnProperty( +export function hasOwnProperty( obj: T, prop: Y, ): obj is T & Record { From dfe822f4d2dcd3e09a35cf5ba6b4c5f39831df83 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sun, 2 May 2021 00:35:16 +0200 Subject: [PATCH 038/424] fix(types): messageId is optional --- src/types/discordeno/edit_webhook_message.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/types/discordeno/edit_webhook_message.ts b/src/types/discordeno/edit_webhook_message.ts index 97ee0af14..f0cc429f2 100644 --- a/src/types/discordeno/edit_webhook_message.ts +++ b/src/types/discordeno/edit_webhook_message.ts @@ -1,6 +1,6 @@ import { EditWebhookMessage } from "../webhooks/edit_webhook_message.ts"; export interface DiscordenoEditWebhookMessage extends EditWebhookMessage { - /** Id of the message you want to edit */ - messageId: string; + /** Id of the message you want to edit if undefined the initial response message will be edited */ + messageId?: string; } From 6f7ade244a16f734b0cfbd2b781048b3011bccbe Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sun, 2 May 2021 12:34:47 +0200 Subject: [PATCH 039/424] add: thread channel support --- src/helpers/channels/edit_channel.ts | 82 ++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 22 deletions(-) diff --git a/src/helpers/channels/edit_channel.ts b/src/helpers/channels/edit_channel.ts index 89b95f2ae..3a6e83be1 100644 --- a/src/helpers/channels/edit_channel.ts +++ b/src/helpers/channels/edit_channel.ts @@ -2,28 +2,68 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { ModifyChannel } from "../../types/channels/modify_channel.ts"; -import { Channel } from "../../types/mod.ts"; +import { ModifyThread } from "../../types/channels/threads/modify_thread.ts"; +import { + Channel, + DiscordChannelTypes, + PermissionStrings, +} from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { calculateBits, + requireBotChannelPermissions, requireOverwritePermissions, } from "../../util/permissions.ts"; +import { camelKeysToSnakeCase, hasOwnProperty } from "../../util/utils.ts"; + //TODO: implement DM group channel edit /** Update a channel's settings. Requires the `MANAGE_CHANNELS` permission for the guild. */ export async function editChannel( channelId: string, - options: ModifyChannel, + options: ModifyChannel | ModifyThread, reason?: string, ) { const channel = await cacheHandlers.get("channels", channelId); - if (channel?.guildId) { - await requireOverwritePermissions( - channel.guildId, - options.permissionOverwrites || [], - ); + + if (channel) { + if ( + [ + DiscordChannelTypes.GuildNewsThread, + DiscordChannelTypes.GuildPivateThread, + DiscordChannelTypes.GuildPublicThread, + ].includes(channel.type) + ) { + const permissions = new Set(); + + if (hasOwnProperty(options, "archive") && options.archive === false) { + permissions.add("SEND_MESSAGES"); + } + + // TODO(threads): change this to a better check + // hacky way of checking if more is being modified + if (Object.keys(options).length > 1) { + permissions.add("MANAGE_THREADS"); + } + + await requireBotChannelPermissions(channel.parentId ?? "", [ + ...permissions, + ]); + } + + if ( + hasOwnProperty( + options, + "permissionOverwrites", + ) && Array.isArray(options.permissionOverwrites) + ) { + await requireOverwritePermissions( + channel.guildId, + options.permissionOverwrites, + ); + } } - if (options.name || options.topic) { + if (options.name || (options as ModifyChannel).topic) { const request = editChannelNameTopicQueue.get(channelId); if (!request) { // If this hasnt been done before simply add 1 for it @@ -49,21 +89,18 @@ export async function editChannel( } const payload = { - ...options, + ...camelKeysToSnakeCase<{}>(options), // deno-lint-ignore camelcase - rate_limit_per_user: options.rateLimitPerUser, - // deno-lint-ignore camelcase - parent_id: options.parentId, - // deno-lint-ignore camelcase - user_limit: options.userLimit, - // deno-lint-ignore camelcase - permission_overwrites: options.permissionOverwrites?.map((overwrite) => { - return { - ...overwrite, - allow: calculateBits(overwrite.allow), - deny: calculateBits(overwrite.deny), - }; - }), + permission_overwrites: + hasOwnProperty(options, "permissionOverwrites") + ? options.permissionOverwrites?.map((overwrite) => { + return { + ...overwrite, + allow: calculateBits(overwrite.allow), + deny: calculateBits(overwrite.deny), + }; + }) + : undefined, }; return await rest.runMethod( @@ -87,6 +124,7 @@ interface EditChannelRequest { } const editChannelNameTopicQueue = new Map(); + let editChannelProcessing = false; function processEditChannelQueue() { From 64606025ece6014d2f3cab769c45881a33a25bf0 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sun, 2 May 2021 13:37:07 +0200 Subject: [PATCH 040/424] add: delete thread functionality --- src/helpers/channels/delete_channel.ts | 33 ++++++++++++++++++-------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/helpers/channels/delete_channel.ts b/src/helpers/channels/delete_channel.ts index d934c8944..23441cb1c 100644 --- a/src/helpers/channels/delete_channel.ts +++ b/src/helpers/channels/delete_channel.ts @@ -1,26 +1,39 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { Errors } from "../../types/misc/errors.ts"; +import { ChannelTypes } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; 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, reason?: string, -): Promise { - await requireBotGuildPermissions(guildId, ["MANAGE_CHANNELS"]); +) { + const channel = await cacheHandlers.get("channels", channelId); - const guild = await cacheHandlers.get("guilds", guildId); - if (!guild) throw new Error(Errors.GUILD_NOT_FOUND); + if (channel?.guildId) { + const guild = await cacheHandlers.get("guilds", channel.guildId); + if (!guild) throw new Error(Errors.GUILD_NOT_FOUND); - if (guild?.rulesChannelId === channelId) { - throw new Error(Errors.RULES_CHANNEL_CANNOT_BE_DELETED); - } + // TODO(threads): check if this requires guild perms or channel is enough + await requireBotGuildPermissions( + guild, + [ + ChannelTypes.GuildNewsThread, + ChannelTypes.GuildPivateThread, + ChannelTypes.GuildPublicThread, + ].includes(channel.type) + ? ["MANAGE_THREADS"] + : ["MANAGE_CHANNELS"], + ); + if (guild.rulesChannelId === channelId) { + throw new Error(Errors.RULES_CHANNEL_CANNOT_BE_DELETED); + } - if (guild?.publicUpdatesChannelId === channelId) { - throw new Error(Errors.UPDATES_CHANNEL_CANNOT_BE_DELETED); + if (guild.publicUpdatesChannelId === channelId) { + throw new Error(Errors.UPDATES_CHANNEL_CANNOT_BE_DELETED); + } } return await rest.runMethod( From 86af3a089cbd3e73ac74a6e652dc89af6504d9f3 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sun, 2 May 2021 13:42:15 +0200 Subject: [PATCH 041/424] add: START_THREAD endpoint --- src/util/constants.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/util/constants.ts b/src/util/constants.ts index 90bb371ec..fae7f4e48 100644 --- a/src/util/constants.ts +++ b/src/util/constants.ts @@ -78,6 +78,10 @@ export const endpoints = { // Bots SHALL NOT use this endpoint but they can CHANNEL_TYPING: (channelId: string) => `${CHANNEL_BASE(channelId)}/typing`, + // Thread Endpoints + START_THREAD: (channelId: string, messageId: string) => + `${endpoints.CHANNEL_MESSAGE(channelId, messageId)}/threads`, + // Guild Endpoints GUILDS: `${baseEndpoints.BASE_URL}/guilds`, GUILD_AUDIT_LOGS: (guildId: string) => `${GUILDS_BASE(guildId)}/audit-logs`, From b5f5b0caf6cf21b8ca1fec02ce4f63fbdc2fd7d5 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sun, 2 May 2021 14:39:27 +0200 Subject: [PATCH 042/424] add: more thread endpoints --- src/util/constants.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/util/constants.ts b/src/util/constants.ts index fae7f4e48..c5a566383 100644 --- a/src/util/constants.ts +++ b/src/util/constants.ts @@ -79,8 +79,26 @@ export const endpoints = { CHANNEL_TYPING: (channelId: string) => `${CHANNEL_BASE(channelId)}/typing`, // Thread Endpoints - START_THREAD: (channelId: string, messageId: string) => + THREAD_START_PUBLIC: (channelId: string, messageId: string) => `${endpoints.CHANNEL_MESSAGE(channelId, messageId)}/threads`, + THREAD_START_PRIVATE: (channelId: string) => + `${CHANNEL_BASE(channelId)}/threads`, + THREAD_ACTIVE: (channelId: string) => + `${CHANNEL_BASE(channelId)}/threads/active`, + THREAD_MEMBERS: (channelId: string) => + `${CHANNEL_BASE(channelId)}/thread-members`, + THREAD_ME: (channelId: string) => + `${endpoints.THREAD_MEMBERS(channelId)}/@me`, + THREAD_USER: (channelId: string, userId: string) => + `${endpoints.THREAD_MEMBERS(channelId)}/${userId}`, + THREAD_ARCHIVED_BASE: (channelId: string) => + `${CHANNEL_BASE(channelId)}/archived`, + THREAD_ARCHIVED_PUBLIC: (channelId: string) => + `${endpoints.THREAD_ARCHIVED_BASE(channelId)}/public`, + THREAD_ARCHIVED_PRIVATE: (channelId: string) => + `${endpoints.THREAD_ARCHIVED_BASE(channelId)}/private`, + THREAD_ARCHIVED_PRIVATE_JOINED: (channelId: string) => + `${CHANNEL_BASE(channelId)}/users/@me/threads/archived/private`, // Guild Endpoints GUILDS: `${baseEndpoints.BASE_URL}/guilds`, From 02b9d7188f98ea81e2a1c841839c291bd1029780 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sun, 2 May 2021 16:35:11 +0200 Subject: [PATCH 043/424] Update edit_channel.ts --- src/helpers/channels/edit_channel.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/helpers/channels/edit_channel.ts b/src/helpers/channels/edit_channel.ts index 3a6e83be1..cc8119c81 100644 --- a/src/helpers/channels/edit_channel.ts +++ b/src/helpers/channels/edit_channel.ts @@ -17,6 +17,7 @@ import { import { camelKeysToSnakeCase, hasOwnProperty } from "../../util/utils.ts"; //TODO: implement DM group channel edit +//TODO(threads): check thread perms /** Update a channel's settings. Requires the `MANAGE_CHANNELS` permission for the guild. */ export async function editChannel( channelId: string, From 4faeab8bac8145c2b074bc9ee3a9c74b9bd677ea Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sun, 2 May 2021 16:35:26 +0200 Subject: [PATCH 044/424] add: startThread --- src/helpers/channels/threads/start_thread.ts | 38 ++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/helpers/channels/threads/start_thread.ts diff --git a/src/helpers/channels/threads/start_thread.ts b/src/helpers/channels/threads/start_thread.ts new file mode 100644 index 000000000..5fe429c22 --- /dev/null +++ b/src/helpers/channels/threads/start_thread.ts @@ -0,0 +1,38 @@ +import { cacheHandlers } from "../../../cache.ts"; +import { rest } from "../../../rest/rest.ts"; +import { ChannelTypes } from "../../../types/channels/channel_types.ts"; +import { StartThread } from "../../../types/channels/threads/start_thread.ts"; +import { Errors } from "../../../types/misc/errors.ts"; +import { endpoints } from "../../../util/constants.ts"; +import { camelKeysToSnakeCase } from "../../../util/utils.ts"; + +/** + * Creates a new public thread from an existing message. Returns a channel on success, and a 400 BAD REQUEST on invalid parameters. Fires a Thread Create Gateway event. + * @param messageId when provided the thread will be public + */ +export async function startThread( + channelId: string, + options: StartThread & { messageId?: string }, +) { + const channel = await cacheHandlers.get("channels", channelId); + if (channel) { + // TODO(threads): perm check + if ( + ![ChannelTypes.GuildText, ChannelTypes.GuildNews].includes(channel.type) + ) { + throw new Error(Errors.INVALID_THREAD_PARENT_CHANNEL_TYPE); + } + + if (!options.messageId && channel.type === ChannelTypes.GuildNews) { + throw new Error(Errors.GUILD_NEWS_CHANNEL_ONLY_SUPPORT_PUBLIC_THREADS); + } + } + + return rest.runMethod( + "post", + options?.messageId + ? endpoints.THREAD_START_PUBLIC(channelId, options.messageId) + : endpoints.THREAD_START_PRIVATE(channelId), + camelKeysToSnakeCase(options), + ); +} From 8c23b88dc51add10b99e34ad6ae5ccbc2b951a84 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sun, 2 May 2021 17:17:11 +0200 Subject: [PATCH 045/424] add: removeFromThread --- .../channels/threads/remove_from_thread.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/helpers/channels/threads/remove_from_thread.ts diff --git a/src/helpers/channels/threads/remove_from_thread.ts b/src/helpers/channels/threads/remove_from_thread.ts new file mode 100644 index 000000000..7cf250275 --- /dev/null +++ b/src/helpers/channels/threads/remove_from_thread.ts @@ -0,0 +1,29 @@ +import { cacheHandlers } from "../../../cache.ts"; +import { rest } from "../../../rest/rest.ts"; +import { ChannelTypes } from "../../../types/channels/channel_types.ts"; +import { Errors } from "../../../types/misc/errors.ts"; +import { endpoints } from "../../../util/constants.ts"; + +/** Removes another user from a thread. Requires the MANAGE_THREADS permission or that you are the creator of the thread. Also requires the thread is not archived. Returns a 204 empty response on success. Fires a Thread Members Update Gateway event. */ +export async function removeFromThread(channelId: string, userId?: string) { + // TODO(threads): perm check + const channel = await cacheHandlers.get("channels", channelId); + if (channel) { + if ( + ![ + ChannelTypes.GuildNewsThread, + ChannelTypes.GuildPivateThread, + ChannelTypes.GuildPublicThread, + ].includes(channel.type) + ) { + throw new Error(Errors.NOT_A_THREAD_CHANNEL); + } + } + + return await rest.runMethod( + "delete", + userId + ? endpoints.THREAD_USER(channelId, userId) + : endpoints.THREAD_ME(channelId), + ); +} From 28e407ca03307e07fc36f345865896c3176ac495 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sun, 2 May 2021 17:17:17 +0200 Subject: [PATCH 046/424] add: getThreadMembers --- .../channels/threads/get_thread_members.ts | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/helpers/channels/threads/get_thread_members.ts diff --git a/src/helpers/channels/threads/get_thread_members.ts b/src/helpers/channels/threads/get_thread_members.ts new file mode 100644 index 000000000..b56b0f576 --- /dev/null +++ b/src/helpers/channels/threads/get_thread_members.ts @@ -0,0 +1,26 @@ +import { cacheHandlers } from "../../../cache.ts"; +import { rest } from "../../../rest/rest.ts"; +import { ChannelTypes } from "../../../types/channels/channel_types.ts"; +import { Errors } from "../../../types/misc/errors.ts"; +import { endpoints } from "../../../util/constants.ts"; + +// TODO(threads): it seems like the documented return type is wrong +/** Returns array of thread members objects that are members of the thread. */ +export async function getThreadMembers(channelId: string) { + // TODO(threads): perm check + // TODO(threads): intents check + const channel = await cacheHandlers.get("channels", channelId); + if (channel) { + if ( + ![ + ChannelTypes.GuildNewsThread, + ChannelTypes.GuildPivateThread, + ChannelTypes.GuildPublicThread, + ].includes(channel.type) + ) { + throw new Error(Errors.NOT_A_THREAD_CHANNEL); + } + } + + return await rest.runMethod("get", endpoints.THREAD_MEMBERS(channelId)); +} From f0ea01b502cf52e7a141914c73571561e915bb21 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sun, 2 May 2021 18:20:57 +0200 Subject: [PATCH 047/424] add: getArchivedThreads --- .../channels/threads/get_archived_threads.ts | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/helpers/channels/threads/get_archived_threads.ts diff --git a/src/helpers/channels/threads/get_archived_threads.ts b/src/helpers/channels/threads/get_archived_threads.ts new file mode 100644 index 000000000..50229b260 --- /dev/null +++ b/src/helpers/channels/threads/get_archived_threads.ts @@ -0,0 +1,24 @@ +import { rest } from "../../../rest/rest.ts"; +import { ListPublicArchivedThreads } from "../../../types/channels/threads/list_public_archived_threads.ts"; +import { endpoints } from "../../../util/constants.ts"; +import { camelKeysToSnakeCase } from "../../../util/utils.ts"; + +export async function getArchivedThreads( + channelId: string, + options?: ListPublicArchivedThreads & { + type?: "public" | "private" | "privateJoinedThreads"; + }, +) { + // TODO(threads): perm check + // TODO(threads): check if this works + + return await rest.runMethod( + "get", + options?.type === "privateJoinedThreads" + ? endpoints.THREAD_ARCHIVED_PRIVATE_JOINED(channelId) + : options?.type === "private" + ? endpoints.THREAD_ARCHIVED_PRIVATE(channelId) + : endpoints.THREAD_ARCHIVED_PUBLIC(channelId), + camelKeysToSnakeCase(options ?? {}), + ); +} From a33193fa92c8bc006b309abf06af35636954606f Mon Sep 17 00:00:00 2001 From: rigormorrtiss Date: Sun, 2 May 2021 20:56:13 +0400 Subject: [PATCH 048/424] remove(types): privateChannels field from Ready (#890) * refactor(types): remove privateChannels field from Ready BREAKING: since Tuesday, 6 April 2021, private_channels field has been undocumented by @night. Reference commit: https://github.com/discord/discord-api-docs/commit/f36156dbb641f5c4d4f4593f345bfd6e27fdee08 --- src/types/gateway/ready.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/types/gateway/ready.ts b/src/types/gateway/ready.ts index e5aafb694..36d7b7c99 100644 --- a/src/types/gateway/ready.ts +++ b/src/types/gateway/ready.ts @@ -9,8 +9,6 @@ export interface Ready { v: number; /** Information about the user including email */ user: User; - /** Empty array */ - privateChannels: []; /** The guilds the user is in */ guilds: UnavailableGuild[]; /** Used for resuming connections */ From ee164bff22599c7b39ef75770432e1ae3f8451b0 Mon Sep 17 00:00:00 2001 From: rigormorrtiss Date: Sun, 2 May 2021 20:57:18 +0400 Subject: [PATCH 049/424] remove(types): System user flag (#889) Reference: https://github.com/discord/discord-api-docs/commit/9293f0d490ac6acf9d627e429e5a8131b303b528 BREAKING: The flag "System" has been removed from the documentation on 9 April 2021 --- src/types/users/user_flags.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/types/users/user_flags.ts b/src/types/users/user_flags.ts index 49e2dbbdd..8db567ab2 100644 --- a/src/types/users/user_flags.ts +++ b/src/types/users/user_flags.ts @@ -10,7 +10,6 @@ export enum DiscordUserFlags { HouseBalance = 1 << 8, EarlySupporter = 1 << 9, TeamUser = 1 << 10, - System = 1 << 12, BugHunterLevel2 = 1 << 14, VerifiedBot = 1 << 16, EarlyVerifiedBotDeveloper = 1 << 17, From 5a74c3cb8e236a747bedcdc212e2ce9f93908a04 Mon Sep 17 00:00:00 2001 From: rigormorrtiss Date: Sun, 2 May 2021 21:22:12 +0400 Subject: [PATCH 050/424] feat(types): add 30037 code to JSON error codes enum Reference: https://github.com/discord/discord-api-docs/pull/2869 --- src/types/codes/json_error_codes.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/types/codes/json_error_codes.ts b/src/types/codes/json_error_codes.ts index 8efd3f186..1d05ebb74 100644 --- a/src/types/codes/json_error_codes.ts +++ b/src/types/codes/json_error_codes.ts @@ -44,6 +44,7 @@ export enum DiscordJsonErrorCodes { MaximumNumberOfGuildDiscoverySubcategoriesHasBeenReached = 30030, GuildAlreadyHasTemplate = 30031, MaximumNumberOfBansForNonGuildMembersHaveBeenExceeded = 30035, + MaximumNumberOfBansFetchesHasBeenReached = 30037, UnauthorizedProvideAValidTokenAndTryAgain = 40001, YouNeedToVerifyYourAccountInOrderToPerformThisAction, RequestEntityTooLargeTrySendingSomethingSmallerInSize = 40005, From 1b7c777aa31c5489c1cca76a30c0da17e6df343e Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sun, 2 May 2021 20:50:46 +0200 Subject: [PATCH 051/424] Update CHANNEL_UPDATE.ts --- src/handlers/channels/CHANNEL_UPDATE.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/handlers/channels/CHANNEL_UPDATE.ts b/src/handlers/channels/CHANNEL_UPDATE.ts index 1045545c5..57ff9af3e 100644 --- a/src/handlers/channels/CHANNEL_UPDATE.ts +++ b/src/handlers/channels/CHANNEL_UPDATE.ts @@ -7,11 +7,10 @@ import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; export async function handleChannelUpdate(data: DiscordGatewayPayload) { const payload = data.d as Channel; const cachedChannel = await cacheHandlers.get("channels", payload.id); + if (!cachedChannel) return; const discordenoChannel = await structures.createDiscordenoChannel(payload); await cacheHandlers.set("channels", discordenoChannel.id, discordenoChannel); - if (!cachedChannel) return; - eventHandlers.channelUpdate?.(discordenoChannel, cachedChannel); } From b148c67b6cd299ce2e3fd12cc16561a0e13ce5c1 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sun, 2 May 2021 20:50:58 +0200 Subject: [PATCH 052/424] add: THREAD_CREATE event handler --- src/handlers/channels/THREAD_CREATE.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/handlers/channels/THREAD_CREATE.ts diff --git a/src/handlers/channels/THREAD_CREATE.ts b/src/handlers/channels/THREAD_CREATE.ts new file mode 100644 index 000000000..ac24436b5 --- /dev/null +++ b/src/handlers/channels/THREAD_CREATE.ts @@ -0,0 +1,14 @@ +import { eventHandlers } from "../../bot.ts"; +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"; + +export async function handleThreadCreate(data: DiscordGatewayPayload) { + const payload = data.d as Channel; + + const discordenoChannel = await structures.createDiscordenoChannel(payload); + await cacheHandlers.set("channels", discordenoChannel.id, discordenoChannel); + + eventHandlers.threadCreate?.(discordenoChannel); +} From 5e747a8cdf4ddb246696868f2cf2584fc4220c70 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sun, 2 May 2021 20:51:09 +0200 Subject: [PATCH 053/424] add: THREAD_UPDATE event handler --- src/handlers/channels/THREAD_UPDATE.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/handlers/channels/THREAD_UPDATE.ts diff --git a/src/handlers/channels/THREAD_UPDATE.ts b/src/handlers/channels/THREAD_UPDATE.ts new file mode 100644 index 000000000..fac23b833 --- /dev/null +++ b/src/handlers/channels/THREAD_UPDATE.ts @@ -0,0 +1,16 @@ +import { eventHandlers } from "../../bot.ts"; +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"; + +export async function handleThreadUpdate(data: DiscordGatewayPayload) { + const payload = data.d as Channel; + const oldChannel = await cacheHandlers.get("channels", payload.id); + if (!oldChannel) return; + + const discordenoChannel = await structures.createDiscordenoChannel(payload); + await cacheHandlers.set("channels", discordenoChannel.id, discordenoChannel); + + eventHandlers.threadUpdate?.(discordenoChannel, oldChannel); +} From efd52e9c9b265adedd2b94910d360403a0e3d1f3 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sun, 2 May 2021 20:51:39 +0200 Subject: [PATCH 054/424] fix: thread channels have own prop --- src/structures/guild.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/structures/guild.ts b/src/structures/guild.ts index 562440c25..3d36eb213 100644 --- a/src/structures/guild.ts +++ b/src/structures/guild.ts @@ -118,6 +118,7 @@ export async function createDiscordenoGuild( memberCount = 0, voiceStates = [], channels = [], + threads = [], presences = [], joinedAt = "", emojis, @@ -131,7 +132,7 @@ export async function createDiscordenoGuild( ), ); - await Promise.all(channels.map(async (channel) => { + await Promise.all([...channels, ...threads].map(async (channel) => { const discordenoChannel = await structures.createDiscordenoChannel( channel, rest.id, From cd0a86d831a3097768ea69008e2475be2c7b4a1c Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sun, 2 May 2021 20:51:48 +0200 Subject: [PATCH 055/424] add: some thread errors --- src/types/misc/errors.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/types/misc/errors.ts b/src/types/misc/errors.ts index ee55755c0..34c50ccea 100644 --- a/src/types/misc/errors.ts +++ b/src/types/misc/errors.ts @@ -18,6 +18,11 @@ export enum Errors { MEMBER_SEARCH_LIMIT_TOO_LOW = "MEMBER_SEARCH_LIMIT_TOO_LOW", PRUNE_MAX_DAYS = "PRUNE_MAX_DAYS", ROLE_NOT_FOUND = "ROLE_NOT_FOUND", + // Thread errors + INVALID_THREAD_PARENT_CHANNEL_TYPE = "INVALID_THREAD_PARENT_CHANNEL_TYPE", + GUILD_NEWS_CHANNEL_ONLY_SUPPORT_PUBLIC_THREADS = + "GUILD_NEWS_CHANNEL_ONLY_SUPPORT_PUBLIC_THREADS", + NOT_A_THREAD_CHANNEL = "NOT_A_THREAD_CHANNEL", // Message Delete Errors DELETE_MESSAGES_MIN = "DELETE_MESSAGES_MIN", PRUNE_MIN_DAYS = "PRUNE_MIN_DAYS", From 59bc25fd67e2bbbc368b2c3d53c776f7f6734992 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sun, 2 May 2021 20:52:05 +0200 Subject: [PATCH 056/424] fix: THREAD_ARCHIVED_BASE constant missing threads/ --- src/util/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/constants.ts b/src/util/constants.ts index c5a566383..d8367493c 100644 --- a/src/util/constants.ts +++ b/src/util/constants.ts @@ -92,7 +92,7 @@ export const endpoints = { THREAD_USER: (channelId: string, userId: string) => `${endpoints.THREAD_MEMBERS(channelId)}/${userId}`, THREAD_ARCHIVED_BASE: (channelId: string) => - `${CHANNEL_BASE(channelId)}/archived`, + `${CHANNEL_BASE(channelId)}/threads/archived`, THREAD_ARCHIVED_PUBLIC: (channelId: string) => `${endpoints.THREAD_ARCHIVED_BASE(channelId)}/public`, THREAD_ARCHIVED_PRIVATE: (channelId: string) => From a094a1e7bd04520293f4e3cfbec8683db1ffbfb0 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sun, 2 May 2021 20:59:16 +0200 Subject: [PATCH 057/424] add: THREAD_DELETE event handler --- src/handlers/channels/THREAD_DELETE.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/handlers/channels/THREAD_DELETE.ts diff --git a/src/handlers/channels/THREAD_DELETE.ts b/src/handlers/channels/THREAD_DELETE.ts new file mode 100644 index 000000000..8452cba2b --- /dev/null +++ b/src/handlers/channels/THREAD_DELETE.ts @@ -0,0 +1,24 @@ +import { eventHandlers } from "../../bot.ts"; +import { cacheHandlers } from "../../cache.ts"; +import { Channel } from "../../types/channels/channel.ts"; +import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; + +export async function handleThreadDelete(data: DiscordGatewayPayload) { + const payload = data.d as Channel; + + const cachedChannel = await cacheHandlers.get("channels", payload.id); + if (!cachedChannel) return; + + await cacheHandlers.delete("channels", payload.id); + cacheHandlers.forEach("messages", (message) => { + eventHandlers.debug?.( + "loop", + `Running forEach messages loop in CHANNEL_DELTE file.`, + ); + if (message.channelId === payload.id) { + cacheHandlers.delete("messages", message.id); + } + }); + + eventHandlers.channelDelete?.(cachedChannel); +} From 3fb9c805000c95feb70209fd1f3b6a5ad5d4875e Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sun, 2 May 2021 20:59:40 +0200 Subject: [PATCH 058/424] fix: unnecessary messages loop for non message channels --- src/handlers/channels/CHANNEL_DELETE.ts | 29 +++++++++++++++++-------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/handlers/channels/CHANNEL_DELETE.ts b/src/handlers/channels/CHANNEL_DELETE.ts index 8da02b9a0..0fc3bdd45 100644 --- a/src/handlers/channels/CHANNEL_DELETE.ts +++ b/src/handlers/channels/CHANNEL_DELETE.ts @@ -30,15 +30,26 @@ export async function handleChannelDelete(data: DiscordGatewayPayload) { } } + if ( + [ + DiscordChannelTypes.GuildText, + DiscordChannelTypes.Dm, + DiscordChannelTypes.GroupDm, + DiscordChannelTypes.GuildNews, + ].includes(payload.type) + ) { + cacheHandlers.forEach("messages", (message) => { + eventHandlers.debug?.( + "loop", + `Running forEach messages loop in CHANNEL_DELTE file.`, + ); + if (message.channelId === payload.id) { + cacheHandlers.delete("messages", message.id); + } + }); + } + await cacheHandlers.delete("channels", payload.id); - cacheHandlers.forEach("messages", (message) => { - eventHandlers.debug?.( - "loop", - `Running forEach messages loop in CHANNEL_DELTE file.`, - ); - if (message.channelId === payload.id) { - cacheHandlers.delete("messages", message.id); - } - }); + eventHandlers.channelDelete?.(cachedChannel); } From df03334464a10e7610ad82b06014c5e3ff6d33e6 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sun, 2 May 2021 21:06:36 +0200 Subject: [PATCH 059/424] use correct event handler function --- src/handlers/channels/THREAD_DELETE.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/handlers/channels/THREAD_DELETE.ts b/src/handlers/channels/THREAD_DELETE.ts index 8452cba2b..7de3d61ed 100644 --- a/src/handlers/channels/THREAD_DELETE.ts +++ b/src/handlers/channels/THREAD_DELETE.ts @@ -20,5 +20,5 @@ export async function handleThreadDelete(data: DiscordGatewayPayload) { } }); - eventHandlers.channelDelete?.(cachedChannel); + eventHandlers.threadDelete?.(cachedChannel); } From 48606a67c664a2a4b67404c6ee831f62a8f1f633 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sun, 2 May 2021 21:06:49 +0200 Subject: [PATCH 060/424] fix: file move imports --- src/types/channels/threads/list_active_threads.ts | 4 ++-- src/types/channels/threads/thread_list_sync.ts | 4 ++-- src/types/channels/threads/thread_members_update.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/types/channels/threads/list_active_threads.ts b/src/types/channels/threads/list_active_threads.ts index 2651360f0..55753d444 100644 --- a/src/types/channels/threads/list_active_threads.ts +++ b/src/types/channels/threads/list_active_threads.ts @@ -1,5 +1,5 @@ -import { ThreadMember } from "../messages/thread_member.ts"; -import { Channel } from "./channel.ts"; +import { Channel } from "../channel.ts"; +import { ThreadMember } from "./thread_member.ts"; // TODO: add docs link export interface ListActiveThreads { diff --git a/src/types/channels/threads/thread_list_sync.ts b/src/types/channels/threads/thread_list_sync.ts index c5fa334d4..2c905a907 100644 --- a/src/types/channels/threads/thread_list_sync.ts +++ b/src/types/channels/threads/thread_list_sync.ts @@ -1,5 +1,5 @@ -import { ThreadMember } from "../messages/thread_member.ts"; -import { Channel } from "./channel.ts"; +import { Channel } from "../channel.ts"; +import { ThreadMember } from "./thread_member.ts"; // TODO: add docs link export interface ThreadListSync { diff --git a/src/types/channels/threads/thread_members_update.ts b/src/types/channels/threads/thread_members_update.ts index 8d3331683..2190f6297 100644 --- a/src/types/channels/threads/thread_members_update.ts +++ b/src/types/channels/threads/thread_members_update.ts @@ -1,4 +1,4 @@ -import { ThreadMember } from "../messages/thread_member.ts"; +import { ThreadMember } from "./thread_member.ts"; // TODO: add docs link export interface ThreadMembersUpdate { From 4f591320be466cfe00bf0f6b50ed78e55136cf21 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sun, 2 May 2021 21:26:08 +0200 Subject: [PATCH 061/424] add: THREAD_LIST_SYNC handlere --- src/handlers/channels/THREAD_LIST_SYNC.ts | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/handlers/channels/THREAD_LIST_SYNC.ts diff --git a/src/handlers/channels/THREAD_LIST_SYNC.ts b/src/handlers/channels/THREAD_LIST_SYNC.ts new file mode 100644 index 000000000..659769d99 --- /dev/null +++ b/src/handlers/channels/THREAD_LIST_SYNC.ts @@ -0,0 +1,34 @@ +import { eventHandlers } from "../../bot.ts"; +import { cacheHandlers } from "../../cache.ts"; +import { DiscordenoChannel } from "../../structures/channel.ts"; +import { structures } from "../../structures/mod.ts"; +import { ThreadListSync } from "../../types/channels/threads/thread_list_sync.ts"; +import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import { Collection } from "../../util/collection.ts"; + +export async function handleThreadListSync(data: DiscordGatewayPayload) { + const payload = data.d as ThreadListSync; + + const discordenoChannels = await Promise.all( + payload.threads.map(async (thread) => { + const discordenoChannel = await structures.createDiscordenoChannel( + thread, + payload.guildId, + ); + + await cacheHandlers.set( + "channels", + discordenoChannel.id, + discordenoChannel, + ); + + return discordenoChannel; + }), + ); + + const threads = new Collection( + discordenoChannels.map((t) => [t.id, t]), + ); + + eventHandlers.threadListSync?.(threads, payload.members, payload.guildId); +} From 2396ba2ce437f877f60b73d32859214e27b55e32 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sun, 2 May 2021 21:30:26 +0200 Subject: [PATCH 062/424] deno lint stupid --- src/helpers/channels/edit_channel.ts | 2 +- src/util/utils.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/helpers/channels/edit_channel.ts b/src/helpers/channels/edit_channel.ts index cc8119c81..5319b171b 100644 --- a/src/helpers/channels/edit_channel.ts +++ b/src/helpers/channels/edit_channel.ts @@ -90,7 +90,7 @@ export async function editChannel( } const payload = { - ...camelKeysToSnakeCase<{}>(options), + ...camelKeysToSnakeCase>(options), // deno-lint-ignore camelcase permission_overwrites: hasOwnProperty(options, "permissionOverwrites") diff --git a/src/util/utils.ts b/src/util/utils.ts index d2c0a016d..af2d605b1 100644 --- a/src/util/utils.ts +++ b/src/util/utils.ts @@ -208,9 +208,11 @@ export function validateSlashCommands( // Typescript is not so good as we developers so we need this little utility function to help it out // Taken from https://fettblog.eu/typescript-hasownproperty/ /** TS save way to check if a property exists in an object */ +// deno-lint-ignore ban-types export function hasOwnProperty( obj: T, prop: Y, ): obj is T & Record { + // deno-lint-ignore no-prototype-builtins return obj.hasOwnProperty(prop); } From 81e70dc4ff5005b73fea14dadd6aa6200e16bf6a Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sun, 2 May 2021 21:34:18 +0200 Subject: [PATCH 063/424] guild id has been removed --- tests/channels/delete_channel.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/channels/delete_channel.ts b/tests/channels/delete_channel.ts index d2b46cb05..41a8a4be3 100644 --- a/tests/channels/delete_channel.ts +++ b/tests/channels/delete_channel.ts @@ -1,8 +1,8 @@ import { cache } from "../../src/cache.ts"; import { createChannel } from "../../src/helpers/channels/create_channel.ts"; import { deleteChannel } from "../../src/helpers/channels/delete_channel.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; import { delayUntil } from "../util/delay_until.ts"; +import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; Deno.test({ name: "[channel] delete a channel without a reason.", @@ -51,7 +51,7 @@ Deno.test({ } // Delete the channel now without a reason - await deleteChannel(tempData.guildId, channel.id, "with a reason"); + await deleteChannel(channel.id, "with a reason"); // wait 5 seconds to give it time for CHANNEL_DELETE event await delayUntil(10000, () => !cache.channels.has(channel.id)); // Make sure it is gone from cache From 5240981d61d36487de4c1d09d033e93f653a4a88 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sun, 2 May 2021 21:36:36 +0200 Subject: [PATCH 064/424] this too --- src/structures/channel.ts | 6 +++--- tests/channels/delete_channel.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/structures/channel.ts b/src/structures/channel.ts index b20da7122..56f50dc05 100644 --- a/src/structures/channel.ts +++ b/src/structures/channel.ts @@ -49,8 +49,8 @@ const baseChannel: Partial = { disconnect(memberId) { return disconnectMember(this.guildId!, memberId); }, - delete() { - return deleteChannel(this.guildId!, this.id!); + delete(reason) { + return deleteChannel(this.id!, reason); }, editOverwrite(id, options) { return editChannelOverwrite(this.guildId!, this.id!, id, options); @@ -147,7 +147,7 @@ export interface DiscordenoChannel /** Disconnect a member from a voice channel. Requires MOVE_MEMBERS permission. */ disconnect(memberID: string): ReturnType; /** Delete the channel */ - delete(): ReturnType; + delete(reason?: string): ReturnType; /** Edit a channel Overwrite */ editOverwrite( overwriteID: string, diff --git a/tests/channels/delete_channel.ts b/tests/channels/delete_channel.ts index 41a8a4be3..57cb9c986 100644 --- a/tests/channels/delete_channel.ts +++ b/tests/channels/delete_channel.ts @@ -21,7 +21,7 @@ Deno.test({ } // Delete the channel now without a reason - await deleteChannel(tempData.guildId, channel.id); + await deleteChannel(channel.id); // wait 5 seconds to give it time for CHANNEL_DELETE event await delayUntil(3000, () => !cache.channels.has(channel.id)); // Make sure it is gone from cache 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 065/424] 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