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/148] 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/148] 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/148] 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/148] 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/148] 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/148] 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/148] 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/148] 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/148] 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/148] 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/148] 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/148] 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/148] 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/148] 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/148] 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/148] 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/148] 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/148] 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/148] 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/148] 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/148] 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/148] 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/148] 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/148] 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/148] 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/148] 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/148] 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 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 028/148] 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 029/148] 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 030/148] 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 031/148] 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 032/148] 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 033/148] 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 034/148] 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 035/148] 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 036/148] 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 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 037/148] 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 038/148] 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 039/148] 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 040/148] 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 041/148] 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 042/148] 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 043/148] 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 044/148] 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 045/148] 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 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 046/148] 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 047/148] 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 048/148] 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 049/148] 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 050/148] 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 051/148] 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 052/148] 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 053/148] 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 054/148] 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 055/148] 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 056/148] 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 057/148] 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 058/148] 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 059/148] 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 7f7273ed2e6df635e68f78ab9d37d74aaddd6ed2 Mon Sep 17 00:00:00 2001 From: itohatweb Date: Mon, 3 May 2021 18:51:15 +0000 Subject: [PATCH 060/148] Commit from GitHub Actions (Lint) --- src/util/mod.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/mod.ts b/src/util/mod.ts index fe2efd7b1..9af7e2b53 100644 --- a/src/util/mod.ts +++ b/src/util/mod.ts @@ -4,4 +4,4 @@ export * from "./constants.ts"; export * from "./loop_object.ts"; export * from "./permissions.ts"; export * from "./utils.ts"; -export * from "./validate_length.ts"; \ No newline at end of file +export * from "./validate_length.ts"; From 6afe31ad553de04aa3b0182bbc966ee20f78c261 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 3 May 2021 21:19:44 +0200 Subject: [PATCH 061/148] add: handleThreadMemberUpdate --- src/handlers/channels/THREAD_MEMBER_UPDATE.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/handlers/channels/THREAD_MEMBER_UPDATE.ts diff --git a/src/handlers/channels/THREAD_MEMBER_UPDATE.ts b/src/handlers/channels/THREAD_MEMBER_UPDATE.ts new file mode 100644 index 000000000..a25490523 --- /dev/null +++ b/src/handlers/channels/THREAD_MEMBER_UPDATE.ts @@ -0,0 +1,20 @@ +import { eventHandlers } from "../../bot.ts"; +import { cacheHandlers } from "../../cache.ts"; +import { ThreadMember } from "../../types/channels/threads/thread_member.ts"; +import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; + +export async function handleThreadMemberUpdate(data: DiscordGatewayPayload) { + const payload = data.d as ThreadMember; + const thread = await cacheHandlers.get( + "channels", + snowflakeToBigint(payload.id), + ); + if (!thread) return; + + thread.member = payload; + + await cacheHandlers.set("channels", thread.id, thread); + + eventHandlers.threadMemberUpdate?.(payload); +} From 09474864110ecd59089852aa5057d7edf1f6480e Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 3 May 2021 21:19:53 +0200 Subject: [PATCH 062/148] fix: now bigint --- src/util/constants.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/util/constants.ts b/src/util/constants.ts index 90f10e4d3..71e17f1e9 100644 --- a/src/util/constants.ts +++ b/src/util/constants.ts @@ -79,25 +79,25 @@ export const endpoints = { CHANNEL_TYPING: (channelId: bigint) => `${CHANNEL_BASE(channelId)}/typing`, // Thread Endpoints - THREAD_START_PUBLIC: (channelId: string, messageId: string) => + THREAD_START_PUBLIC: (channelId: bigint, messageId: bigint) => `${endpoints.CHANNEL_MESSAGE(channelId, messageId)}/threads`, - THREAD_START_PRIVATE: (channelId: string) => + THREAD_START_PRIVATE: (channelId: bigint) => `${CHANNEL_BASE(channelId)}/threads`, - THREAD_ACTIVE: (channelId: string) => + THREAD_ACTIVE: (channelId: bigint) => `${CHANNEL_BASE(channelId)}/threads/active`, - THREAD_MEMBERS: (channelId: string) => + THREAD_MEMBERS: (channelId: bigint) => `${CHANNEL_BASE(channelId)}/thread-members`, - THREAD_ME: (channelId: string) => + THREAD_ME: (channelId: bigint) => `${endpoints.THREAD_MEMBERS(channelId)}/@me`, - THREAD_USER: (channelId: string, userId: string) => + THREAD_USER: (channelId: bigint, userId: bigint) => `${endpoints.THREAD_MEMBERS(channelId)}/${userId}`, - THREAD_ARCHIVED_BASE: (channelId: string) => + THREAD_ARCHIVED_BASE: (channelId: bigint) => `${CHANNEL_BASE(channelId)}/threads/archived`, - THREAD_ARCHIVED_PUBLIC: (channelId: string) => + THREAD_ARCHIVED_PUBLIC: (channelId: bigint) => `${endpoints.THREAD_ARCHIVED_BASE(channelId)}/public`, - THREAD_ARCHIVED_PRIVATE: (channelId: string) => + THREAD_ARCHIVED_PRIVATE: (channelId: bigint) => `${endpoints.THREAD_ARCHIVED_BASE(channelId)}/private`, - THREAD_ARCHIVED_PRIVATE_JOINED: (channelId: string) => + THREAD_ARCHIVED_PRIVATE_JOINED: (channelId: bigint) => `${CHANNEL_BASE(channelId)}/users/@me/threads/archived/private`, // Guild Endpoints From c0a2c520a5a5d17b4b1febca7cb8e8696ac79b24 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 3 May 2021 21:21:51 +0200 Subject: [PATCH 063/148] fix: bigint now --- src/helpers/channels/threads/get_archived_threads.ts | 2 +- src/helpers/channels/threads/get_thread_members.ts | 2 +- src/helpers/channels/threads/remove_from_thread.ts | 2 +- src/helpers/channels/threads/start_thread.ts | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/helpers/channels/threads/get_archived_threads.ts b/src/helpers/channels/threads/get_archived_threads.ts index 50229b260..4a4de2927 100644 --- a/src/helpers/channels/threads/get_archived_threads.ts +++ b/src/helpers/channels/threads/get_archived_threads.ts @@ -4,7 +4,7 @@ import { endpoints } from "../../../util/constants.ts"; import { camelKeysToSnakeCase } from "../../../util/utils.ts"; export async function getArchivedThreads( - channelId: string, + channelId: bigint, options?: ListPublicArchivedThreads & { type?: "public" | "private" | "privateJoinedThreads"; }, diff --git a/src/helpers/channels/threads/get_thread_members.ts b/src/helpers/channels/threads/get_thread_members.ts index b56b0f576..34c1d0e13 100644 --- a/src/helpers/channels/threads/get_thread_members.ts +++ b/src/helpers/channels/threads/get_thread_members.ts @@ -6,7 +6,7 @@ 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) { +export async function getThreadMembers(channelId: bigint) { // TODO(threads): perm check // TODO(threads): intents check const channel = await cacheHandlers.get("channels", channelId); diff --git a/src/helpers/channels/threads/remove_from_thread.ts b/src/helpers/channels/threads/remove_from_thread.ts index 7cf250275..9e967a843 100644 --- a/src/helpers/channels/threads/remove_from_thread.ts +++ b/src/helpers/channels/threads/remove_from_thread.ts @@ -5,7 +5,7 @@ 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) { +export async function removeFromThread(channelId: bigint, userId?: bigint) { // TODO(threads): perm check const channel = await cacheHandlers.get("channels", channelId); if (channel) { diff --git a/src/helpers/channels/threads/start_thread.ts b/src/helpers/channels/threads/start_thread.ts index 5fe429c22..dc4f8bbde 100644 --- a/src/helpers/channels/threads/start_thread.ts +++ b/src/helpers/channels/threads/start_thread.ts @@ -11,8 +11,8 @@ import { camelKeysToSnakeCase } from "../../../util/utils.ts"; * @param messageId when provided the thread will be public */ export async function startThread( - channelId: string, - options: StartThread & { messageId?: string }, + channelId: bigint, + options: StartThread & { messageId?: bigint }, ) { const channel = await cacheHandlers.get("channels", channelId); if (channel) { From 49eb18d848bc6f4ed7ce41953e46e8e2b363a757 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 3 May 2021 21:46:17 +0200 Subject: [PATCH 064/148] Update THREAD_DELETE.ts --- src/handlers/channels/THREAD_DELETE.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/handlers/channels/THREAD_DELETE.ts b/src/handlers/channels/THREAD_DELETE.ts index 7de3d61ed..e4c2b4d87 100644 --- a/src/handlers/channels/THREAD_DELETE.ts +++ b/src/handlers/channels/THREAD_DELETE.ts @@ -2,20 +2,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"; +import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleThreadDelete(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; - 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); } }); From fb8e232d2fdae9aaaae0e190556b0582b1f10d42 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 3 May 2021 21:46:19 +0200 Subject: [PATCH 065/148] Update THREAD_LIST_SYNC.ts --- src/handlers/channels/THREAD_LIST_SYNC.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/handlers/channels/THREAD_LIST_SYNC.ts b/src/handlers/channels/THREAD_LIST_SYNC.ts index 659769d99..aedcab173 100644 --- a/src/handlers/channels/THREAD_LIST_SYNC.ts +++ b/src/handlers/channels/THREAD_LIST_SYNC.ts @@ -4,6 +4,7 @@ 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 { snowflakeToBigint } from "../../util/bigint.ts"; import { Collection } from "../../util/collection.ts"; export async function handleThreadListSync(data: DiscordGatewayPayload) { @@ -13,7 +14,7 @@ export async function handleThreadListSync(data: DiscordGatewayPayload) { payload.threads.map(async (thread) => { const discordenoChannel = await structures.createDiscordenoChannel( thread, - payload.guildId, + snowflakeToBigint(payload.guildId), ); await cacheHandlers.set( @@ -26,9 +27,13 @@ export async function handleThreadListSync(data: DiscordGatewayPayload) { }), ); - const threads = new Collection( + const threads = new Collection( discordenoChannels.map((t) => [t.id, t]), ); - eventHandlers.threadListSync?.(threads, payload.members, payload.guildId); + eventHandlers.threadListSync?.( + threads, + payload.members, + snowflakeToBigint(payload.guildId), + ); } From c2175cc3396b6f7afece56326a76e1953ad29104 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 3 May 2021 21:46:26 +0200 Subject: [PATCH 066/148] add: handleThreadMembersUpdate --- .../channels/THREAD_MEMBERS_UPDATE.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/handlers/channels/THREAD_MEMBERS_UPDATE.ts diff --git a/src/handlers/channels/THREAD_MEMBERS_UPDATE.ts b/src/handlers/channels/THREAD_MEMBERS_UPDATE.ts new file mode 100644 index 000000000..b614f143e --- /dev/null +++ b/src/handlers/channels/THREAD_MEMBERS_UPDATE.ts @@ -0,0 +1,19 @@ +import { eventHandlers } from "../../bot.ts"; +import { cacheHandlers } from "../../cache.ts"; +import { ThreadMembersUpdate } from "../../types/channels/threads/thread_members_update.ts"; +import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import { snowflakeToBigint } from "../../util/bigint.ts"; + +export async function handleThreadMembersUpdate(data: DiscordGatewayPayload) { + const payload = data.d as ThreadMembersUpdate; + const thread = await cacheHandlers.get( + "channels", + snowflakeToBigint(payload.id), + ); + if (!thread) return; + + thread.memberCount = payload.memberCount; + await cacheHandlers.set("channels", thread.id, thread); + + eventHandlers.threadMembersUpdate?.(payload); +} From 781a3e71c073ce4c99d1e680443a0e2990f3a974 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 3 May 2021 21:46:30 +0200 Subject: [PATCH 067/148] Update THREAD_UPDATE.ts --- src/handlers/channels/THREAD_UPDATE.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/handlers/channels/THREAD_UPDATE.ts b/src/handlers/channels/THREAD_UPDATE.ts index fac23b833..1e3ae12d0 100644 --- a/src/handlers/channels/THREAD_UPDATE.ts +++ b/src/handlers/channels/THREAD_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 handleThreadUpdate(data: DiscordGatewayPayload) { const payload = data.d as Channel; - const oldChannel = await cacheHandlers.get("channels", payload.id); + const oldChannel = await cacheHandlers.get( + "channels", + snowflakeToBigint(payload.id), + ); if (!oldChannel) return; const discordenoChannel = await structures.createDiscordenoChannel(payload); From a017a976a96e7dd984aa19f17106c5a686a531cf Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 3 May 2021 21:46:39 +0200 Subject: [PATCH 068/148] add: new thread events --- src/types/discordeno/eventHandlers.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/types/discordeno/eventHandlers.ts b/src/types/discordeno/eventHandlers.ts index 4c97cea77..5386935ab 100644 --- a/src/types/discordeno/eventHandlers.ts +++ b/src/types/discordeno/eventHandlers.ts @@ -4,6 +4,8 @@ import { DiscordenoMember } from "../../structures/member.ts"; import { DiscordenoMessage } from "../../structures/message.ts"; import { DiscordenoRole } from "../../structures/role.ts"; import { Collection } from "../../util/collection.ts"; +import { ThreadMember } from "../channels/threads/thread_member.ts"; +import { ThreadMembersUpdate } from "../channels/threads/thread_members_update.ts"; import { IntegrationCreateUpdate } from "../integration/integration_create_update.ts"; import { ApplicationCommandCreateUpdateDelete } from "../interactions/application_command_create_update_delete.ts"; import { @@ -211,6 +213,25 @@ export interface EventHandlers { shardId: number, unavailableGuildIds: Set, ) => unknown; + /** Sent when a thread is created */ + threadCreate?: (channel: DiscordenoChannel) => unknown; + /** Sent when a thread is updated */ + threadUpdate?: ( + cahnnel: DiscordenoChannel, + oldChannel: DiscordenoChannel, + ) => unknown; + /** Sent when the bot gains access to threads */ + threadListSync?: ( + channels: Collection, + members: ThreadMember[], + guildId: bigint, + ) => unknown; + /** Sent when the current users thread member is updated */ + threadMemberUpdate?: (threadMember: ThreadMember) => unknown; + /** Sent when anyone is added to or removed from a thread */ + threadMembersUpdate?: (update: ThreadMembersUpdate) => unknown; + /** Sent when a thread is deleted */ + threadDelete?: (channel: DiscordenoChannel) => unknown; /** Sent when a user starts typing in a channel. */ typingStart?: (data: TypingStart) => unknown; /** Sent when a user joins a voice channel */ From 9e05a0c4fa0111ecd7e9d3b3b9859658ceaa972b Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 3 May 2021 21:46:46 +0200 Subject: [PATCH 069/148] add: new thread events --- src/handlers/mod.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/handlers/mod.ts b/src/handlers/mod.ts index 2eda4a9c7..169e79d21 100644 --- a/src/handlers/mod.ts +++ b/src/handlers/mod.ts @@ -2,6 +2,12 @@ import { handleChannelCreate } from "./channels/CHANNEL_CREATE.ts"; import { handleChannelDelete } from "./channels/CHANNEL_DELETE.ts"; import { handleChannelPinsUpdate } from "./channels/CHANNEL_PINS_UPDATE.ts"; import { handleChannelUpdate } from "./channels/CHANNEL_UPDATE.ts"; +import { handleThreadCreate } from "./channels/THREAD_CREATE.ts"; +import { handleThreadDelete } from "./channels/THREAD_DELETE.ts"; +import { handleThreadListSync } from "./channels/THREAD_LIST_SYNC.ts"; +import { handleThreadMembersUpdate } from "./channels/THREAD_MEMBERS_UPDATE.ts"; +import { handleThreadMemberUpdate } from "./channels/THREAD_MEMBER_UPDATE.ts"; +import { handleThreadUpdate } from "./channels/THREAD_UPDATE.ts"; import { handleApplicationCommandCreate } from "./commands/APPLICATION_COMMAND_CREATE.ts"; import { handleApplicationCommandDelete } from "./commands/APPLICATION_COMMAND_DELETE.ts"; import { handleApplicationCommandUpdate } from "./commands/APPLICATION_COMMAND_UPDATE.ts"; @@ -77,6 +83,12 @@ export { handleMessageUpdate, handlePresenceUpdate, handleReady, + handleThreadCreate, + handleThreadDelete, + handleThreadListSync, + handleThreadMembersUpdate, + handleThreadMemberUpdate, + handleThreadUpdate, handleTypingStart, handleUserUpdate, handleVoiceServerUpdate, @@ -92,6 +104,12 @@ export let handlers = { CHANNEL_DELETE: handleChannelDelete, CHANNEL_PINS_UPDATE: handleChannelPinsUpdate, CHANNEL_UPDATE: handleChannelUpdate, + THREAD_CREATE: handleThreadCreate, + THREAD_UPDATE: handleThreadUpdate, + THREAD_DELETE: handleThreadDelete, + THREAD_LIST_SYNC: handleThreadListSync, + THREAD_MEMBER_UPDATE: handleThreadMemberUpdate, + THREAD_MEMBERS_UPDATE: handleThreadMembersUpdate, // commands APPLICATION_COMMAND_CREATE: handleApplicationCommandCreate, APPLICATION_COMMAND_DELETE: handleApplicationCommandDelete, From 304e3a26ac53f3a9a3d4e41e4904fae42faa0891 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 3 May 2021 21:47:03 +0200 Subject: [PATCH 070/148] NOT TESTED BECAUSE DISCORD NOT WORKING --- src/helpers/channels/threads/add_to_thread.ts | 35 +++++++++++++++++++ .../channels/threads/get_active_threads.ts | 12 +++++++ 2 files changed, 47 insertions(+) create mode 100644 src/helpers/channels/threads/add_to_thread.ts create mode 100644 src/helpers/channels/threads/get_active_threads.ts diff --git a/src/helpers/channels/threads/add_to_thread.ts b/src/helpers/channels/threads/add_to_thread.ts new file mode 100644 index 000000000..1fd913b5f --- /dev/null +++ b/src/helpers/channels/threads/add_to_thread.ts @@ -0,0 +1,35 @@ +import { cacheHandlers } from "../../../cache.ts"; +import { rest } from "../../../rest/rest.ts"; +import { ChannelTypes, Errors } from "../../../types/mod.ts"; +import { endpoints } from "../../../util/constants.ts"; +//TODO(threads): this does not work rn +/** Adds the current user to a thread. Returns a 204 empty response on success. Also requires the thread is not archived. Fires a Thread Members Update Gateway event.Adds another user to a thread. Requires the ability to send messages in the thread. Also requires the thread is not archived. Returns a 204 empty response on success. Fires a Thread Members Update Gateway event. + * @param userId the user to add to the thread defaults to bot + */ +export async function addToThread(channelId: bigint, userId?: bigint) { + // 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); + } + } + console.log( + "put", + userId + ? endpoints.THREAD_USER(channelId, userId) + : endpoints.THREAD_ME(channelId), + ); + return await rest.runMethod( + "put", + userId + ? endpoints.THREAD_USER(channelId, userId) + : endpoints.THREAD_ME(channelId), + ); +} diff --git a/src/helpers/channels/threads/get_active_threads.ts b/src/helpers/channels/threads/get_active_threads.ts new file mode 100644 index 000000000..6fd529bd2 --- /dev/null +++ b/src/helpers/channels/threads/get_active_threads.ts @@ -0,0 +1,12 @@ +import { rest } from "../../../rest/rest.ts"; +import { endpoints } from "../../../util/constants.ts"; + +/** Returns all active threads in the channel, including public and private threads. Threads are ordered by their id, in descending order. Requires the READ_MESSAGE_HISTORY permission. */ +export async function getActiveThreads(channelId: bigint) { + // TODO(threads): perm check + // TODO(threads): test if it works + return rest.runMethod( + "get", + endpoints.THREAD_ACTIVE(channelId), + ); +} From 9c3c8c58acb51d319f34bead8b8ede1d9614e2bc Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 3 May 2021 21:55:08 +0200 Subject: [PATCH 071/148] forgot that one --- src/helpers/channels/threads/get_active_threads.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/channels/threads/get_active_threads.ts b/src/helpers/channels/threads/get_active_threads.ts index 6fd529bd2..2ed30691d 100644 --- a/src/helpers/channels/threads/get_active_threads.ts +++ b/src/helpers/channels/threads/get_active_threads.ts @@ -5,7 +5,7 @@ import { endpoints } from "../../../util/constants.ts"; export async function getActiveThreads(channelId: bigint) { // TODO(threads): perm check // TODO(threads): test if it works - return rest.runMethod( + return await rest.runMethod( "get", endpoints.THREAD_ACTIVE(channelId), ); From 2c58d6d28d0e5a120f1c682258b187721258ba7e Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 3 May 2021 22:56:32 +0200 Subject: [PATCH 072/148] remove guild member being cached in parent object --- src/structures/member.ts | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/src/structures/member.ts b/src/structures/member.ts index a250cb15f..093b9b9d4 100644 --- a/src/structures/member.ts +++ b/src/structures/member.ts @@ -23,7 +23,6 @@ import { createNewProp } from "../util/utils.ts"; import { DiscordenoGuild } from "./guild.ts"; const MEMBER_SNOWFLAKES = [ - "roles", "id", "discriminator", ]; @@ -87,29 +86,10 @@ export async function createDiscordenoMember( user, joinedAt, premiumSince, - ...rest } = data; const props: Record> = {}; - for (const [key, value] of Object.entries(rest)) { - eventHandlers.debug?.( - "loop", - `Running for of loop for Object.keys(rest) in DiscordenoMember function.`, - ); - - if (key === "roles") { - props[key] = value.map((id: string) => snowflakeToBigint(id)); - continue; - } - - props[key] = createNewProp( - MEMBER_SNOWFLAKES.includes(key) - ? value ? snowflakeToBigint(value) : undefined - : value, - ); - } - for (const [key, value] of Object.entries(user)) { eventHandlers.debug?.( "loop", @@ -142,29 +122,21 @@ export async function createDiscordenoMember( // User was never cached before member.guilds.set(guildId, { - nick: rest.nick, - roles: rest.roles.map((id) => snowflakeToBigint(id)), + ...data, + roles: data.roles.map((id) => snowflakeToBigint(id)), joinedAt: Date.parse(joinedAt), premiumSince: premiumSince ? Date.parse(premiumSince) : undefined, - deaf: rest.deaf, - mute: rest.mute, }); return member; } export interface DiscordenoMember extends - Omit< - GuildMember, - "roles" - >, Omit< User, | "discriminator" | "id" > { - /** Array of role object ids */ - roles: bigint[]; /** The user's id */ id: bigint; /** The user's 4-digit discord-tag */ From 6c80e1c47ebf3cd8d7d7d522cdbb1825367e5a76 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 3 May 2021 22:57:11 +0200 Subject: [PATCH 073/148] fmt stuff --- src/structures/message.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/structures/message.ts b/src/structures/message.ts index 47a798594..bc0d23d42 100644 --- a/src/structures/message.ts +++ b/src/structures/message.ts @@ -231,7 +231,9 @@ export interface DiscordenoMessage extends isBot: boolean; /** The username#discrimnator for the user who sent this message */ tag: string; + // For better user experience + /** Id of the guild which the massage has been send in. "0n" if it a DM */ guildId: bigint; /** id of the channel the message was sent in */ @@ -252,6 +254,7 @@ export interface DiscordenoMessage extends timestamp: number; /** When this message was edited (or undefined if never) */ editedTimestamp?: number; + // GETTERS /** The channel where this message was sent. Can be undefined if uncached. */ From 6d0b0cb974824fc2b97975e29377aa2b2d699b05 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 3 May 2021 22:58:06 +0200 Subject: [PATCH 074/148] now sendWebhook --- src/helpers/mod.ts | 6 +++--- .../webhooks/{execute_webhook.ts => send_webhook.ts} | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) rename src/helpers/webhooks/{execute_webhook.ts => send_webhook.ts} (95%) diff --git a/src/helpers/mod.ts b/src/helpers/mod.ts index 44bb6a467..b4ed6c9f1 100644 --- a/src/helpers/mod.ts +++ b/src/helpers/mod.ts @@ -118,7 +118,7 @@ import { deleteWebhookWithToken } from "./webhooks/delete_webhook_with_token.ts" import { editWebhook } from "./webhooks/edit_webhook.ts"; import { editWebhookMessage } from "./webhooks/edit_webhook_message.ts"; import { editWebhookWithToken } from "./webhooks/edit_webhook_with_token.ts"; -import { executeWebhook } from "./webhooks/execute_webhook.ts"; +import { sendWebhook } from "./webhooks/send_webhook.ts"; import { getWebhook } from "./webhooks/get_webhook.ts"; import { getWebhooks } from "./webhooks/get_webhooks.ts"; import { getWebhookWithToken } from "./webhooks/get_webhook_with_token.ts"; @@ -181,7 +181,7 @@ export { editWelcomeScreen, editWidget, emojiURL, - executeWebhook, + sendWebhook, fetchMembers, followChannel, getAuditLogs, @@ -392,7 +392,7 @@ export let helpers = { editWebhookMessage, editWebhookWithToken, editWebhook, - executeWebhook, + sendWebhook, getWebhookWithToken, getWebhook, getWebhooks, diff --git a/src/helpers/webhooks/execute_webhook.ts b/src/helpers/webhooks/send_webhook.ts similarity index 95% rename from src/helpers/webhooks/execute_webhook.ts rename to src/helpers/webhooks/send_webhook.ts index 2a03e3ebb..e53f86e74 100644 --- a/src/helpers/webhooks/execute_webhook.ts +++ b/src/helpers/webhooks/send_webhook.ts @@ -6,8 +6,8 @@ import { Errors } from "../../types/misc/errors.ts"; import { ExecuteWebhook } from "../../types/webhooks/execute_webhook.ts"; import { endpoints } from "../../util/constants.ts"; -/** Execute a webhook with webhook Id and webhook token */ -export async function executeWebhook( +/** Send a webhook with webhook Id and webhook token */ +export async function sendWebhook( webhookId: bigint, webhookToken: string, options: ExecuteWebhook, @@ -75,7 +75,6 @@ export async function executeWebhook( avatar_url: options.avatarUrl, }, ); - // TODO: not sure if (!options.wait) return; return structures.createDiscordenoMessage(result); From 889d03066addb2ab5fabac4f04860121791a9640 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 3 May 2021 22:58:11 +0200 Subject: [PATCH 075/148] Update create_role.ts --- src/helpers/roles/create_role.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/helpers/roles/create_role.ts b/src/helpers/roles/create_role.ts index 363809489..2b53d295e 100644 --- a/src/helpers/roles/create_role.ts +++ b/src/helpers/roles/create_role.ts @@ -31,9 +31,13 @@ export async function createRole( role: result, guildId, }); - const guild = await cacheHandlers.get("guilds", guildId); - guild?.roles.set(role.id, role); - // TODO: ADD TO CACHE? + const guild = await cacheHandlers.get("guilds", guildId); + if (guild) { + guild.roles.set(role.id, role); + + await cacheHandlers.set("guilds", guildId, guild); + } + return role; } From 61c61dabdb6be2f094e4918a03bae425f6941c4e Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 3 May 2021 22:58:15 +0200 Subject: [PATCH 076/148] Update get_roles.ts --- src/helpers/roles/get_roles.ts | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/helpers/roles/get_roles.ts b/src/helpers/roles/get_roles.ts index b65dbf882..a94a7fa84 100644 --- a/src/helpers/roles/get_roles.ts +++ b/src/helpers/roles/get_roles.ts @@ -1,5 +1,8 @@ +import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; +import { structures } from "../../structures/mod.ts"; import { Role } from "../../types/permissions/role.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"; @@ -8,7 +11,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: bigint) { +export async function getRoles(guildId: bigint, addToCache = true) { await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); const result = await rest.runMethod( @@ -16,9 +19,23 @@ export async function getRoles(guildId: bigint) { endpoints.GUILD_ROLES(guildId), ); - // TODO: addToCache - - return new Collection( - result.map((role) => [role.id, role]), + const roleStructures = await Promise.all( + result.map(async (role) => + await structures.createDiscordenoRole({ role, guildId }) + ), ); + + const roles = new Collection( + roleStructures.map((role) => [role.id, role]), + ); + + if (addToCache) { + const guild = await cacheHandlers.get("guilds", guildId); + if (guild) { + guild.roles = roles; + await cacheHandlers.set("guilds", guild.id, guild); + } + } + + return roleStructures; } From 3ef1f9fa8fce124b4d890fe0ddc87e0cb959eba8 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 3 May 2021 22:58:17 +0200 Subject: [PATCH 077/148] Update create_guild_from_template.ts --- .../templates/create_guild_from_template.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/helpers/templates/create_guild_from_template.ts b/src/helpers/templates/create_guild_from_template.ts index 770f71299..6bbd3795e 100644 --- a/src/helpers/templates/create_guild_from_template.ts +++ b/src/helpers/templates/create_guild_from_template.ts @@ -1,9 +1,11 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; +import { structures } from "../../structures/mod.ts"; import { Guild } from "../../types/guilds/guild.ts"; import { CreateGuildFromTemplate } from "../../types/templates/create_guild_from_template.ts"; import { endpoints } from "../../util/constants.ts"; import { urlToBase64 } from "../../util/utils.ts"; +import { ws } from "../../ws/ws.ts"; /** * Create a new guild based on a template @@ -23,11 +25,17 @@ export async function createGuildFromTemplate( data.icon = await urlToBase64(data.icon); } - // TODO: discordeno guild? - - return await rest.runMethod( + const createdGuild = await rest.runMethod( "post", endpoints.GUILD_TEMPLATE(templateCode), data, ); + + return await structures.createDiscordenoGuild( + createdGuild, + Number( + (BigInt(createdGuild.id) >> 22n % BigInt(ws.botGatewayData.shards)) + .toString(), + ), + ); } From d3bd06e297d8a73ba3c8cea94c0b38d4ea81ee5f Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 3 May 2021 22:58:21 +0200 Subject: [PATCH 078/148] Update modify_channel.ts --- src/types/channels/modify_channel.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/types/channels/modify_channel.ts b/src/types/channels/modify_channel.ts index b6defe24b..09db31d89 100644 --- a/src/types/channels/modify_channel.ts +++ b/src/types/channels/modify_channel.ts @@ -35,7 +35,6 @@ export interface DiscordModifyChannel extends SnakeCasedPropertiesDeep< Omit > { + // deno-lint-ignore camelcase permission_overwrites?: DiscordOverwrite[]; } - -//TODO: check this From 5d755dfedb083598311de1dc95aa9262e684c289 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 3 May 2021 22:58:23 +0200 Subject: [PATCH 079/148] Update create_guild_channel.ts --- src/types/guilds/create_guild_channel.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/guilds/create_guild_channel.ts b/src/types/guilds/create_guild_channel.ts index d6fe506d0..38eb79102 100644 --- a/src/types/guilds/create_guild_channel.ts +++ b/src/types/guilds/create_guild_channel.ts @@ -30,6 +30,6 @@ export interface DiscordCreateGuildChannel extends SnakeCasedPropertiesDeep< Omit > { + // deno-lint-ignore camelcase permission_overwrites: DiscordOverwrite[]; } -// TODO: check this From 31318f6dee3e749c24ecc8bf5a09618b0acb9b2a Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 3 May 2021 22:58:24 +0200 Subject: [PATCH 080/148] Update create_guild_role.ts --- src/types/guilds/create_guild_role.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/types/guilds/create_guild_role.ts b/src/types/guilds/create_guild_role.ts index 2183a0f7d..d1be99b30 100644 --- a/src/types/guilds/create_guild_role.ts +++ b/src/types/guilds/create_guild_role.ts @@ -18,4 +18,3 @@ export interface DiscordCreateGuildRole extends Omit { permissions?: string; } -// TODO: check this From 8ee9a7cdecd16ff6435620dff3c3c796d699eec9 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 3 May 2021 22:58:27 +0200 Subject: [PATCH 081/148] Update guild.ts --- src/types/guilds/guild.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/guilds/guild.ts b/src/types/guilds/guild.ts index bcaa3dc9f..1f7ea91fe 100644 --- a/src/types/guilds/guild.ts +++ b/src/types/guilds/guild.ts @@ -105,7 +105,7 @@ export interface Guild { approximateMemberCount?: number; /** Approximate number of non-offline members in this guild, returned from the GET /guilds/ endpoint when with_counts is true */ approximatePresenceCount?: number; - /** The welcome screen of a Community guild, shown to new members, returned when in the invite object */ + /** The welcome screen of a Community guild, shown to new members, returned in an Invite's guild object */ welcomeScreen?: WelcomeScreen; /** `true` if this guild is designated as NSFW */ nsfw: boolean; From 8f05a60fc46fe587c5bad4b037d631617d3f4626 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 3 May 2021 22:58:30 +0200 Subject: [PATCH 082/148] Update modify_guild_channel_position.ts --- src/types/guilds/modify_guild_channel_position.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/types/guilds/modify_guild_channel_position.ts b/src/types/guilds/modify_guild_channel_position.ts index 646cce814..734786e9c 100644 --- a/src/types/guilds/modify_guild_channel_position.ts +++ b/src/types/guilds/modify_guild_channel_position.ts @@ -1,4 +1,3 @@ -// TODO: most likely it is but check if lockPositions and parentId really are optional /** https://discord.com/developers/docs/resources/guild#modify-guild-channel-positions */ export interface ModifyGuildChannelPositions { /** Channel id */ From b638f9bee8967c0fb513ca561c2eef9e95a666fd Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 3 May 2021 22:58:32 +0200 Subject: [PATCH 083/148] Update modify_guild_role.ts --- src/types/guilds/modify_guild_role.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/types/guilds/modify_guild_role.ts b/src/types/guilds/modify_guild_role.ts index cb5e09006..a23d92329 100644 --- a/src/types/guilds/modify_guild_role.ts +++ b/src/types/guilds/modify_guild_role.ts @@ -18,5 +18,3 @@ export interface DiscordModifyGuildRole extends Omit { permissions?: string | null; } - -// TODO: check this From 02fe69a48d2fb28298f3d45b254765fa56f0aac2 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 3 May 2021 22:58:34 +0200 Subject: [PATCH 084/148] Update create_message.ts --- src/types/messages/create_message.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/types/messages/create_message.ts b/src/types/messages/create_message.ts index 836b0040c..fa1704f90 100644 --- a/src/types/messages/create_message.ts +++ b/src/types/messages/create_message.ts @@ -28,5 +28,3 @@ export interface CreateMessage { export type DiscordCreateMessage = SnakeCasedPropertiesDeep< Omit >; - -// TODO: check this From 70e64bb16d261a3d0f6bcf4a526ef28d19c6f956 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 3 May 2021 22:58:38 +0200 Subject: [PATCH 085/148] Update application_flags.ts --- src/types/oauth2/application_flags.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/types/oauth2/application_flags.ts b/src/types/oauth2/application_flags.ts index 5fe9538f2..d2ada528b 100644 --- a/src/types/oauth2/application_flags.ts +++ b/src/types/oauth2/application_flags.ts @@ -1,5 +1,4 @@ -// https://github.com/discord/discord-api-docs/pull/2624 -// TODO: add documentation link +/** https://discord.com/developers/docs/topics/oauth2#application-application-flags */ export enum DiscordApplicationFlags { GatewayPresence = 1 << 12, GatewayPresenceLimited = 1 << 13, From b24853e5b734870f0884e3c9dc895bdaeeb8db42 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 3 May 2021 22:58:41 +0200 Subject: [PATCH 086/148] Update execute_webhook.ts --- src/types/webhooks/execute_webhook.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/types/webhooks/execute_webhook.ts b/src/types/webhooks/execute_webhook.ts index f668a0906..9268f21bf 100644 --- a/src/types/webhooks/execute_webhook.ts +++ b/src/types/webhooks/execute_webhook.ts @@ -26,4 +26,3 @@ export interface ExecuteWebhook { export type DiscordExecuteWebhook = SnakeCasedPropertiesDeep< Omit >; -//TODO: check this From 2ffec5b09fcfbc4400820ff1a052b85f1c74ad0d Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 3 May 2021 22:58:43 +0200 Subject: [PATCH 087/148] Update channel_overwrite_has_permission.ts --- tests/channels/channel_overwrite_has_permission.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/channels/channel_overwrite_has_permission.ts b/tests/channels/channel_overwrite_has_permission.ts index 239f81886..2eaa988c7 100644 --- a/tests/channels/channel_overwrite_has_permission.ts +++ b/tests/channels/channel_overwrite_has_permission.ts @@ -10,8 +10,7 @@ import { assertEquals, assertExists } from "../deps.ts"; import { delayUntil } from "../util/delay_until.ts"; import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; -// TODO: whats save? -async function ifItFailsBlameWolf(options: CreateGuildChannel, _save = false) { +async function ifItFailsBlameWolf(options: CreateGuildChannel) { const channel = await createChannel(tempData.guildId, options); // Assertions @@ -60,7 +59,6 @@ Deno.test({ }, ], }, - true, ); }, ...defaultTestOptions, From bb03468d56a568b48b543fcf0b767818abb75b47 Mon Sep 17 00:00:00 2001 From: itohatweb Date: Mon, 3 May 2021 20:59:18 +0000 Subject: [PATCH 088/148] Commit from GitHub Actions (Lint) --- src/helpers/mod.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/mod.ts b/src/helpers/mod.ts index b4ed6c9f1..6d0aea748 100644 --- a/src/helpers/mod.ts +++ b/src/helpers/mod.ts @@ -181,7 +181,6 @@ export { editWelcomeScreen, editWidget, emojiURL, - sendWebhook, fetchMembers, followChannel, getAuditLogs, @@ -247,6 +246,7 @@ export { sendDirectMessage, sendInteractionResponse, sendMessage, + sendWebhook, startTyping, swapChannels, syncGuildTemplate, From 6adf0b5359a8013f813e75698401ef4abee0a1e6 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 3 May 2021 22:59:56 +0200 Subject: [PATCH 089/148] i guess remove --- tests/channels/edit_channel_overwrite.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/channels/edit_channel_overwrite.ts b/tests/channels/edit_channel_overwrite.ts index 64dbcb787..c26dcff6a 100644 --- a/tests/channels/edit_channel_overwrite.ts +++ b/tests/channels/edit_channel_overwrite.ts @@ -11,8 +11,7 @@ import { assertEquals, assertExists } from "../deps.ts"; import { delayUntil } from "../util/delay_until.ts"; import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; -// TODO: whats save -async function ifItFailsBlameWolf(options: CreateGuildChannel, _save = false) { +async function ifItFailsBlameWolf(options: CreateGuildChannel) { const channel = await createChannel(tempData.guildId, options); // Assertions @@ -78,7 +77,6 @@ Deno.test({ }, ], }, - true, ); }, ...defaultTestOptions, From 0e4c3481b2759c08de984ae2b98a37cce19d793e Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 3 May 2021 23:00:39 +0200 Subject: [PATCH 090/148] all are false anyways --- tests/channels/clone_channel.ts | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/tests/channels/clone_channel.ts b/tests/channels/clone_channel.ts index df772deb5..168c60b86 100644 --- a/tests/channels/clone_channel.ts +++ b/tests/channels/clone_channel.ts @@ -10,8 +10,7 @@ import { assertEquals, assertExists } from "../deps.ts"; import { delayUntil } from "../util/delay_until.ts"; import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; -// TODO: whats save -async function ifItFailsBlameWolf(options: CreateGuildChannel, _save = false) { +async function ifItFailsBlameWolf(options: CreateGuildChannel) { const channel = await createChannel(tempData.guildId, options); const cloned = await cloneChannel(channel.id); @@ -51,7 +50,7 @@ async function ifItFailsBlameWolf(options: CreateGuildChannel, _save = false) { Deno.test({ name: "[channel] clone a new text channel", async fn() { - await ifItFailsBlameWolf({ name: "Discordeno-clone-test" }, false); + await ifItFailsBlameWolf({ name: "Discordeno-clone-test" }); }, ...defaultTestOptions, }); @@ -64,7 +63,6 @@ Deno.test({ name: "Discordeno-clone-test", type: DiscordChannelTypes.GUILD_CATEGORY, }, - false, ); }, ...defaultTestOptions, @@ -78,7 +76,6 @@ Deno.test({ name: "Discordeno-clone-test", type: DiscordChannelTypes.GUILD_VOICE, }, - false, ); }, ...defaultTestOptions, @@ -93,7 +90,6 @@ Deno.test({ type: DiscordChannelTypes.GUILD_VOICE, bitrate: 32000, }, - false, ); }, ...defaultTestOptions, @@ -108,7 +104,6 @@ Deno.test({ type: DiscordChannelTypes.GUILD_VOICE, userLimit: 32, }, - false, ); }, ...defaultTestOptions, @@ -122,7 +117,6 @@ Deno.test({ name: "Discordeno-clone-test", rateLimitPerUser: 2423, }, - false, ); }, ...defaultTestOptions, @@ -133,7 +127,6 @@ Deno.test({ async fn() { await ifItFailsBlameWolf( { name: "Discordeno-clone-test", nsfw: true }, - false, ); }, ...defaultTestOptions, @@ -154,7 +147,6 @@ Deno.test({ }, ], }, - false, ); }, ...defaultTestOptions, From c7fdf8e287599b192e6648ef2a11adacaeb44c21 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 10:44:50 +0200 Subject: [PATCH 091/148] remove unused import --- src/helpers/roles/get_roles.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/helpers/roles/get_roles.ts b/src/helpers/roles/get_roles.ts index a94a7fa84..c2b3f6aaf 100644 --- a/src/helpers/roles/get_roles.ts +++ b/src/helpers/roles/get_roles.ts @@ -2,7 +2,6 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { Role } from "../../types/permissions/role.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"; From 8072122b851f76631e1e47eb3181ce6453a899d1 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 11:23:15 +0200 Subject: [PATCH 092/148] fix: toggleBits value can be false --- src/structures/voice_state.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/structures/voice_state.ts b/src/structures/voice_state.ts index c5c846562..002ec81da 100644 --- a/src/structures/voice_state.ts +++ b/src/structures/voice_state.ts @@ -82,7 +82,7 @@ export async function createDiscordenoVoiceState( const toggleBits = voiceStateToggles[key as keyof typeof voiceStateToggles]; if (toggleBits) { - bitfield |= toggleBits; + bitfield |= value ? toggleBits : 0n; continue; } From 81435535f8ca9735e74b37cf18f4a88c25b309cf Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 11:30:59 +0200 Subject: [PATCH 093/148] add: bitfield --- src/structures/guild.ts | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/structures/guild.ts b/src/structures/guild.ts index 87f6dccc1..96f8a8b06 100644 --- a/src/structures/guild.ts +++ b/src/structures/guild.ts @@ -47,6 +47,19 @@ const GUILD_SNOWFLAKES = [ "publicUpdatesChannelId", ]; +export const guildToggles = { + /** Whether this user is owner of this guild */ + owner: 1n, + /** Whether the guild widget is enabled */ + widgetEnabled: 2n, + /** Whether this is a large guild */ + large: 4n, + /** Whether this guild is unavailable due to an outage */ + unavailable: 8n, + /** Whether this server is an nsfw guild */ + nsfw: 16n, +}; + const baseGuild: Partial = { get members() { return cache.members.filter((member) => member.guilds.has(this.id!)); @@ -120,6 +133,21 @@ const baseGuild: Partial = { leave() { return leaveGuild(this.id!); }, + get isOwner() { + return Boolean(this.bitfield! & guildToggles.owner); + }, + get widgetEnabled() { + return Boolean(this.bitfield! & guildToggles.widgetEnabled); + }, + get large() { + return Boolean(this.bitfield! & guildToggles.large); + }, + get unavailable() { + return Boolean(this.bitfield! & guildToggles.unavailable); + }, + get nsfw() { + return Boolean(this.bitfield! & guildToggles.nsfw); + }, }; export async function createDiscordenoGuild( @@ -137,6 +165,7 @@ export async function createDiscordenoGuild( ...rest } = data; + let bitfield = 0n; const guildId = snowflakeToBigint(rest.id); const roles = await Promise.all( @@ -172,6 +201,12 @@ export async function createDiscordenoGuild( `Running for of loop in createDiscordenoGuild function.`, ); + const toggleBits = guildToggles[key as keyof typeof guildToggles]; + if (toggleBits) { + bitfield |= value ? toggleBits : 0n; + continue; + } + props[key] = createNewProp( GUILD_SNOWFLAKES.includes(key) ? value ? snowflakeToBigint(value) : undefined @@ -278,6 +313,10 @@ export interface DiscordenoGuild extends voiceStates: Collection; /** Custom guild emojis */ emojis: Collection; + /** Whether the bot is the owner of this guild */ + isOwner: boolean; + /** Holds all the boolean toggles. */ + bitfield: bigint; // GETTERS /** Members in this guild. */ From cceee6bc5b6f621226c70ac50d2a1f04601ca389 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 12:05:11 +0200 Subject: [PATCH 094/148] add: member bitfield --- src/structures/member.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/structures/member.ts b/src/structures/member.ts index 093b9b9d4..6f28ca7b0 100644 --- a/src/structures/member.ts +++ b/src/structures/member.ts @@ -27,6 +27,17 @@ const MEMBER_SNOWFLAKES = [ "discriminator", ]; +export const memberToggles = { + /** Whether the user belongs to an OAuth2 application */ + bot: 1n, + /** Whether the user is an Official Discord System user (part of the urgent message system) */ + system: 2n, + /** Whether the user has two factor enabled on their account */ + mfaEnabled: 4n, + /** Whether the email on this account has been verified */ + verified: 8n, +}; + const baseMember: Partial = { get avatarURL() { return avatarURL(this.id!, this.discriminator!, this.avatar!); @@ -75,6 +86,18 @@ const baseMember: Partial = { removeRole(guildId, roleId, reason) { return removeRole(guildId, this.id!, roleId, reason); }, + get bot() { + return Boolean(this.bitfield! & memberToggles.bot); + }, + get system() { + return Boolean(this.bitfield! & memberToggles.system) + }, + get mfaEnabled() { + return Boolean(this.bitfield! & memberToggles.mfaEnabled) + }, + get verified() { + return Boolean(this.bitfield! & memberToggles.verified) + } }; export async function createDiscordenoMember( @@ -88,6 +111,7 @@ export async function createDiscordenoMember( premiumSince, } = data; + let bitfield = 0n; const props: Record> = {}; for (const [key, value] of Object.entries(user)) { @@ -96,6 +120,12 @@ export async function createDiscordenoMember( `Running for of for Object.keys(user) loop in DiscordenoMember function.`, ); + const toggleBits = memberToggles[key as keyof typeof memberToggles]; + if (toggleBits) { + bitfield |= value ? toggleBits : 0n; + continue; + } + props[key] = createNewProp( MEMBER_SNOWFLAKES.includes(key) ? value ? snowflakeToBigint(value) : undefined @@ -150,6 +180,8 @@ export interface DiscordenoMember extends roles: bigint[]; } >; + /** Holds all the boolean toggles. */ + bitfield: bigint; // GETTERS /** The avatar url using the default format and size. */ From e63e6319a8d6617593c19727916505e92e7c3719 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 12:05:17 +0200 Subject: [PATCH 095/148] add: message bitfield --- src/structures/message.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/structures/message.ts b/src/structures/message.ts index bc0d23d42..3902398c7 100644 --- a/src/structures/message.ts +++ b/src/structures/message.ts @@ -29,6 +29,15 @@ const MESSAGE_SNOWFLAKES = [ "webhookId", ]; +const messageToggles = { + /** Whether this was a TTS message */ + tts: 1n, + /** Whether this message mentions everyone */ + mentionEveryone: 2n, + /** Whether this message is pinned */ + pinned: 4n, +}; + const baseMessage: Partial = { get channel() { if (this.guildId) return cache.channels.get(this.channelId!); @@ -132,6 +141,15 @@ const baseMessage: Partial = { removeReaction(reaction, userId) { return removeReaction(this.channelId!, this.id!, reaction, { userId }); }, + get tts() { + return Boolean(this.bitfield! & messageToggles.tts); + }, + get mentionEveryone() { + return Boolean(this.bitfield! & messageToggles.mentionEveryone); + }, + get pinned() { + return Boolean(this.bitfield! & messageToggles.pinned); + }, }; export async function createDiscordenoMessage(data: Message) { @@ -146,6 +164,8 @@ export async function createDiscordenoMessage(data: Message) { ...rest } = data; + let bitfield = 0n; + const props: Record> = {}; for (const [key, value] of Object.entries(rest)) { eventHandlers.debug?.( @@ -153,6 +173,12 @@ export async function createDiscordenoMessage(data: Message) { `Running for of loop in createDiscordenoMessage function.`, ); + const toggleBits = messageToggles[key as keyof typeof messageToggles]; + if (toggleBits) { + bitfield |= value ? toggleBits : 0n; + continue; + } + props[key] = createNewProp( MESSAGE_SNOWFLAKES.includes(key) ? value ? snowflakeToBigint(value) : undefined @@ -231,6 +257,8 @@ export interface DiscordenoMessage extends isBot: boolean; /** The username#discrimnator for the user who sent this message */ tag: string; + /** Holds all the boolean toggles. */ + bitfield: bigint; // For better user experience From d8f9e28fb02b25bcb67f5ad3f2035c580cb6e83e Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 12:05:24 +0200 Subject: [PATCH 096/148] add: role bitfield --- src/structures/role.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/structures/role.ts b/src/structures/role.ts index 783c20ce2..7a0c15a7c 100644 --- a/src/structures/role.ts +++ b/src/structures/role.ts @@ -19,6 +19,17 @@ const ROLE_SNOWFLAKES = [ "guildId", ]; +const roleToggles = { + /** If this role is showed seperately in the user listing */ + hoist: 1n, + /** Whether this role is managed by an integration */ + managed: 2n, + /** Whether this role is mentionable */ + mentionable: 4n, + /** If this role is the nitro boost role. */ + isNitroBoostRole: 8n, +}; + const baseRole: Partial = { get guild() { return cache.guilds.get(this.guildId!); @@ -71,6 +82,18 @@ const baseRole: Partial = { memberHighestRole.position, ); }, + get hoist() { + return Boolean(this.bitfield! & roleToggles.hoist); + }, + get managed() { + return Boolean(this.bitfield! & roleToggles.managed); + }, + get mentionable() { + return Boolean(this.bitfield! & roleToggles.mentionable); + }, + get isNitroBoostRole() { + return Boolean(this.bitfield! & roleToggles.isNitroBoostRole); + }, }; // deno-lint-ignore require-await @@ -84,6 +107,8 @@ export async function createDiscordenoRole( ...rest } = ({ guildId: data.guildId, ...data.role }); + let bitfield = 0n; + const props: Record> = {}; for (const [key, value] of Object.entries(rest)) { eventHandlers.debug?.( @@ -91,6 +116,12 @@ export async function createDiscordenoRole( `Running for of loop in createDiscordenoRole function.`, ); + const toggleBits = roleToggles[key as keyof typeof roleToggles]; + if (toggleBits) { + bitfield |= value ? toggleBits : 0n; + continue; + } + props[key] = createNewProp( ROLE_SNOWFLAKES.includes(key) ? value ? snowflakeToBigint(value) : undefined @@ -123,6 +154,8 @@ export interface DiscordenoRole extends Omit { integrationId: bigint; /** The roles guildId */ guildId: bigint; + /** Holds all the boolean toggles. */ + bitfield: bigint; // GETTERS From f9da3d03bfb50291490f165e7ef9a2a10a992ebd Mon Sep 17 00:00:00 2001 From: itohatweb Date: Tue, 4 May 2021 10:05:47 +0000 Subject: [PATCH 097/148] Commit from GitHub Actions (Lint) --- src/structures/member.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/structures/member.ts b/src/structures/member.ts index 6f28ca7b0..e3d46d3bc 100644 --- a/src/structures/member.ts +++ b/src/structures/member.ts @@ -90,14 +90,14 @@ const baseMember: Partial = { return Boolean(this.bitfield! & memberToggles.bot); }, get system() { - return Boolean(this.bitfield! & memberToggles.system) + return Boolean(this.bitfield! & memberToggles.system); }, get mfaEnabled() { - return Boolean(this.bitfield! & memberToggles.mfaEnabled) + return Boolean(this.bitfield! & memberToggles.mfaEnabled); }, get verified() { - return Boolean(this.bitfield! & memberToggles.verified) - } + return Boolean(this.bitfield! & memberToggles.verified); + }, }; export async function createDiscordenoMember( From 320180edee3a840bb756276b653c31389e693cf0 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 12:17:24 +0200 Subject: [PATCH 098/148] add type to all type imports for handlers --- src/handlers/channels/CHANNEL_CREATE.ts | 4 ++-- src/handlers/channels/CHANNEL_DELETE.ts | 4 ++-- src/handlers/channels/CHANNEL_PINS_UPDATE.ts | 4 ++-- src/handlers/channels/CHANNEL_UPDATE.ts | 4 ++-- src/handlers/commands/APPLICATION_COMMAND_CREATE.ts | 4 ++-- src/handlers/commands/APPLICATION_COMMAND_DELETE.ts | 4 ++-- src/handlers/commands/APPLICATION_COMMAND_UPDATE.ts | 4 ++-- src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts | 4 ++-- src/handlers/guilds/GUILD_BAN_ADD.ts | 4 ++-- src/handlers/guilds/GUILD_BAN_REMOVE.ts | 4 ++-- src/handlers/guilds/GUILD_CREATE.ts | 4 ++-- src/handlers/guilds/GUILD_DELETE.ts | 4 ++-- src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts | 4 ++-- src/handlers/guilds/GUILD_UPDATE.ts | 6 +++--- src/handlers/integrations/INTEGRATION_CREATE.ts | 4 ++-- src/handlers/integrations/INTEGRATION_DELETE.ts | 4 ++-- src/handlers/integrations/INTEGRATION_UPDATE.ts | 4 ++-- src/handlers/interactions/INTERACTION_CREATE.ts | 6 +++--- src/handlers/invites/INVITE_CREATE.ts | 4 ++-- src/handlers/invites/INVITE_DELETE.ts | 4 ++-- src/handlers/members/GUILD_MEMBERS_CHUNK.ts | 4 ++-- src/handlers/members/GUILD_MEMBER_ADD.ts | 4 ++-- src/handlers/members/GUILD_MEMBER_REMOVE.ts | 4 ++-- src/handlers/members/GUILD_MEMBER_UPDATE.ts | 4 ++-- src/handlers/messages/MESSAGE_CREATE.ts | 6 +++--- src/handlers/messages/MESSAGE_DELETE.ts | 4 ++-- src/handlers/messages/MESSAGE_DELETE_BULK.ts | 4 ++-- src/handlers/messages/MESSAGE_REACTION_ADD.ts | 4 ++-- src/handlers/messages/MESSAGE_REACTION_REMOVE.ts | 4 ++-- src/handlers/messages/MESSAGE_REACTION_REMOVE_ALL.ts | 4 ++-- src/handlers/messages/MESSAGE_REACTION_REMOVE_EMOJI.ts | 4 ++-- src/handlers/messages/MESSAGE_UPDATE.ts | 4 ++-- src/handlers/misc/PRESENCE_UPDATE.ts | 4 ++-- src/handlers/misc/READY.ts | 6 +++--- src/handlers/misc/TYPING_START.ts | 4 ++-- src/handlers/misc/USER_UPDATE.ts | 4 ++-- src/handlers/roles/GUILD_ROLE_CREATE.ts | 4 ++-- src/handlers/roles/GUILD_ROLE_DELETE.ts | 4 ++-- src/handlers/roles/GUILD_ROLE_UPDATE.ts | 4 ++-- src/handlers/voice/VOICE_SERVER_UPDATE.ts | 4 ++-- src/handlers/voice/VOICE_STATE_UPDATE.ts | 4 ++-- src/handlers/webhooks/WEBHOOKS_UPDATE.ts | 4 ++-- 42 files changed, 88 insertions(+), 88 deletions(-) diff --git a/src/handlers/channels/CHANNEL_CREATE.ts b/src/handlers/channels/CHANNEL_CREATE.ts index 135dbc0d9..679241f19 100644 --- a/src/handlers/channels/CHANNEL_CREATE.ts +++ b/src/handlers/channels/CHANNEL_CREATE.ts @@ -1,8 +1,8 @@ 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"; +import type { Channel } from "../../types/channels/channel.ts"; +import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; export async function handleChannelCreate(data: DiscordGatewayPayload) { const payload = data.d as Channel; diff --git a/src/handlers/channels/CHANNEL_DELETE.ts b/src/handlers/channels/CHANNEL_DELETE.ts index 1b226370b..ea68fd58f 100644 --- a/src/handlers/channels/CHANNEL_DELETE.ts +++ b/src/handlers/channels/CHANNEL_DELETE.ts @@ -1,8 +1,8 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; -import { Channel } from "../../types/channels/channel.ts"; +import type { Channel } from "../../types/channels/channel.ts"; import { DiscordChannelTypes } from "../../types/channels/channel_types.ts"; -import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleChannelDelete(data: DiscordGatewayPayload) { diff --git a/src/handlers/channels/CHANNEL_PINS_UPDATE.ts b/src/handlers/channels/CHANNEL_PINS_UPDATE.ts index b5570bc2e..529e33195 100644 --- a/src/handlers/channels/CHANNEL_PINS_UPDATE.ts +++ b/src/handlers/channels/CHANNEL_PINS_UPDATE.ts @@ -1,7 +1,7 @@ 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 type { ChannelPinsUpdate } from "../../types/channels/channel_pins_update.ts"; +import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleChannelPinsUpdate(data: DiscordGatewayPayload) { diff --git a/src/handlers/channels/CHANNEL_UPDATE.ts b/src/handlers/channels/CHANNEL_UPDATE.ts index 624eaaf70..7fffd35ac 100644 --- a/src/handlers/channels/CHANNEL_UPDATE.ts +++ b/src/handlers/channels/CHANNEL_UPDATE.ts @@ -1,8 +1,8 @@ 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"; +import type { Channel } from "../../types/channels/channel.ts"; +import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleChannelUpdate(data: DiscordGatewayPayload) { diff --git a/src/handlers/commands/APPLICATION_COMMAND_CREATE.ts b/src/handlers/commands/APPLICATION_COMMAND_CREATE.ts index 2ceae936b..c52eddfa1 100644 --- a/src/handlers/commands/APPLICATION_COMMAND_CREATE.ts +++ b/src/handlers/commands/APPLICATION_COMMAND_CREATE.ts @@ -1,6 +1,6 @@ import { eventHandlers } from "../../bot.ts"; -import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { +import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { ApplicationCommandCreateUpdateDelete, } from "../../types/interactions/application_command_create_update_delete.ts"; diff --git a/src/handlers/commands/APPLICATION_COMMAND_DELETE.ts b/src/handlers/commands/APPLICATION_COMMAND_DELETE.ts index 63d96b23e..674b23330 100644 --- a/src/handlers/commands/APPLICATION_COMMAND_DELETE.ts +++ b/src/handlers/commands/APPLICATION_COMMAND_DELETE.ts @@ -1,6 +1,6 @@ import { eventHandlers } from "../../bot.ts"; -import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { +import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { ApplicationCommandCreateUpdateDelete, } from "../../types/interactions/application_command_create_update_delete.ts"; diff --git a/src/handlers/commands/APPLICATION_COMMAND_UPDATE.ts b/src/handlers/commands/APPLICATION_COMMAND_UPDATE.ts index ad9ffde28..b5ac20ee3 100644 --- a/src/handlers/commands/APPLICATION_COMMAND_UPDATE.ts +++ b/src/handlers/commands/APPLICATION_COMMAND_UPDATE.ts @@ -1,6 +1,6 @@ import { eventHandlers } from "../../bot.ts"; -import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { +import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { ApplicationCommandCreateUpdateDelete, } from "../../types/interactions/application_command_create_update_delete.ts"; diff --git a/src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts b/src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts index bbb1c817d..04dba3335 100644 --- a/src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts +++ b/src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts @@ -1,7 +1,7 @@ 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 type { GuildEmojisUpdate } from "../../types/emojis/guild_emojis_update.ts"; +import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; import { Collection } from "../../util/collection.ts"; diff --git a/src/handlers/guilds/GUILD_BAN_ADD.ts b/src/handlers/guilds/GUILD_BAN_ADD.ts index 70d233ff0..584369503 100644 --- a/src/handlers/guilds/GUILD_BAN_ADD.ts +++ b/src/handlers/guilds/GUILD_BAN_ADD.ts @@ -1,7 +1,7 @@ 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 type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { GuildBanAddRemove } from "../../types/guilds/guild_ban_add_remove.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleGuildBanAdd(data: DiscordGatewayPayload) { diff --git a/src/handlers/guilds/GUILD_BAN_REMOVE.ts b/src/handlers/guilds/GUILD_BAN_REMOVE.ts index eb588bd2c..8e7805fbe 100644 --- a/src/handlers/guilds/GUILD_BAN_REMOVE.ts +++ b/src/handlers/guilds/GUILD_BAN_REMOVE.ts @@ -1,7 +1,7 @@ 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 type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { GuildBanAddRemove } from "../../types/guilds/guild_ban_add_remove.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleGuildBanRemove(data: DiscordGatewayPayload) { diff --git a/src/handlers/guilds/GUILD_CREATE.ts b/src/handlers/guilds/GUILD_CREATE.ts index a9cc05791..3c62e57ea 100644 --- a/src/handlers/guilds/GUILD_CREATE.ts +++ b/src/handlers/guilds/GUILD_CREATE.ts @@ -1,8 +1,8 @@ import { eventHandlers } from "../../bot.ts"; 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 type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { Guild } from "../../types/guilds/guild.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; import { ws } from "../../ws/ws.ts"; diff --git a/src/handlers/guilds/GUILD_DELETE.ts b/src/handlers/guilds/GUILD_DELETE.ts index 5b32388e8..ea30c220b 100644 --- a/src/handlers/guilds/GUILD_DELETE.ts +++ b/src/handlers/guilds/GUILD_DELETE.ts @@ -1,7 +1,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 type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { UnavailableGuild } from "../../types/guilds/unavailable_guild.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; import { ws } from "../../ws/ws.ts"; diff --git a/src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts b/src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts index 36b013ec6..136db1a4d 100644 --- a/src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts +++ b/src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts @@ -1,7 +1,7 @@ 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 type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { GuildIntegrationsUpdate } from "../../types/integration/guild_integrations_update.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleGuildIntegrationsUpdate( diff --git a/src/handlers/guilds/GUILD_UPDATE.ts b/src/handlers/guilds/GUILD_UPDATE.ts index 9504e9df0..173337717 100644 --- a/src/handlers/guilds/GUILD_UPDATE.ts +++ b/src/handlers/guilds/GUILD_UPDATE.ts @@ -1,8 +1,8 @@ import { eventHandlers } from "../../bot.ts"; 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 type { GuildUpdateChange } from "../../types/discordeno/guild_update_change.ts"; +import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { Guild } from "../../types/guilds/guild.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleGuildUpdate(data: DiscordGatewayPayload) { diff --git a/src/handlers/integrations/INTEGRATION_CREATE.ts b/src/handlers/integrations/INTEGRATION_CREATE.ts index 1f6aede60..147831a5a 100644 --- a/src/handlers/integrations/INTEGRATION_CREATE.ts +++ b/src/handlers/integrations/INTEGRATION_CREATE.ts @@ -1,6 +1,6 @@ import { eventHandlers } from "../../bot.ts"; -import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { +import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { IntegrationCreateUpdate, } from "../../types/integration/integration_create_update.ts"; diff --git a/src/handlers/integrations/INTEGRATION_DELETE.ts b/src/handlers/integrations/INTEGRATION_DELETE.ts index 1718d2a3c..d7fcbe088 100644 --- a/src/handlers/integrations/INTEGRATION_DELETE.ts +++ b/src/handlers/integrations/INTEGRATION_DELETE.ts @@ -1,6 +1,6 @@ import { eventHandlers } from "../../bot.ts"; -import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { IntegrationDelete } from "../../types/integration/integration_delete.ts"; +import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { IntegrationDelete } from "../../types/integration/integration_delete.ts"; export function handleIntegrationDelete(data: DiscordGatewayPayload) { eventHandlers.integrationDelete?.( diff --git a/src/handlers/integrations/INTEGRATION_UPDATE.ts b/src/handlers/integrations/INTEGRATION_UPDATE.ts index c756ee2b3..4ce7fa940 100644 --- a/src/handlers/integrations/INTEGRATION_UPDATE.ts +++ b/src/handlers/integrations/INTEGRATION_UPDATE.ts @@ -1,6 +1,6 @@ import { eventHandlers } from "../../bot.ts"; -import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { +import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { IntegrationCreateUpdate, } from "../../types/integration/integration_create_update.ts"; diff --git a/src/handlers/interactions/INTERACTION_CREATE.ts b/src/handlers/interactions/INTERACTION_CREATE.ts index 026af104c..6c5a03913 100644 --- a/src/handlers/interactions/INTERACTION_CREATE.ts +++ b/src/handlers/interactions/INTERACTION_CREATE.ts @@ -1,9 +1,9 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; 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 type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; +import type { Interaction } from "../../types/interactions/interaction.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleInteractionCreate(data: DiscordGatewayPayload) { diff --git a/src/handlers/invites/INVITE_CREATE.ts b/src/handlers/invites/INVITE_CREATE.ts index bb5a4d8c7..44ffec43f 100644 --- a/src/handlers/invites/INVITE_CREATE.ts +++ b/src/handlers/invites/INVITE_CREATE.ts @@ -1,6 +1,6 @@ import { eventHandlers } from "../../bot.ts"; -import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { InviteCreate } from "../../types/invites/invite_create.ts"; +import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { InviteCreate } from "../../types/invites/invite_create.ts"; export function handleInviteCreate(data: DiscordGatewayPayload) { eventHandlers.inviteCreate?.( diff --git a/src/handlers/invites/INVITE_DELETE.ts b/src/handlers/invites/INVITE_DELETE.ts index 6c7b137a8..2f09e6f52 100644 --- a/src/handlers/invites/INVITE_DELETE.ts +++ b/src/handlers/invites/INVITE_DELETE.ts @@ -1,6 +1,6 @@ import { eventHandlers } from "../../bot.ts"; -import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { InviteDelete } from "../../types/invites/invite_delete.ts"; +import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { InviteDelete } from "../../types/invites/invite_delete.ts"; export function handleInviteDelete(data: DiscordGatewayPayload) { eventHandlers.inviteDelete?.( diff --git a/src/handlers/members/GUILD_MEMBERS_CHUNK.ts b/src/handlers/members/GUILD_MEMBERS_CHUNK.ts index f1b76e556..65d1eeb76 100644 --- a/src/handlers/members/GUILD_MEMBERS_CHUNK.ts +++ b/src/handlers/members/GUILD_MEMBERS_CHUNK.ts @@ -1,7 +1,7 @@ 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 type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { GuildMembersChunk } from "../../types/members/guild_members_chunk.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; import { Collection } from "../../util/collection.ts"; diff --git a/src/handlers/members/GUILD_MEMBER_ADD.ts b/src/handlers/members/GUILD_MEMBER_ADD.ts index 7743d3d75..8e6e597de 100644 --- a/src/handlers/members/GUILD_MEMBER_ADD.ts +++ b/src/handlers/members/GUILD_MEMBER_ADD.ts @@ -1,8 +1,8 @@ import { eventHandlers } from "../../bot.ts"; 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 type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { GuildMemberAdd } from "../../types/members/guild_member_add.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleGuildMemberAdd(data: DiscordGatewayPayload) { diff --git a/src/handlers/members/GUILD_MEMBER_REMOVE.ts b/src/handlers/members/GUILD_MEMBER_REMOVE.ts index 9a18461f0..dfc051200 100644 --- a/src/handlers/members/GUILD_MEMBER_REMOVE.ts +++ b/src/handlers/members/GUILD_MEMBER_REMOVE.ts @@ -1,7 +1,7 @@ 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 type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { GuildMemberRemove } from "../../types/members/guild_member_remove.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleGuildMemberRemove(data: DiscordGatewayPayload) { diff --git a/src/handlers/members/GUILD_MEMBER_UPDATE.ts b/src/handlers/members/GUILD_MEMBER_UPDATE.ts index 05c4f5a38..72185ddb8 100644 --- a/src/handlers/members/GUILD_MEMBER_UPDATE.ts +++ b/src/handlers/members/GUILD_MEMBER_UPDATE.ts @@ -1,8 +1,8 @@ import { eventHandlers } from "../../bot.ts"; 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 type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { GuildMemberUpdate } from "../../types/members/guild_member_update.ts"; import { bigintToSnowflake, snowflakeToBigint } from "../../util/bigint.ts"; export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) { diff --git a/src/handlers/messages/MESSAGE_CREATE.ts b/src/handlers/messages/MESSAGE_CREATE.ts index 51d6856cc..5492f8664 100644 --- a/src/handlers/messages/MESSAGE_CREATE.ts +++ b/src/handlers/messages/MESSAGE_CREATE.ts @@ -1,9 +1,9 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; 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 type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; +import type { Message } from "../../types/messages/message.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleMessageCreate(data: DiscordGatewayPayload) { diff --git a/src/handlers/messages/MESSAGE_DELETE.ts b/src/handlers/messages/MESSAGE_DELETE.ts index 078d6cfb2..89430f202 100644 --- a/src/handlers/messages/MESSAGE_DELETE.ts +++ b/src/handlers/messages/MESSAGE_DELETE.ts @@ -1,7 +1,7 @@ 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 type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { MessageDelete } from "../../types/messages/message_delete.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleMessageDelete(data: DiscordGatewayPayload) { diff --git a/src/handlers/messages/MESSAGE_DELETE_BULK.ts b/src/handlers/messages/MESSAGE_DELETE_BULK.ts index f5b5ad680..2b585d338 100644 --- a/src/handlers/messages/MESSAGE_DELETE_BULK.ts +++ b/src/handlers/messages/MESSAGE_DELETE_BULK.ts @@ -1,7 +1,7 @@ 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 type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { MessageDeleteBulk } from "../../types/messages/message_delete_bulk.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleMessageDeleteBulk(data: DiscordGatewayPayload) { diff --git a/src/handlers/messages/MESSAGE_REACTION_ADD.ts b/src/handlers/messages/MESSAGE_REACTION_ADD.ts index ec6871a73..1bd69cf8c 100644 --- a/src/handlers/messages/MESSAGE_REACTION_ADD.ts +++ b/src/handlers/messages/MESSAGE_REACTION_ADD.ts @@ -1,8 +1,8 @@ import { botId, eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { structures } from "../../structures/mod.ts"; -import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { +import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { MessageReactionAdd, } from "../../types/messages/message_reaction_add.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; diff --git a/src/handlers/messages/MESSAGE_REACTION_REMOVE.ts b/src/handlers/messages/MESSAGE_REACTION_REMOVE.ts index 652baa592..59c5d77ef 100644 --- a/src/handlers/messages/MESSAGE_REACTION_REMOVE.ts +++ b/src/handlers/messages/MESSAGE_REACTION_REMOVE.ts @@ -1,7 +1,7 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; -import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { +import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { MessageReactionRemove, } from "../../types/messages/message_reaction_remove.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; diff --git a/src/handlers/messages/MESSAGE_REACTION_REMOVE_ALL.ts b/src/handlers/messages/MESSAGE_REACTION_REMOVE_ALL.ts index 0cb0088ed..81b365241 100644 --- a/src/handlers/messages/MESSAGE_REACTION_REMOVE_ALL.ts +++ b/src/handlers/messages/MESSAGE_REACTION_REMOVE_ALL.ts @@ -1,7 +1,7 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; -import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { +import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { MessageReactionRemoveAll, } from "../../types/messages/message_reaction_remove_all.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; diff --git a/src/handlers/messages/MESSAGE_REACTION_REMOVE_EMOJI.ts b/src/handlers/messages/MESSAGE_REACTION_REMOVE_EMOJI.ts index 43ca252ef..4241e718e 100644 --- a/src/handlers/messages/MESSAGE_REACTION_REMOVE_EMOJI.ts +++ b/src/handlers/messages/MESSAGE_REACTION_REMOVE_EMOJI.ts @@ -1,7 +1,7 @@ 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 type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { MessageReactionRemoveEmoji } from "../../types/messages/message_reaction_remove_emoji.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleMessageReactionRemoveEmoji( diff --git a/src/handlers/messages/MESSAGE_UPDATE.ts b/src/handlers/messages/MESSAGE_UPDATE.ts index 648aeec06..61383517e 100644 --- a/src/handlers/messages/MESSAGE_UPDATE.ts +++ b/src/handlers/messages/MESSAGE_UPDATE.ts @@ -1,8 +1,8 @@ import { eventHandlers } from "../../bot.ts"; 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 type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { Message } from "../../types/messages/message.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleMessageUpdate(data: DiscordGatewayPayload) { diff --git a/src/handlers/misc/PRESENCE_UPDATE.ts b/src/handlers/misc/PRESENCE_UPDATE.ts index c770dc8b4..d1c2127c9 100644 --- a/src/handlers/misc/PRESENCE_UPDATE.ts +++ b/src/handlers/misc/PRESENCE_UPDATE.ts @@ -1,7 +1,7 @@ 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 type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { PresenceUpdate } from "../../types/misc/presence_update.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handlePresenceUpdate(data: DiscordGatewayPayload) { diff --git a/src/handlers/misc/READY.ts b/src/handlers/misc/READY.ts index 782e88f29..0ff0afa34 100644 --- a/src/handlers/misc/READY.ts +++ b/src/handlers/misc/READY.ts @@ -2,9 +2,9 @@ import { eventHandlers, setApplicationId, setBotId } from "../../bot.ts"; import { cache, cacheHandlers } from "../../cache.ts"; import { initialMemberLoadQueue } from "../../structures/guild.ts"; 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 type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { Ready } from "../../types/gateway/ready.ts"; +import type { GuildMemberWithUser } from "../../types/mod.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; import { ws } from "../../ws/ws.ts"; diff --git a/src/handlers/misc/TYPING_START.ts b/src/handlers/misc/TYPING_START.ts index 1cfde4296..707edfc4f 100644 --- a/src/handlers/misc/TYPING_START.ts +++ b/src/handlers/misc/TYPING_START.ts @@ -1,6 +1,6 @@ import { eventHandlers } from "../../bot.ts"; -import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { TypingStart } from "../../types/misc/typing_start.ts"; +import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { TypingStart } from "../../types/misc/typing_start.ts"; export function handleTypingStart(data: DiscordGatewayPayload) { eventHandlers.typingStart?.( diff --git a/src/handlers/misc/USER_UPDATE.ts b/src/handlers/misc/USER_UPDATE.ts index 02297cce9..fbe68ff70 100644 --- a/src/handlers/misc/USER_UPDATE.ts +++ b/src/handlers/misc/USER_UPDATE.ts @@ -1,7 +1,7 @@ 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 type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { User } from "../../types/users/user.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleUserUpdate(data: DiscordGatewayPayload) { diff --git a/src/handlers/roles/GUILD_ROLE_CREATE.ts b/src/handlers/roles/GUILD_ROLE_CREATE.ts index acdc40c0b..c8801e2ce 100644 --- a/src/handlers/roles/GUILD_ROLE_CREATE.ts +++ b/src/handlers/roles/GUILD_ROLE_CREATE.ts @@ -1,8 +1,8 @@ import { eventHandlers } from "../../bot.ts"; 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 type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { GuildRoleCreate } from "../../types/mod.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleGuildRoleCreate(data: DiscordGatewayPayload) { diff --git a/src/handlers/roles/GUILD_ROLE_DELETE.ts b/src/handlers/roles/GUILD_ROLE_DELETE.ts index 8fd35f5e1..bed41d946 100644 --- a/src/handlers/roles/GUILD_ROLE_DELETE.ts +++ b/src/handlers/roles/GUILD_ROLE_DELETE.ts @@ -1,7 +1,7 @@ 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 type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { GuildRoleDelete } from "../../types/guilds/guild_role_delete.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleGuildRoleDelete(data: DiscordGatewayPayload) { diff --git a/src/handlers/roles/GUILD_ROLE_UPDATE.ts b/src/handlers/roles/GUILD_ROLE_UPDATE.ts index ae9c6e6d1..e3c1b445f 100644 --- a/src/handlers/roles/GUILD_ROLE_UPDATE.ts +++ b/src/handlers/roles/GUILD_ROLE_UPDATE.ts @@ -1,8 +1,8 @@ import { eventHandlers } from "../../bot.ts"; 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 type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { GuildRoleUpdate } from "../../types/mod.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleGuildRoleUpdate(data: DiscordGatewayPayload) { diff --git a/src/handlers/voice/VOICE_SERVER_UPDATE.ts b/src/handlers/voice/VOICE_SERVER_UPDATE.ts index 3f6128a52..8150f7f01 100644 --- a/src/handlers/voice/VOICE_SERVER_UPDATE.ts +++ b/src/handlers/voice/VOICE_SERVER_UPDATE.ts @@ -1,7 +1,7 @@ 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 type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { VoiceServerUpdate } from "../../types/voice/voice_server_update.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleVoiceServerUpdate(data: DiscordGatewayPayload) { diff --git a/src/handlers/voice/VOICE_STATE_UPDATE.ts b/src/handlers/voice/VOICE_STATE_UPDATE.ts index e358eb3b6..7c9b93751 100644 --- a/src/handlers/voice/VOICE_STATE_UPDATE.ts +++ b/src/handlers/voice/VOICE_STATE_UPDATE.ts @@ -1,8 +1,8 @@ import { eventHandlers } from "../../bot.ts"; 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 type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { VoiceState } from "../../types/voice/voice_state.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleVoiceStateUpdate(data: DiscordGatewayPayload) { diff --git a/src/handlers/webhooks/WEBHOOKS_UPDATE.ts b/src/handlers/webhooks/WEBHOOKS_UPDATE.ts index 110a6761d..9512aa58f 100644 --- a/src/handlers/webhooks/WEBHOOKS_UPDATE.ts +++ b/src/handlers/webhooks/WEBHOOKS_UPDATE.ts @@ -1,6 +1,6 @@ import { eventHandlers } from "../../bot.ts"; -import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { WebhookUpdate } from "../../types/webhooks/webhooks_update.ts"; +import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import type { WebhookUpdate } from "../../types/webhooks/webhooks_update.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export function handleWebhooksUpdate(data: DiscordGatewayPayload) { From 19cbad63a2d40fe6a105d6e8e023c9431f5643e8 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 12:38:54 +0200 Subject: [PATCH 099/148] this is the biggest pain ever --- .../channels/channel_overwrite_has_permission.ts | 4 ++-- src/helpers/channels/clone_channel.ts | 2 +- src/helpers/channels/create_channel.ts | 6 +++--- src/helpers/channels/edit_channel.ts | 4 ++-- src/helpers/channels/edit_channel_overwrite.ts | 2 +- src/helpers/channels/follow_channel.ts | 2 +- src/helpers/channels/get_channel.ts | 2 +- 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/swap_channels.ts | 2 +- .../batch_edit_slash_command_permissions.ts | 2 +- src/helpers/commands/create_slash_command.ts | 4 ++-- .../commands/edit_slash_command_permissions.ts | 2 +- src/helpers/commands/edit_slash_response.ts | 2 +- src/helpers/commands/get_slash_command.ts | 2 +- .../commands/get_slash_command_permission.ts | 2 +- .../commands/get_slash_command_permissions.ts | 2 +- src/helpers/commands/get_slash_commands.ts | 2 +- src/helpers/commands/send_interaction_response.ts | 2 +- src/helpers/commands/upsert_slash_command.ts | 4 ++-- src/helpers/commands/upsert_slash_commands.ts | 4 ++-- src/helpers/discovery/add_discovery_subcategory.ts | 2 +- src/helpers/discovery/edit_discovery.ts | 4 ++-- src/helpers/discovery/get_discovery_categories.ts | 2 +- src/helpers/discovery/valid_discovery_term.ts | 2 +- src/helpers/emojis/create_emoji.ts | 2 +- src/helpers/emojis/edit_emoji.ts | 4 ++-- src/helpers/emojis/get_emoji.ts | 2 +- src/helpers/emojis/get_emojis.ts | 2 +- src/helpers/guilds/create_guild.ts | 4 ++-- src/helpers/guilds/edit_guild.ts | 4 ++-- src/helpers/guilds/edit_welcome_screen.ts | 4 ++-- src/helpers/guilds/edit_widget.ts | 2 +- src/helpers/guilds/get_audit_logs.ts | 4 ++-- src/helpers/guilds/get_available_voice_regions.ts | 2 +- src/helpers/guilds/get_ban.ts | 2 +- src/helpers/guilds/get_bans.ts | 2 +- src/helpers/guilds/get_guild.ts | 2 +- 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 | 4 ++-- src/helpers/guilds/guild_icon_url.ts | 4 ++-- src/helpers/guilds/guild_splash_url.ts | 4 ++-- src/helpers/guilds/update_bot_voice_state.ts | 14 ++++++-------- src/helpers/guilds/update_user_voice_state.ts | 12 +++++------- src/helpers/integrations/get_integrations.ts | 2 +- src/helpers/invites/create_invite.ts | 4 ++-- src/helpers/invites/delete_invite.ts | 2 +- src/helpers/invites/get_channel_invites.ts | 2 +- src/helpers/invites/get_invite.ts | 2 +- src/helpers/invites/get_invites.ts | 2 +- src/helpers/members/avatar_url.ts | 4 ++-- src/helpers/members/ban_member.ts | 2 +- src/helpers/members/edit_bot_profile.ts | 2 +- src/helpers/members/edit_member.ts | 6 +++--- src/helpers/members/get_member.ts | 2 +- src/helpers/members/get_members.ts | 4 ++-- src/helpers/members/prune_members.ts | 2 +- src/helpers/members/search_members.ts | 4 ++-- src/helpers/members/send_direct_message.ts | 4 ++-- src/helpers/messages/edit_message.ts | 4 ++-- src/helpers/messages/get_message.ts | 2 +- src/helpers/messages/get_messages.ts | 2 +- src/helpers/messages/get_reactions.ts | 4 ++-- src/helpers/messages/publish_message.ts | 2 +- src/helpers/messages/send_message.ts | 6 +++--- src/helpers/misc/get_gateway_bot.ts | 2 +- src/helpers/misc/get_user.ts | 2 +- src/helpers/roles/create_role.ts | 2 +- src/helpers/roles/edit_role.ts | 3 ++- src/helpers/roles/get_roles.ts | 2 +- .../templates/create_guild_from_template.ts | 4 ++-- src/helpers/templates/create_guild_template.ts | 2 +- src/helpers/templates/delete_guild_template.ts | 2 +- src/helpers/templates/edit_guild_template.ts | 4 ++-- src/helpers/templates/get_guild_templates.ts | 2 +- src/helpers/templates/get_template.ts | 2 +- src/helpers/templates/sync_guild_template.ts | 2 +- src/helpers/type_guards/is_action_row.ts | 4 ++-- src/helpers/type_guards/is_button.ts | 4 ++-- src/helpers/webhooks/create_webhook.ts | 4 ++-- src/helpers/webhooks/edit_webhook.ts | 4 ++-- src/helpers/webhooks/edit_webhook_message.ts | 4 ++-- src/helpers/webhooks/edit_webhook_with_token.ts | 4 ++-- src/helpers/webhooks/execute_webhook.ts | 4 ++-- src/helpers/webhooks/get_webhook.ts | 2 +- src/helpers/webhooks/get_webhook_with_token.ts | 2 +- src/helpers/webhooks/get_webhooks.ts | 2 +- 95 files changed, 141 insertions(+), 144 deletions(-) diff --git a/src/helpers/channels/channel_overwrite_has_permission.ts b/src/helpers/channels/channel_overwrite_has_permission.ts index bcf6b3407..2b0adcd12 100644 --- a/src/helpers/channels/channel_overwrite_has_permission.ts +++ b/src/helpers/channels/channel_overwrite_has_permission.ts @@ -1,6 +1,6 @@ -import { DiscordOverwrite } from "../../types/channels/overwrite.ts"; +import type { DiscordOverwrite } from "../../types/channels/overwrite.ts"; import { DiscordBitwisePermissionFlags } from "../../types/permissions/bitwise_permission_flags.ts"; -import { PermissionStrings } from "../../types/permissions/permission_strings.ts"; +import type { 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( diff --git a/src/helpers/channels/clone_channel.ts b/src/helpers/channels/clone_channel.ts index 200189a32..d7ba2aab5 100644 --- a/src/helpers/channels/clone_channel.ts +++ b/src/helpers/channels/clone_channel.ts @@ -1,6 +1,6 @@ import { cacheHandlers } from "../../cache.ts"; import { DiscordChannelTypes } from "../../types/channels/channel_types.ts"; -import { CreateGuildChannel } from "../../types/guilds/create_guild_channel.ts"; +import type { 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"; diff --git a/src/helpers/channels/create_channel.ts b/src/helpers/channels/create_channel.ts index 316362399..cb0b70bb6 100644 --- a/src/helpers/channels/create_channel.ts +++ b/src/helpers/channels/create_channel.ts @@ -2,13 +2,13 @@ import { eventHandlers } from "../../bot.ts"; 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 type { Channel } from "../../types/channels/channel.ts"; import { DiscordChannelTypes } from "../../types/channels/channel_types.ts"; -import { +import type { CreateGuildChannel, DiscordCreateGuildChannel, } from "../../types/guilds/create_guild_channel.ts"; -import { PermissionStrings } from "../../types/permissions/permission_strings.ts"; +import type { PermissionStrings } from "../../types/permissions/permission_strings.ts"; import { endpoints } from "../../util/constants.ts"; import { calculateBits, diff --git a/src/helpers/channels/edit_channel.ts b/src/helpers/channels/edit_channel.ts index 26a40fdfa..57d302637 100644 --- a/src/helpers/channels/edit_channel.ts +++ b/src/helpers/channels/edit_channel.ts @@ -1,7 +1,7 @@ import { eventHandlers } from "../../bot.ts"; import { rest } from "../../rest/rest.ts"; -import { ModifyChannel } from "../../types/channels/modify_channel.ts"; -import { Channel } from "../../types/mod.ts"; +import type { Channel } from "../../types/channels/channel.ts"; +import type { ModifyChannel } from "../../types/channels/modify_channel.ts"; import { endpoints } from "../../util/constants.ts"; import { calculateBits, diff --git a/src/helpers/channels/edit_channel_overwrite.ts b/src/helpers/channels/edit_channel_overwrite.ts index 056cd6fc4..179bddbd1 100644 --- a/src/helpers/channels/edit_channel_overwrite.ts +++ b/src/helpers/channels/edit_channel_overwrite.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { Overwrite } from "../../types/channels/overwrite.ts"; +import type { Overwrite } from "../../types/channels/overwrite.ts"; import { endpoints } from "../../util/constants.ts"; import { calculateBits, diff --git a/src/helpers/channels/follow_channel.ts b/src/helpers/channels/follow_channel.ts index 6ef4ed0e7..ede74126e 100644 --- a/src/helpers/channels/follow_channel.ts +++ b/src/helpers/channels/follow_channel.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { FollowedChannel } from "../../types/channels/followed_channel.ts"; +import type { FollowedChannel } from "../../types/channels/followed_channel.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/channels/get_channel.ts b/src/helpers/channels/get_channel.ts index 122f075c8..4818bba41 100644 --- a/src/helpers/channels/get_channel.ts +++ b/src/helpers/channels/get_channel.ts @@ -1,7 +1,7 @@ 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 type { Channel } from "../../types/channels/channel.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; import { endpoints } from "../../util/constants.ts"; diff --git a/src/helpers/channels/get_channel_webhooks.ts b/src/helpers/channels/get_channel_webhooks.ts index d3752ff97..9f4110c43 100644 --- a/src/helpers/channels/get_channel_webhooks.ts +++ b/src/helpers/channels/get_channel_webhooks.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { Webhook } from "../../types/webhooks/webhook.ts"; +import type { Webhook } from "../../types/webhooks/webhook.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/channels/get_channels.ts b/src/helpers/channels/get_channels.ts index 681601cd1..53d72529d 100644 --- a/src/helpers/channels/get_channels.ts +++ b/src/helpers/channels/get_channels.ts @@ -1,7 +1,7 @@ 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 type { Channel } from "../../types/channels/channel.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; diff --git a/src/helpers/channels/get_pins.ts b/src/helpers/channels/get_pins.ts index dd4d26954..63c2090f4 100644 --- a/src/helpers/channels/get_pins.ts +++ b/src/helpers/channels/get_pins.ts @@ -1,6 +1,6 @@ import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; -import { Message } from "../../types/messages/message.ts"; +import type { Message } from "../../types/messages/message.ts"; import { endpoints } from "../../util/constants.ts"; /** Get pinned messages in this channel. */ diff --git a/src/helpers/channels/swap_channels.ts b/src/helpers/channels/swap_channels.ts index 21dddd139..a3b3135f5 100644 --- a/src/helpers/channels/swap_channels.ts +++ b/src/helpers/channels/swap_channels.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { ModifyGuildChannelPositions } from "../../types/guilds/modify_guild_channel_position.ts"; +import type { ModifyGuildChannelPositions } from "../../types/guilds/modify_guild_channel_position.ts"; import { endpoints } from "../../util/constants.ts"; /** Modify the positions of channels on the guild. Requires MANAGE_CHANNELS permisison. */ diff --git a/src/helpers/commands/batch_edit_slash_command_permissions.ts b/src/helpers/commands/batch_edit_slash_command_permissions.ts index 139ee5981..8be782bff 100644 --- a/src/helpers/commands/batch_edit_slash_command_permissions.ts +++ b/src/helpers/commands/batch_edit_slash_command_permissions.ts @@ -1,6 +1,6 @@ import { applicationId } from "../../bot.ts"; import { rest } from "../../rest/rest.ts"; -import { ApplicationCommandPermissions } from "../../types/interactions/application_command_permissions.ts"; +import type { ApplicationCommandPermissions } from "../../types/interactions/application_command_permissions.ts"; import { endpoints } from "../../util/constants.ts"; import { camelKeysToSnakeCase } from "../../util/utils.ts"; diff --git a/src/helpers/commands/create_slash_command.ts b/src/helpers/commands/create_slash_command.ts index 9a6f1f36d..b5241f556 100644 --- a/src/helpers/commands/create_slash_command.ts +++ b/src/helpers/commands/create_slash_command.ts @@ -1,7 +1,7 @@ import { applicationId } from "../../bot.ts"; import { rest } from "../../rest/rest.ts"; -import { CreateGlobalApplicationCommand } from "../../types/interactions/create_global_application_command.ts"; -import { ApplicationCommand } from "../../types/mod.ts"; +import type { ApplicationCommand } from "../../types/interactions/application_command.ts"; +import type { CreateGlobalApplicationCommand } from "../../types/interactions/create_global_application_command.ts"; import { endpoints } from "../../util/constants.ts"; import { camelKeysToSnakeCase, diff --git a/src/helpers/commands/edit_slash_command_permissions.ts b/src/helpers/commands/edit_slash_command_permissions.ts index 743780b45..bbaae3bc4 100644 --- a/src/helpers/commands/edit_slash_command_permissions.ts +++ b/src/helpers/commands/edit_slash_command_permissions.ts @@ -1,6 +1,6 @@ import { applicationId } from "../../bot.ts"; import { rest } from "../../rest/rest.ts"; -import { ApplicationCommandPermissions } from "../../types/interactions/application_command_permissions.ts"; +import type { ApplicationCommandPermissions } from "../../types/interactions/application_command_permissions.ts"; import { endpoints } from "../../util/constants.ts"; import { camelKeysToSnakeCase } from "../../util/utils.ts"; diff --git a/src/helpers/commands/edit_slash_response.ts b/src/helpers/commands/edit_slash_response.ts index 2c458f047..9857805e6 100644 --- a/src/helpers/commands/edit_slash_response.ts +++ b/src/helpers/commands/edit_slash_response.ts @@ -1,7 +1,7 @@ import { applicationId } from "../../bot.ts"; import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; -import { DiscordenoEditWebhookMessage } from "../../types/discordeno/edit_webhook_message.ts"; +import type { DiscordenoEditWebhookMessage } from "../../types/discordeno/edit_webhook_message.ts"; import { DiscordAllowedMentionsTypes } from "../../types/messages/allowed_mentions_types.ts"; import { Errors } from "../../types/misc/errors.ts"; import { endpoints } from "../../util/constants.ts"; diff --git a/src/helpers/commands/get_slash_command.ts b/src/helpers/commands/get_slash_command.ts index 2c0f9be01..846b47bf0 100644 --- a/src/helpers/commands/get_slash_command.ts +++ b/src/helpers/commands/get_slash_command.ts @@ -1,6 +1,6 @@ import { applicationId } from "../../bot.ts"; import { rest } from "../../rest/rest.ts"; -import { ApplicationCommand } from "../../types/interactions/application_command.ts"; +import type { ApplicationCommand } from "../../types/interactions/application_command.ts"; 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. */ diff --git a/src/helpers/commands/get_slash_command_permission.ts b/src/helpers/commands/get_slash_command_permission.ts index ead639b36..f07c92f18 100644 --- a/src/helpers/commands/get_slash_command_permission.ts +++ b/src/helpers/commands/get_slash_command_permission.ts @@ -1,6 +1,6 @@ import { applicationId } from "../../bot.ts"; import { rest } from "../../rest/rest.ts"; -import { GuildApplicationCommandPermissions } from "../../types/interactions/guild_application_command_permissions.ts"; +import type { GuildApplicationCommandPermissions } from "../../types/interactions/guild_application_command_permissions.ts"; import { endpoints } from "../../util/constants.ts"; /** Fetches command permissions for a specific command for your application in a guild. Returns a GuildApplicationCommandPermissions object. */ diff --git a/src/helpers/commands/get_slash_command_permissions.ts b/src/helpers/commands/get_slash_command_permissions.ts index 821642c8d..07c12fb8f 100644 --- a/src/helpers/commands/get_slash_command_permissions.ts +++ b/src/helpers/commands/get_slash_command_permissions.ts @@ -1,6 +1,6 @@ import { applicationId } from "../../bot.ts"; import { rest } from "../../rest/rest.ts"; -import { GuildApplicationCommandPermissions } from "../../types/interactions/guild_application_command_permissions.ts"; +import type { GuildApplicationCommandPermissions } from "../../types/interactions/guild_application_command_permissions.ts"; import { endpoints } from "../../util/constants.ts"; /** Fetches command permissions for all commands for your application in a guild. Returns an array of GuildApplicationCommandPermissions objects. */ diff --git a/src/helpers/commands/get_slash_commands.ts b/src/helpers/commands/get_slash_commands.ts index bdac9a9bc..c4f4c8eff 100644 --- a/src/helpers/commands/get_slash_commands.ts +++ b/src/helpers/commands/get_slash_commands.ts @@ -1,6 +1,6 @@ import { applicationId } from "../../bot.ts"; import { rest } from "../../rest/rest.ts"; -import { ApplicationCommand } from "../../types/interactions/application_command.ts"; +import type { ApplicationCommand } from "../../types/interactions/application_command.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; diff --git a/src/helpers/commands/send_interaction_response.ts b/src/helpers/commands/send_interaction_response.ts index 6200c6641..dae5c23bd 100644 --- a/src/helpers/commands/send_interaction_response.ts +++ b/src/helpers/commands/send_interaction_response.ts @@ -1,7 +1,7 @@ import { applicationId, eventHandlers } from "../../bot.ts"; import { cache } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; -import { DiscordenoInteractionResponse } from "../../types/discordeno/interaction_response.ts"; +import type { DiscordenoInteractionResponse } from "../../types/discordeno/interaction_response.ts"; import { endpoints } from "../../util/constants.ts"; /** diff --git a/src/helpers/commands/upsert_slash_command.ts b/src/helpers/commands/upsert_slash_command.ts index d0211400d..ed2dc20f9 100644 --- a/src/helpers/commands/upsert_slash_command.ts +++ b/src/helpers/commands/upsert_slash_command.ts @@ -1,7 +1,7 @@ import { applicationId } from "../../bot.ts"; import { rest } from "../../rest/rest.ts"; -import { EditGlobalApplicationCommand } from "../../types/interactions/edit_global_application_command.ts"; -import { ApplicationCommand } from "../../types/mod.ts"; +import type { ApplicationCommand } from "../../types/interactions/application_command.ts"; +import type { EditGlobalApplicationCommand } from "../../types/interactions/edit_global_application_command.ts"; import { endpoints } from "../../util/constants.ts"; import { validateSlashCommands } from "../../util/utils.ts"; diff --git a/src/helpers/commands/upsert_slash_commands.ts b/src/helpers/commands/upsert_slash_commands.ts index 3be28f765..b49c2cb41 100644 --- a/src/helpers/commands/upsert_slash_commands.ts +++ b/src/helpers/commands/upsert_slash_commands.ts @@ -1,7 +1,7 @@ import { applicationId } from "../../bot.ts"; import { rest } from "../../rest/rest.ts"; -import { EditGlobalApplicationCommand } from "../../types/interactions/edit_global_application_command.ts"; -import { ApplicationCommand } from "../../types/mod.ts"; +import type { ApplicationCommand } from "../../types/interactions/application_command.ts"; +import type { EditGlobalApplicationCommand } from "../../types/interactions/edit_global_application_command.ts"; import { endpoints } from "../../util/constants.ts"; import { validateSlashCommands } from "../../util/utils.ts"; diff --git a/src/helpers/discovery/add_discovery_subcategory.ts b/src/helpers/discovery/add_discovery_subcategory.ts index 3341f394c..4061925cd 100644 --- a/src/helpers/discovery/add_discovery_subcategory.ts +++ b/src/helpers/discovery/add_discovery_subcategory.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { +import type { AddGuildDiscoverySubcategory, } from "../../types/discovery/add_guild_discovery_subcategory.ts"; import { endpoints } from "../../util/constants.ts"; diff --git a/src/helpers/discovery/edit_discovery.ts b/src/helpers/discovery/edit_discovery.ts index e94c7a60b..71f7e3ab5 100644 --- a/src/helpers/discovery/edit_discovery.ts +++ b/src/helpers/discovery/edit_discovery.ts @@ -1,6 +1,6 @@ import { rest } from "../../rest/rest.ts"; -import { DiscoveryMetadata } from "../../types/discovery/discovery_metadata.ts"; -import { ModifyGuildDiscoveryMetadata } from "../../types/discovery/modify_guild_discovery_metadata.ts"; +import type { DiscoveryMetadata } from "../../types/discovery/discovery_metadata.ts"; +import type { ModifyGuildDiscoveryMetadata } from "../../types/discovery/modify_guild_discovery_metadata.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; import { camelKeysToSnakeCase } from "../../util/utils.ts"; diff --git a/src/helpers/discovery/get_discovery_categories.ts b/src/helpers/discovery/get_discovery_categories.ts index 8ec9858f5..0ac60d848 100644 --- a/src/helpers/discovery/get_discovery_categories.ts +++ b/src/helpers/discovery/get_discovery_categories.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { DiscoveryCategory } from "../../types/discovery/discovery_category.ts"; +import type { DiscoveryCategory } from "../../types/discovery/discovery_category.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; diff --git a/src/helpers/discovery/valid_discovery_term.ts b/src/helpers/discovery/valid_discovery_term.ts index 5a96016af..b41a60742 100644 --- a/src/helpers/discovery/valid_discovery_term.ts +++ b/src/helpers/discovery/valid_discovery_term.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { ValidateDiscoverySearchTerm } from "../../types/discovery/validate_discovery_search_term.ts"; +import type { ValidateDiscoverySearchTerm } from "../../types/discovery/validate_discovery_search_term.ts"; import { endpoints } from "../../util/constants.ts"; export async function validDiscoveryTerm(term: string) { diff --git a/src/helpers/emojis/create_emoji.ts b/src/helpers/emojis/create_emoji.ts index 504bdd299..432885fc0 100644 --- a/src/helpers/emojis/create_emoji.ts +++ b/src/helpers/emojis/create_emoji.ts @@ -1,6 +1,6 @@ import { rest } from "../../rest/rest.ts"; import { CreateGuildEmoji } from "../../types/emojis/create_guild_emoji.ts"; -import { Emoji } from "../../types/emojis/emoji.ts"; +import type { Emoji } from "../../types/emojis/emoji.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/emojis/edit_emoji.ts b/src/helpers/emojis/edit_emoji.ts index 5d2a0f8ed..87264c5f6 100644 --- a/src/helpers/emojis/edit_emoji.ts +++ b/src/helpers/emojis/edit_emoji.ts @@ -1,6 +1,6 @@ import { rest } from "../../rest/rest.ts"; -import { ModifyGuildEmoji } from "../../types/emojis/modify_guild_emoji.ts"; -import { Emoji } from "../../types/mod.ts"; +import type { Emoji } from "../../types/emojis/emoji.ts"; +import type { ModifyGuildEmoji } from "../../types/emojis/modify_guild_emoji.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/emojis/get_emoji.ts b/src/helpers/emojis/get_emoji.ts index d66ac2aa1..9679ee86a 100644 --- a/src/helpers/emojis/get_emoji.ts +++ b/src/helpers/emojis/get_emoji.ts @@ -1,6 +1,6 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; -import { Emoji } from "../../types/emojis/emoji.ts"; +import type { Emoji } from "../../types/emojis/emoji.ts"; import { Errors } from "../../types/misc/errors.ts"; import { endpoints } from "../../util/constants.ts"; diff --git a/src/helpers/emojis/get_emojis.ts b/src/helpers/emojis/get_emojis.ts index c0e56b65f..e3dfa30fd 100644 --- a/src/helpers/emojis/get_emojis.ts +++ b/src/helpers/emojis/get_emojis.ts @@ -1,7 +1,7 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; -import { Emoji } from "../../types/emojis/emoji.ts"; +import type { 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"; diff --git a/src/helpers/guilds/create_guild.ts b/src/helpers/guilds/create_guild.ts index 40c28f3fa..517a0f63c 100644 --- a/src/helpers/guilds/create_guild.ts +++ b/src/helpers/guilds/create_guild.ts @@ -2,8 +2,8 @@ import { botId } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; -import { CreateGuild } from "../../types/guilds/create_guild.ts"; -import { Guild } from "../../types/guilds/guild.ts"; +import type { CreateGuild } from "../../types/guilds/create_guild.ts"; +import type { Guild } from "../../types/guilds/guild.ts"; import { endpoints } from "../../util/constants.ts"; import { getMember } from "../members/get_member.ts"; diff --git a/src/helpers/guilds/edit_guild.ts b/src/helpers/guilds/edit_guild.ts index 212419486..278597312 100644 --- a/src/helpers/guilds/edit_guild.ts +++ b/src/helpers/guilds/edit_guild.ts @@ -1,8 +1,8 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; -import { Guild } from "../../types/guilds/guild.ts"; -import { ModifyGuild } from "../../types/guilds/modify_guild.ts"; +import type { Guild } from "../../types/guilds/guild.ts"; +import type { ModifyGuild } from "../../types/guilds/modify_guild.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; import { urlToBase64 } from "../../util/utils.ts"; diff --git a/src/helpers/guilds/edit_welcome_screen.ts b/src/helpers/guilds/edit_welcome_screen.ts index 284f1fb96..29114dea3 100644 --- a/src/helpers/guilds/edit_welcome_screen.ts +++ b/src/helpers/guilds/edit_welcome_screen.ts @@ -1,6 +1,6 @@ import { rest } from "../../rest/rest.ts"; -import { ModifyGuildWelcomeScreen } from "../../types/guilds/modify_guild_welcome_screen.ts"; -import { WelcomeScreen } from "../../types/mod.ts"; +import type { ModifyGuildWelcomeScreen } from "../../types/guilds/modify_guild_welcome_screen.ts"; +import type { WelcomeScreen } from "../../types/guilds/welcome_screen.ts"; import { endpoints } from "../../util/constants.ts"; import { camelKeysToSnakeCase } from "../../util/utils.ts"; diff --git a/src/helpers/guilds/edit_widget.ts b/src/helpers/guilds/edit_widget.ts index 8a27129b3..9cc0ccd69 100644 --- a/src/helpers/guilds/edit_widget.ts +++ b/src/helpers/guilds/edit_widget.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { GuildWidget } from "../../types/guilds/guild_widget.ts"; +import type { GuildWidget } from "../../types/guilds/guild_widget.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/guilds/get_audit_logs.ts b/src/helpers/guilds/get_audit_logs.ts index babcc0354..a090fbf49 100644 --- a/src/helpers/guilds/get_audit_logs.ts +++ b/src/helpers/guilds/get_audit_logs.ts @@ -1,6 +1,6 @@ import { rest } from "../../rest/rest.ts"; -import { AuditLog } from "../../types/audit_log/audit_log.ts"; -import { GetGuildAuditLog } from "../../types/audit_log/get_guild_audit_log.ts"; +import type { AuditLog } from "../../types/audit_log/audit_log.ts"; +import type { GetGuildAuditLog } from "../../types/audit_log/get_guild_audit_log.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; import { camelKeysToSnakeCase } from "../../util/utils.ts"; diff --git a/src/helpers/guilds/get_available_voice_regions.ts b/src/helpers/guilds/get_available_voice_regions.ts index 5570e4916..2111f6a3d 100644 --- a/src/helpers/guilds/get_available_voice_regions.ts +++ b/src/helpers/guilds/get_available_voice_regions.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { VoiceRegion } from "../../types/voice/voice_region.ts"; +import type { VoiceRegion } from "../../types/voice/voice_region.ts"; import { endpoints } from "../../util/constants.ts"; /** Returns an array of voice regions that can be used when creating servers. */ diff --git a/src/helpers/guilds/get_ban.ts b/src/helpers/guilds/get_ban.ts index db70fc796..c6f73a22a 100644 --- a/src/helpers/guilds/get_ban.ts +++ b/src/helpers/guilds/get_ban.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { Ban } from "../../types/guilds/ban.ts"; +import type { Ban } from "../../types/guilds/ban.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/guilds/get_bans.ts b/src/helpers/guilds/get_bans.ts index ba939dfb8..f2a09617d 100644 --- a/src/helpers/guilds/get_bans.ts +++ b/src/helpers/guilds/get_bans.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { Ban } from "../../types/guilds/ban.ts"; +import type { Ban } from "../../types/guilds/ban.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; diff --git a/src/helpers/guilds/get_guild.ts b/src/helpers/guilds/get_guild.ts index 0a809bbf2..3b13a74dc 100644 --- a/src/helpers/guilds/get_guild.ts +++ b/src/helpers/guilds/get_guild.ts @@ -1,7 +1,7 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; -import { Guild } from "../../types/guilds/guild.ts"; +import type { Guild } from "../../types/guilds/guild.ts"; import { endpoints } from "../../util/constants.ts"; import { ws } from "../../ws/ws.ts"; diff --git a/src/helpers/guilds/get_guild_preview.ts b/src/helpers/guilds/get_guild_preview.ts index b5024f2b8..a62379a6d 100644 --- a/src/helpers/guilds/get_guild_preview.ts +++ b/src/helpers/guilds/get_guild_preview.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { GuildPreview } from "../../types/guilds/guild_preview.ts"; +import type { 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. */ diff --git a/src/helpers/guilds/get_prune_count.ts b/src/helpers/guilds/get_prune_count.ts index 27f1691cc..fe25797d6 100644 --- a/src/helpers/guilds/get_prune_count.ts +++ b/src/helpers/guilds/get_prune_count.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { GetGuildPruneCountQuery } from "../../types/guilds/get_guild_prune_count.ts"; +import type { GetGuildPruneCountQuery } from "../../types/guilds/get_guild_prune_count.ts"; import { Errors } from "../../types/misc/errors.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/guilds/get_vainty_url.ts b/src/helpers/guilds/get_vainty_url.ts index c14719b30..9554b2b04 100644 --- a/src/helpers/guilds/get_vainty_url.ts +++ b/src/helpers/guilds/get_vainty_url.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { InviteMetadata } from "../../types/invites/invite_metadata.ts"; +import type { 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. */ diff --git a/src/helpers/guilds/get_voice_regions.ts b/src/helpers/guilds/get_voice_regions.ts index ad1598ce5..966867d82 100644 --- a/src/helpers/guilds/get_voice_regions.ts +++ b/src/helpers/guilds/get_voice_regions.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { VoiceRegion } from "../../types/voice/voice_region.ts"; +import type { VoiceRegion } from "../../types/voice/voice_region.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; diff --git a/src/helpers/guilds/get_welcome_screen.ts b/src/helpers/guilds/get_welcome_screen.ts index f30b8e9c7..2b20e2826 100644 --- a/src/helpers/guilds/get_welcome_screen.ts +++ b/src/helpers/guilds/get_welcome_screen.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { WelcomeScreen } from "../../types/mod.ts"; +import type { WelcomeScreen } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; export async function getWelcomeScreen(guildId: bigint) { diff --git a/src/helpers/guilds/get_widget.ts b/src/helpers/guilds/get_widget.ts index 0be0e4991..9a31b2c30 100644 --- a/src/helpers/guilds/get_widget.ts +++ b/src/helpers/guilds/get_widget.ts @@ -1,6 +1,6 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; -import { GuildWidgetDetails } from "../../types/guilds/guild_widget_details.ts"; +import type { GuildWidgetDetails } from "../../types/guilds/guild_widget_details.ts"; import { Errors } from "../../types/misc/errors.ts"; import { endpoints } from "../../util/constants.ts"; diff --git a/src/helpers/guilds/get_widget_image_url.ts b/src/helpers/guilds/get_widget_image_url.ts index ede9e97ff..e754b0aba 100644 --- a/src/helpers/guilds/get_widget_image_url.ts +++ b/src/helpers/guilds/get_widget_image_url.ts @@ -1,5 +1,5 @@ import { cacheHandlers } from "../../cache.ts"; -import { GetGuildWidgetImageQuery } from "../../types/guilds/get_guild_widget_image.ts"; +import type { GetGuildWidgetImageQuery } from "../../types/guilds/get_guild_widget_image.ts"; import { Errors } from "../../types/misc/errors.ts"; import { endpoints } from "../../util/constants.ts"; diff --git a/src/helpers/guilds/get_widget_settings.ts b/src/helpers/guilds/get_widget_settings.ts index e8a106816..622199621 100644 --- a/src/helpers/guilds/get_widget_settings.ts +++ b/src/helpers/guilds/get_widget_settings.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { GuildWidget } from "../../types/guilds/guild_widget.ts"; +import type { GuildWidget } from "../../types/guilds/guild_widget.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/guilds/guild_banner_url.ts b/src/helpers/guilds/guild_banner_url.ts index 030d2cab6..b539b27be 100644 --- a/src/helpers/guilds/guild_banner_url.ts +++ b/src/helpers/guilds/guild_banner_url.ts @@ -1,5 +1,5 @@ -import { DiscordImageFormat } from "../../types/misc/image_format.ts"; -import { DiscordImageSize } from "../../types/misc/image_size.ts"; +import type { DiscordImageFormat } from "../../types/misc/image_format.ts"; +import type { DiscordImageSize } from "../../types/misc/image_size.ts"; import { endpoints } from "../../util/constants.ts"; import { formatImageURL } from "../../util/utils.ts"; diff --git a/src/helpers/guilds/guild_icon_url.ts b/src/helpers/guilds/guild_icon_url.ts index 09982fec3..5a4c2104a 100644 --- a/src/helpers/guilds/guild_icon_url.ts +++ b/src/helpers/guilds/guild_icon_url.ts @@ -1,5 +1,5 @@ -import { DiscordImageFormat } from "../../types/misc/image_format.ts"; -import { DiscordImageSize } from "../../types/misc/image_size.ts"; +import type { DiscordImageFormat } from "../../types/misc/image_format.ts"; +import type { DiscordImageSize } from "../../types/misc/image_size.ts"; import { endpoints } from "../../util/constants.ts"; import { formatImageURL } from "../../util/utils.ts"; diff --git a/src/helpers/guilds/guild_splash_url.ts b/src/helpers/guilds/guild_splash_url.ts index 83d734a07..b8aef6d56 100644 --- a/src/helpers/guilds/guild_splash_url.ts +++ b/src/helpers/guilds/guild_splash_url.ts @@ -1,5 +1,5 @@ -import { DiscordImageFormat } from "../../types/misc/image_format.ts"; -import { DiscordImageSize } from "../../types/misc/image_size.ts"; +import type { DiscordImageFormat } from "../../types/misc/image_format.ts"; +import type { DiscordImageSize } from "../../types/misc/image_size.ts"; import { endpoints } from "../../util/constants.ts"; import { formatImageURL } from "../../util/utils.ts"; diff --git a/src/helpers/guilds/update_bot_voice_state.ts b/src/helpers/guilds/update_bot_voice_state.ts index e75d5ce9c..60426da49 100644 --- a/src/helpers/guilds/update_bot_voice_state.ts +++ b/src/helpers/guilds/update_bot_voice_state.ts @@ -1,6 +1,5 @@ -import { RequestManager } from "../../rest/request_manager.ts"; -import { - DiscordUpdateSelfVoiceState, +import { rest } from "../../rest/rest.ts"; +import type { UpdateSelfVoiceState, } from "../../types/guilds/update_self_voice_state.ts"; import { endpoints } from "../../util/constants.ts"; @@ -15,14 +14,13 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts"; * - You must have the `REQUEST_TO_SPEAK` permission to request to speak. You can always clear your own request to speak. * - You are able to set `request_to_speak_timestamp` to any present or future time. */ -export function updateBotVoiceState( +export async function updateBotVoiceState( guildId: bigint, data: UpdateSelfVoiceState, ) { - const payload = camelKeysToSnakeCase(data); - - return RequestManager.patch( + return await rest.runMethod( + "patch", endpoints.UPDATE_VOICE_STATE(guildId), - payload, + camelKeysToSnakeCase(data), ); } diff --git a/src/helpers/guilds/update_user_voice_state.ts b/src/helpers/guilds/update_user_voice_state.ts index 88708ad10..6a8e47ebd 100644 --- a/src/helpers/guilds/update_user_voice_state.ts +++ b/src/helpers/guilds/update_user_voice_state.ts @@ -1,6 +1,5 @@ -import { RequestManager } from "../../rest/request_manager.ts"; -import { - DiscordUpdateOthersVoiceState, +import { rest } from "../../rest/rest.ts"; +import type { UpdateOthersVoiceState, } from "../../types/guilds/update_others_voice_state.ts"; import { endpoints } from "../../util/constants.ts"; @@ -20,10 +19,9 @@ export function updateVoiceState( userId: bigint, data: UpdateOthersVoiceState, ) { - const payload = camelKeysToSnakeCase(data); - - return RequestManager.patch( + return rest.runMethod( + "patch", endpoints.UPDATE_VOICE_STATE(guildId, userId), - payload, + camelKeysToSnakeCase(data), ); } diff --git a/src/helpers/integrations/get_integrations.ts b/src/helpers/integrations/get_integrations.ts index 96fd2110c..1947d3317 100644 --- a/src/helpers/integrations/get_integrations.ts +++ b/src/helpers/integrations/get_integrations.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { Integration } from "../../types/mod.ts"; +import type { Integration } from "../../types/integration/integration.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/invites/create_invite.ts b/src/helpers/invites/create_invite.ts index 6761d9048..e6e3e6008 100644 --- a/src/helpers/invites/create_invite.ts +++ b/src/helpers/invites/create_invite.ts @@ -1,6 +1,6 @@ import { rest } from "../../rest/rest.ts"; -import { CreateChannelInvite } from "../../types/invites/create_channel_invite.ts"; -import { Invite } from "../../types/invites/invite.ts"; +import type { CreateChannelInvite } from "../../types/invites/create_channel_invite.ts"; +import type { Invite } from "../../types/invites/invite.ts"; import { Errors } from "../../types/misc/errors.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/invites/delete_invite.ts b/src/helpers/invites/delete_invite.ts index 130cd2488..01d1d1c48 100644 --- a/src/helpers/invites/delete_invite.ts +++ b/src/helpers/invites/delete_invite.ts @@ -1,6 +1,6 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; -import { Invite } from "../../types/invites/invite.ts"; +import type { Invite } from "../../types/invites/invite.ts"; import { Errors } from "../../types/misc/errors.ts"; import { endpoints } from "../../util/constants.ts"; import { diff --git a/src/helpers/invites/get_channel_invites.ts b/src/helpers/invites/get_channel_invites.ts index ecd27a6d5..42fa1e9d9 100644 --- a/src/helpers/invites/get_channel_invites.ts +++ b/src/helpers/invites/get_channel_invites.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { Invite } from "../../types/invites/invite.ts"; +import type { Invite } from "../../types/invites/invite.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/invites/get_invite.ts b/src/helpers/invites/get_invite.ts index de91249fe..f0781e927 100644 --- a/src/helpers/invites/get_invite.ts +++ b/src/helpers/invites/get_invite.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { Invite } from "../../types/invites/invite.ts"; +import type { Invite } from "../../types/invites/invite.ts"; import { endpoints } from "../../util/constants.ts"; /** Returns an invite for the given code or throws an error if the invite doesn't exists. */ diff --git a/src/helpers/invites/get_invites.ts b/src/helpers/invites/get_invites.ts index 0ad0fda87..f2d1a732f 100644 --- a/src/helpers/invites/get_invites.ts +++ b/src/helpers/invites/get_invites.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { Invite } from "../../types/invites/invite.ts"; +import type { Invite } from "../../types/invites/invite.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/members/avatar_url.ts b/src/helpers/members/avatar_url.ts index 64a136370..0f9ad36da 100644 --- a/src/helpers/members/avatar_url.ts +++ b/src/helpers/members/avatar_url.ts @@ -1,5 +1,5 @@ -import { DiscordImageFormat } from "../../types/misc/image_format.ts"; -import { DiscordImageSize } from "../../types/misc/image_size.ts"; +import type { DiscordImageFormat } from "../../types/misc/image_format.ts"; +import type { DiscordImageSize } from "../../types/misc/image_size.ts"; import { endpoints } from "../../util/constants.ts"; import { formatImageURL } from "../../util/utils.ts"; diff --git a/src/helpers/members/ban_member.ts b/src/helpers/members/ban_member.ts index 57215ba59..7af64906c 100644 --- a/src/helpers/members/ban_member.ts +++ b/src/helpers/members/ban_member.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { CreateGuildBan } from "../../types/guilds/create_guild_ban.ts"; +import type { CreateGuildBan } from "../../types/guilds/create_guild_ban.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; import { camelKeysToSnakeCase } from "../../util/utils.ts"; diff --git a/src/helpers/members/edit_bot_profile.ts b/src/helpers/members/edit_bot_profile.ts index 2e4fd6c7c..719351636 100644 --- a/src/helpers/members/edit_bot_profile.ts +++ b/src/helpers/members/edit_bot_profile.ts @@ -1,6 +1,6 @@ import { rest } from "../../rest/rest.ts"; import { Errors } from "../../types/misc/errors.ts"; -import { User } from "../../types/mod.ts"; +import type { User } from "../../types/users/user.ts"; import { endpoints } from "../../util/constants.ts"; import { urlToBase64 } from "../../util/utils.ts"; diff --git a/src/helpers/members/edit_member.ts b/src/helpers/members/edit_member.ts index b9ad4efea..8b28e890b 100644 --- a/src/helpers/members/edit_member.ts +++ b/src/helpers/members/edit_member.ts @@ -1,10 +1,10 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; -import { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; +import type { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; +import type { ModifyGuildMember } from "../../types/guilds/modify_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 type { PermissionStrings } from "../../types/permissions/permission_strings.ts"; import { bigintToSnowflake } from "../../util/bigint.ts"; import { endpoints } from "../../util/constants.ts"; import { diff --git a/src/helpers/members/get_member.ts b/src/helpers/members/get_member.ts index 4949f3165..b2c17db17 100644 --- a/src/helpers/members/get_member.ts +++ b/src/helpers/members/get_member.ts @@ -1,7 +1,7 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; -import { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; +import type { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; import { endpoints } from "../../util/constants.ts"; /** Returns a guild member object for the specified user. diff --git a/src/helpers/members/get_members.ts b/src/helpers/members/get_members.ts index 9e0b10a02..6a7c95dd4 100644 --- a/src/helpers/members/get_members.ts +++ b/src/helpers/members/get_members.ts @@ -4,8 +4,8 @@ import { rest } from "../../rest/rest.ts"; import { DiscordenoMember } from "../../structures/member.ts"; import { structures } from "../../structures/mod.ts"; 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 type { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; +import type { 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"; diff --git a/src/helpers/members/prune_members.ts b/src/helpers/members/prune_members.ts index 0ee5010fb..a59860ad5 100644 --- a/src/helpers/members/prune_members.ts +++ b/src/helpers/members/prune_members.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { BeginGuildPrune } from "../../types/guilds/begin_guild_prune.ts"; +import type { BeginGuildPrune } from "../../types/guilds/begin_guild_prune.ts"; import { Errors } from "../../types/misc/errors.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/members/search_members.ts b/src/helpers/members/search_members.ts index b57745f1d..6258c69de 100644 --- a/src/helpers/members/search_members.ts +++ b/src/helpers/members/search_members.ts @@ -2,8 +2,8 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { DiscordenoMember } from "../../structures/member.ts"; import { structures } from "../../structures/mod.ts"; -import { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; -import { SearchGuildMembers } from "../../types/members/search_guild_members.ts"; +import type { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; +import type { SearchGuildMembers } from "../../types/members/search_guild_members.ts"; import { Errors } from "../../types/misc/errors.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; diff --git a/src/helpers/members/send_direct_message.ts b/src/helpers/members/send_direct_message.ts index 4aae8e391..710994a62 100644 --- a/src/helpers/members/send_direct_message.ts +++ b/src/helpers/members/send_direct_message.ts @@ -1,8 +1,8 @@ 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 { CreateMessage } from "../../types/messages/create_message.ts"; +import type { Channel } from "../../types/channels/channel.ts"; +import type { CreateMessage } from "../../types/messages/create_message.ts"; import { endpoints } from "../../util/constants.ts"; import { sendMessage } from "../messages/send_message.ts"; diff --git a/src/helpers/messages/edit_message.ts b/src/helpers/messages/edit_message.ts index e45bc4577..b76a55974 100644 --- a/src/helpers/messages/edit_message.ts +++ b/src/helpers/messages/edit_message.ts @@ -3,9 +3,9 @@ import { rest } from "../../rest/rest.ts"; import { DiscordenoMessage } from "../../structures/message.ts"; import { structures } from "../../structures/mod.ts"; import { EditMessage } from "../../types/messages/edit_message.ts"; -import { Message } from "../../types/messages/message.ts"; +import type { Message } from "../../types/messages/message.ts"; import { Errors } from "../../types/misc/errors.ts"; -import { PermissionStrings } from "../../types/permissions/permission_strings.ts"; +import type { PermissionStrings } from "../../types/permissions/permission_strings.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/messages/get_message.ts b/src/helpers/messages/get_message.ts index 7779a9d67..863eb07e0 100644 --- a/src/helpers/messages/get_message.ts +++ b/src/helpers/messages/get_message.ts @@ -1,7 +1,7 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; -import { Message } from "../../types/messages/message.ts"; +import type { Message } from "../../types/messages/message.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/messages/get_messages.ts b/src/helpers/messages/get_messages.ts index f12e4eb0c..79b29d238 100644 --- a/src/helpers/messages/get_messages.ts +++ b/src/helpers/messages/get_messages.ts @@ -6,7 +6,7 @@ import { GetMessagesBefore, GetMessagesLimit, } from "../../types/messages/get_messages.ts"; -import { Message } from "../../types/messages/message.ts"; +import type { Message } from "../../types/messages/message.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/messages/get_reactions.ts b/src/helpers/messages/get_reactions.ts index 04ee9806e..b06dd5709 100644 --- a/src/helpers/messages/get_reactions.ts +++ b/src/helpers/messages/get_reactions.ts @@ -1,6 +1,6 @@ import { rest } from "../../rest/rest.ts"; -import { GetReactions } from "../../types/messages/message_get_reactions.ts"; -import { User } from "../../types/users/user.ts"; +import type { GetReactions } from "../../types/messages/message_get_reactions.ts"; +import type { User } from "../../types/users/user.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; diff --git a/src/helpers/messages/publish_message.ts b/src/helpers/messages/publish_message.ts index 5c60a38bf..877d7c32d 100644 --- a/src/helpers/messages/publish_message.ts +++ b/src/helpers/messages/publish_message.ts @@ -1,6 +1,6 @@ import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; -import { Message } from "../../types/messages/message.ts"; +import type { Message } from "../../types/messages/message.ts"; import { endpoints } from "../../util/constants.ts"; /** Crosspost a message in a News Channel to following channels. */ diff --git a/src/helpers/messages/send_message.ts b/src/helpers/messages/send_message.ts index 0dd952d6e..9b08d706a 100644 --- a/src/helpers/messages/send_message.ts +++ b/src/helpers/messages/send_message.ts @@ -4,10 +4,10 @@ import { structures } from "../../structures/mod.ts"; import { DiscordChannelTypes } from "../../types/channels/channel_types.ts"; import { DiscordAllowedMentionsTypes } from "../../types/messages/allowed_mentions_types.ts"; import { ButtonStyles } from "../../types/messages/components/button_styles.ts"; -import { CreateMessage } from "../../types/messages/create_message.ts"; -import { Message } from "../../types/messages/message.ts"; +import type { CreateMessage } from "../../types/messages/create_message.ts"; +import type { Message } from "../../types/messages/message.ts"; import { Errors } from "../../types/misc/errors.ts"; -import { PermissionStrings } from "../../types/permissions/permission_strings.ts"; +import type { PermissionStrings } from "../../types/permissions/permission_strings.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; import { camelKeysToSnakeCase } from "../../util/utils.ts"; diff --git a/src/helpers/misc/get_gateway_bot.ts b/src/helpers/misc/get_gateway_bot.ts index d765780be..ac7594177 100644 --- a/src/helpers/misc/get_gateway_bot.ts +++ b/src/helpers/misc/get_gateway_bot.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { GetGatewayBot } from "../../types/gateway/get_gateway_bot.ts"; +import type { GetGatewayBot } from "../../types/gateway/get_gateway_bot.ts"; import { endpoints } from "../../util/constants.ts"; /** Get the bots Gateway metadata that can help during the operation of large or sharded bots. */ diff --git a/src/helpers/misc/get_user.ts b/src/helpers/misc/get_user.ts index 0c1517c91..f4632beb5 100644 --- a/src/helpers/misc/get_user.ts +++ b/src/helpers/misc/get_user.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { User } from "../../types/users/user.ts"; +import type { 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. */ diff --git a/src/helpers/roles/create_role.ts b/src/helpers/roles/create_role.ts index 363809489..d8050ea4f 100644 --- a/src/helpers/roles/create_role.ts +++ b/src/helpers/roles/create_role.ts @@ -2,7 +2,7 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { CreateGuildRole } from "../../types/guilds/create_guild_role.ts"; -import { Role } from "../../types/permissions/role.ts"; +import type { Role } from "../../types/permissions/role.ts"; import { endpoints } from "../../util/constants.ts"; import { calculateBits, diff --git a/src/helpers/roles/edit_role.ts b/src/helpers/roles/edit_role.ts index ad178d063..3b0595913 100644 --- a/src/helpers/roles/edit_role.ts +++ b/src/helpers/roles/edit_role.ts @@ -1,6 +1,7 @@ import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; -import { CreateGuildRole, Role } from "../../types/mod.ts"; +import type { CreateGuildRole } from "../../types/guilds/create_guild_role.ts"; +import type { Role } from "../../types/permissions/role.ts"; import { endpoints } from "../../util/constants.ts"; import { calculateBits, diff --git a/src/helpers/roles/get_roles.ts b/src/helpers/roles/get_roles.ts index b65dbf882..5c6967a6a 100644 --- a/src/helpers/roles/get_roles.ts +++ b/src/helpers/roles/get_roles.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { Role } from "../../types/permissions/role.ts"; +import type { Role } from "../../types/permissions/role.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/templates/create_guild_from_template.ts b/src/helpers/templates/create_guild_from_template.ts index 770f71299..9db4d427f 100644 --- a/src/helpers/templates/create_guild_from_template.ts +++ b/src/helpers/templates/create_guild_from_template.ts @@ -1,7 +1,7 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; -import { Guild } from "../../types/guilds/guild.ts"; -import { CreateGuildFromTemplate } from "../../types/templates/create_guild_from_template.ts"; +import type { Guild } from "../../types/guilds/guild.ts"; +import type { CreateGuildFromTemplate } from "../../types/templates/create_guild_from_template.ts"; import { endpoints } from "../../util/constants.ts"; import { urlToBase64 } from "../../util/utils.ts"; diff --git a/src/helpers/templates/create_guild_template.ts b/src/helpers/templates/create_guild_template.ts index b6d54feed..c8f3d5dfb 100644 --- a/src/helpers/templates/create_guild_template.ts +++ b/src/helpers/templates/create_guild_template.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { Template } from "../../types/templates/template.ts"; +import type { Template } from "../../types/templates/template.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/templates/delete_guild_template.ts b/src/helpers/templates/delete_guild_template.ts index 4cacb22e7..253a39b4e 100644 --- a/src/helpers/templates/delete_guild_template.ts +++ b/src/helpers/templates/delete_guild_template.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { Template } from "../../types/templates/template.ts"; +import type { Template } from "../../types/templates/template.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/templates/edit_guild_template.ts b/src/helpers/templates/edit_guild_template.ts index d35779cbd..d4aee54df 100644 --- a/src/helpers/templates/edit_guild_template.ts +++ b/src/helpers/templates/edit_guild_template.ts @@ -1,6 +1,6 @@ import { rest } from "../../rest/rest.ts"; -import { ModifyGuildTemplate } from "../../types/templates/modify_guild_template.ts"; -import { Template } from "../../types/templates/template.ts"; +import type { ModifyGuildTemplate } from "../../types/templates/modify_guild_template.ts"; +import type { Template } from "../../types/templates/template.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/templates/get_guild_templates.ts b/src/helpers/templates/get_guild_templates.ts index 30ba5be5f..c2a3d8521 100644 --- a/src/helpers/templates/get_guild_templates.ts +++ b/src/helpers/templates/get_guild_templates.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { Template } from "../../types/templates/template.ts"; +import type { Template } from "../../types/templates/template.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/templates/get_template.ts b/src/helpers/templates/get_template.ts index 41213e967..f67d9ffe0 100644 --- a/src/helpers/templates/get_template.ts +++ b/src/helpers/templates/get_template.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { Template } from "../../types/templates/template.ts"; +import type { Template } from "../../types/templates/template.ts"; import { endpoints } from "../../util/constants.ts"; /** Returns the guild template if it exists */ diff --git a/src/helpers/templates/sync_guild_template.ts b/src/helpers/templates/sync_guild_template.ts index 235952321..24fe0fc05 100644 --- a/src/helpers/templates/sync_guild_template.ts +++ b/src/helpers/templates/sync_guild_template.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { Template } from "../../types/templates/template.ts"; +import type { Template } from "../../types/templates/template.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/type_guards/is_action_row.ts b/src/helpers/type_guards/is_action_row.ts index c64fc8a6d..2dec9aafe 100644 --- a/src/helpers/type_guards/is_action_row.ts +++ b/src/helpers/type_guards/is_action_row.ts @@ -1,5 +1,5 @@ -import { ActionRow } from "../../types/messages/components/action_row.ts"; -import { MessageComponent } from "../../types/messages/components/message_components.ts"; +import type { ActionRow } from "../../types/messages/components/action_row.ts"; +import type { MessageComponent } from "../../types/messages/components/message_components.ts"; import { MessageComponentTypes } from "../../types/messages/components/message_component_types.ts"; /** A type guard function to tell if it is a action row component */ diff --git a/src/helpers/type_guards/is_button.ts b/src/helpers/type_guards/is_button.ts index dfe2b92cd..acc99645b 100644 --- a/src/helpers/type_guards/is_button.ts +++ b/src/helpers/type_guards/is_button.ts @@ -1,5 +1,5 @@ -import { ButtonComponent } from "../../types/messages/components/button_component.ts"; -import { MessageComponent } from "../../types/messages/components/message_components.ts"; +import type { ButtonComponent } from "../../types/messages/components/button_component.ts"; +import type { MessageComponent } from "../../types/messages/components/message_components.ts"; import { MessageComponentTypes } from "../../types/messages/components/message_component_types.ts"; /** A type guard function to tell if it is a button component */ diff --git a/src/helpers/webhooks/create_webhook.ts b/src/helpers/webhooks/create_webhook.ts index dd169d286..a83c25147 100644 --- a/src/helpers/webhooks/create_webhook.ts +++ b/src/helpers/webhooks/create_webhook.ts @@ -1,7 +1,7 @@ import { rest } from "../../rest/rest.ts"; import { Errors } from "../../types/misc/errors.ts"; -import { CreateWebhook } from "../../types/webhooks/create_webhook.ts"; -import { Webhook } from "../../types/webhooks/webhook.ts"; +import type { CreateWebhook } from "../../types/webhooks/create_webhook.ts"; +import type { Webhook } from "../../types/webhooks/webhook.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; import { urlToBase64 } from "../../util/utils.ts"; diff --git a/src/helpers/webhooks/edit_webhook.ts b/src/helpers/webhooks/edit_webhook.ts index 28dc6b11a..244bd129e 100644 --- a/src/helpers/webhooks/edit_webhook.ts +++ b/src/helpers/webhooks/edit_webhook.ts @@ -1,6 +1,6 @@ import { rest } from "../../rest/rest.ts"; -import { ModifyWebhook } from "../../types/webhooks/modify_webhook.ts"; -import { Webhook } from "../../types/webhooks/webhook.ts"; +import type { ModifyWebhook } from "../../types/webhooks/modify_webhook.ts"; +import type { Webhook } from "../../types/webhooks/webhook.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/webhooks/edit_webhook_message.ts b/src/helpers/webhooks/edit_webhook_message.ts index d1193a885..d49ca7dfb 100644 --- a/src/helpers/webhooks/edit_webhook_message.ts +++ b/src/helpers/webhooks/edit_webhook_message.ts @@ -1,9 +1,9 @@ import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordAllowedMentionsTypes } from "../../types/messages/allowed_mentions_types.ts"; -import { Message } from "../../types/messages/message.ts"; +import type { Message } from "../../types/messages/message.ts"; import { Errors } from "../../types/misc/errors.ts"; -import { EditWebhookMessage } from "../../types/webhooks/edit_webhook_message.ts"; +import type { EditWebhookMessage } from "../../types/webhooks/edit_webhook_message.ts"; import { endpoints } from "../../util/constants.ts"; export async function editWebhookMessage( diff --git a/src/helpers/webhooks/edit_webhook_with_token.ts b/src/helpers/webhooks/edit_webhook_with_token.ts index 0d35ead16..3332a1d13 100644 --- a/src/helpers/webhooks/edit_webhook_with_token.ts +++ b/src/helpers/webhooks/edit_webhook_with_token.ts @@ -1,6 +1,6 @@ import { rest } from "../../rest/rest.ts"; -import { ModifyWebhook } from "../../types/webhooks/modify_webhook.ts"; -import { Webhook } from "../../types/webhooks/webhook.ts"; +import type { ModifyWebhook } from "../../types/webhooks/modify_webhook.ts"; +import type { Webhook } from "../../types/webhooks/webhook.ts"; import { endpoints } from "../../util/constants.ts"; /** Edit a webhook. Returns the updated webhook object on success. */ diff --git a/src/helpers/webhooks/execute_webhook.ts b/src/helpers/webhooks/execute_webhook.ts index 2a03e3ebb..c282cbd06 100644 --- a/src/helpers/webhooks/execute_webhook.ts +++ b/src/helpers/webhooks/execute_webhook.ts @@ -1,9 +1,9 @@ import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordAllowedMentionsTypes } from "../../types/messages/allowed_mentions_types.ts"; -import { Message } from "../../types/messages/message.ts"; +import type { Message } from "../../types/messages/message.ts"; import { Errors } from "../../types/misc/errors.ts"; -import { ExecuteWebhook } from "../../types/webhooks/execute_webhook.ts"; +import type { ExecuteWebhook } from "../../types/webhooks/execute_webhook.ts"; import { endpoints } from "../../util/constants.ts"; /** Execute a webhook with webhook Id and webhook token */ diff --git a/src/helpers/webhooks/get_webhook.ts b/src/helpers/webhooks/get_webhook.ts index 6dd2e655d..86f40ab5e 100644 --- a/src/helpers/webhooks/get_webhook.ts +++ b/src/helpers/webhooks/get_webhook.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { Webhook } from "../../types/webhooks/webhook.ts"; +import type { Webhook } from "../../types/webhooks/webhook.ts"; import { endpoints } from "../../util/constants.ts"; /** Returns the new webhook object for the given id. */ diff --git a/src/helpers/webhooks/get_webhook_with_token.ts b/src/helpers/webhooks/get_webhook_with_token.ts index 665011c84..d4085b1c1 100644 --- a/src/helpers/webhooks/get_webhook_with_token.ts +++ b/src/helpers/webhooks/get_webhook_with_token.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { Webhook } from "../../types/webhooks/webhook.ts"; +import type { Webhook } from "../../types/webhooks/webhook.ts"; import { endpoints } from "../../util/constants.ts"; /** Returns the new webhook object for the given id, this call does not require authentication and returns no user in the webhook object. */ diff --git a/src/helpers/webhooks/get_webhooks.ts b/src/helpers/webhooks/get_webhooks.ts index c05c1a3cb..a9e90873d 100644 --- a/src/helpers/webhooks/get_webhooks.ts +++ b/src/helpers/webhooks/get_webhooks.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { Webhook } from "../../types/webhooks/webhook.ts"; +import type { Webhook } from "../../types/webhooks/webhook.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; From 315f162e7854adec18b68cb773ac8cb1d80eca55 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 12:41:07 +0200 Subject: [PATCH 100/148] structures too --- src/rest/create_request_body.ts | 2 +- src/structures/channel.ts | 13 ++++++++----- src/structures/guild.ts | 16 ++++++++-------- src/structures/member.ts | 14 +++++++------- src/structures/message.ts | 8 ++++---- src/structures/role.ts | 2 +- src/structures/voice_state.ts | 4 ++-- 7 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/rest/create_request_body.ts b/src/rest/create_request_body.ts index 3ab79d995..76f01a7ec 100644 --- a/src/rest/create_request_body.ts +++ b/src/rest/create_request_body.ts @@ -1,4 +1,4 @@ -import { FileContent } from "../types/misc/file_content.ts"; +import type { FileContent } from "../types/misc/file_content.ts"; import { USER_AGENT } from "../util/constants.ts"; import { rest, RestPayload, RestRequest } from "./rest.ts"; diff --git a/src/structures/channel.ts b/src/structures/channel.ts index 3a84ba831..920a7cfaa 100644 --- a/src/structures/channel.ts +++ b/src/structures/channel.ts @@ -8,11 +8,14 @@ import { editChannel } from "../helpers/channels/edit_channel.ts"; import { editChannelOverwrite } from "../helpers/channels/edit_channel_overwrite.ts"; import { sendMessage } from "../helpers/messages/send_message.ts"; import { disconnectMember } from "../helpers/mod.ts"; -import { Channel } from "../types/channels/channel.ts"; -import { ModifyChannel } from "../types/channels/modify_channel.ts"; -import { DiscordOverwrite, Overwrite } from "../types/channels/overwrite.ts"; -import { CreateMessage } from "../types/messages/create_message.ts"; -import { PermissionStrings } from "../types/permissions/permission_strings.ts"; +import type { Channel } from "../types/channels/channel.ts"; +import type { ModifyChannel } from "../types/channels/modify_channel.ts"; +import type { + DiscordOverwrite, + Overwrite, +} from "../types/channels/overwrite.ts"; +import type { CreateMessage } from "../types/messages/create_message.ts"; +import type { PermissionStrings } from "../types/permissions/permission_strings.ts"; import { snowflakeToBigint } from "../util/bigint.ts"; import { Collection } from "../util/collection.ts"; import { createNewProp } from "../util/utils.ts"; diff --git a/src/structures/guild.ts b/src/structures/guild.ts index 87f6dccc1..fc7e0e7d3 100644 --- a/src/structures/guild.ts +++ b/src/structures/guild.ts @@ -13,18 +13,18 @@ import { getInvites } from "../helpers/invites/get_invites.ts"; import { banMember } from "../helpers/members/ban_member.ts"; import { unbanMember } from "../helpers/members/unban_member.ts"; import { GetGuildAuditLog } from "../types/audit_log/get_guild_audit_log.ts"; -import { Emoji } from "../types/emojis/emoji.ts"; -import { CreateGuildBan } from "../types/guilds/create_guild_ban.ts"; -import { Guild } from "../types/guilds/guild.ts"; +import type { Emoji } from "../types/emojis/emoji.ts"; +import type { CreateGuildBan } from "../types/guilds/create_guild_ban.ts"; +import type { Guild } from "../types/guilds/guild.ts"; import { DiscordGuildFeatures } from "../types/guilds/guild_features.ts"; -import { +import type { GuildMember, GuildMemberWithUser, } from "../types/guilds/guild_member.ts"; -import { ModifyGuild } from "../types/guilds/modify_guild.ts"; -import { DiscordImageFormat } from "../types/misc/image_format.ts"; -import { DiscordImageSize } from "../types/misc/image_size.ts"; -import { PresenceUpdate } from "../types/misc/presence_update.ts"; +import type { ModifyGuild } from "../types/guilds/modify_guild.ts"; +import type { DiscordImageFormat } from "../types/misc/image_format.ts"; +import type { DiscordImageSize } from "../types/misc/image_size.ts"; +import type { PresenceUpdate } from "../types/misc/presence_update.ts"; import { snowflakeToBigint } from "../util/bigint.ts"; import { Collection } from "../util/collection.ts"; import { createNewProp } from "../util/utils.ts"; diff --git a/src/structures/member.ts b/src/structures/member.ts index a250cb15f..47581ce4c 100644 --- a/src/structures/member.ts +++ b/src/structures/member.ts @@ -7,16 +7,16 @@ import { kickMember } from "../helpers/members/kick_member.ts"; import { sendDirectMessage } from "../helpers/members/send_direct_message.ts"; import { addRole } from "../helpers/roles/add_role.ts"; import { removeRole } from "../helpers/roles/remove_role.ts"; -import { CreateGuildBan } from "../types/guilds/create_guild_ban.ts"; -import { +import type { CreateGuildBan } from "../types/guilds/create_guild_ban.ts"; +import type { GuildMember, GuildMemberWithUser, } from "../types/guilds/guild_member.ts"; -import { ModifyGuildMember } from "../types/guilds/modify_guild_member.ts"; -import { CreateMessage } from "../types/messages/create_message.ts"; -import { DiscordImageFormat } from "../types/misc/image_format.ts"; -import { DiscordImageSize } from "../types/misc/image_size.ts"; -import { User } from "../types/users/user.ts"; +import type { ModifyGuildMember } from "../types/guilds/modify_guild_member.ts"; +import type { CreateMessage } from "../types/messages/create_message.ts"; +import type { DiscordImageFormat } from "../types/misc/image_format.ts"; +import type { DiscordImageSize } from "../types/misc/image_size.ts"; +import type { User } from "../types/users/user.ts"; import { snowflakeToBigint } from "../util/bigint.ts"; import { Collection } from "../util/collection.ts"; import { createNewProp } from "../util/utils.ts"; diff --git a/src/structures/message.ts b/src/structures/message.ts index 47a798594..7191bcc37 100644 --- a/src/structures/message.ts +++ b/src/structures/message.ts @@ -10,10 +10,10 @@ import { removeAllReactions } from "../helpers/messages/remove_all_reactions.ts" import { removeReaction } from "../helpers/messages/remove_reaction.ts"; import { removeReactionEmoji } from "../helpers/messages/remove_reaction_emoji.ts"; import { sendMessage } from "../helpers/messages/send_message.ts"; -import { GuildMember } from "../types/guilds/guild_member.ts"; -import { CreateMessage } from "../types/messages/create_message.ts"; -import { EditMessage } from "../types/messages/edit_message.ts"; -import { Message } from "../types/messages/message.ts"; +import type { GuildMember } from "../types/guilds/guild_member.ts"; +import type { CreateMessage } from "../types/messages/create_message.ts"; +import type { EditMessage } from "../types/messages/edit_message.ts"; +import type { Message } from "../types/messages/message.ts"; import { bigintToSnowflake, snowflakeToBigint } from "../util/bigint.ts"; import { CHANNEL_MENTION_REGEX } from "../util/constants.ts"; import { createNewProp } from "../util/utils.ts"; diff --git a/src/structures/role.ts b/src/structures/role.ts index 783c20ce2..53f831aec 100644 --- a/src/structures/role.ts +++ b/src/structures/role.ts @@ -4,7 +4,7 @@ import { deleteRole } from "../helpers/roles/delete_role.ts"; import { editRole } from "../helpers/roles/edit_role.ts"; import { CreateGuildRole } from "../types/guilds/create_guild_role.ts"; import { Errors } from "../types/misc/errors.ts"; -import { Role } from "../types/permissions/role.ts"; +import type { Role } from "../types/permissions/role.ts"; import { snowflakeToBigint } from "../util/bigint.ts"; import { Collection } from "../util/collection.ts"; import { highestRole } from "../util/permissions.ts"; diff --git a/src/structures/voice_state.ts b/src/structures/voice_state.ts index c5c846562..d51d6ff45 100644 --- a/src/structures/voice_state.ts +++ b/src/structures/voice_state.ts @@ -1,7 +1,7 @@ import { eventHandlers } from "../bot.ts"; import { cache } from "../cache.ts"; -import { GuildMember } from "../types/guilds/guild_member.ts"; -import { VoiceState } from "../types/voice/voice_state.ts"; +import type { GuildMember } from "../types/guilds/guild_member.ts"; +import type { VoiceState } from "../types/voice/voice_state.ts"; import { snowflakeToBigint } from "../util/bigint.ts"; import { createNewProp } from "../util/utils.ts"; import { DiscordenoGuild } from "./guild.ts"; From 6e7ca7688c30ca805ba57892b90a779714525a63 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 12:42:13 +0200 Subject: [PATCH 101/148] for the utils --- src/util/permissions.ts | 2 +- src/util/utils.ts | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/util/permissions.ts b/src/util/permissions.ts index 86cb97ea0..75206d8c5 100644 --- a/src/util/permissions.ts +++ b/src/util/permissions.ts @@ -6,7 +6,7 @@ import { DiscordenoMember } from "../structures/member.ts"; import { DiscordenoRole } from "../structures/role.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"; +import type { PermissionStrings } from "../types/permissions/permission_strings.ts"; async function getCached( table: "guilds", diff --git a/src/util/utils.ts b/src/util/utils.ts index 6a2b9a240..af5a45a43 100644 --- a/src/util/utils.ts +++ b/src/util/utils.ts @@ -1,13 +1,13 @@ import { encode } from "../../deps.ts"; import { eventHandlers } from "../bot.ts"; -import { ApplicationCommandOption } from "../types/interactions/application_command_option.ts"; -import { ApplicationCommandOptionChoice } from "../types/interactions/application_command_option_choice.ts"; +import type { ApplicationCommandOption } from "../types/interactions/application_command_option.ts"; +import type { ApplicationCommandOptionChoice } from "../types/interactions/application_command_option_choice.ts"; import { DiscordApplicationCommandOptionTypes } from "../types/interactions/application_command_option_types.ts"; -import { CreateGlobalApplicationCommand } from "../types/interactions/create_global_application_command.ts"; +import type { CreateGlobalApplicationCommand } from "../types/interactions/create_global_application_command.ts"; +import type { EditGlobalApplicationCommand } from "../types/interactions/edit_global_application_command.ts"; import { Errors } from "../types/misc/errors.ts"; -import { DiscordImageFormat } from "../types/misc/image_format.ts"; -import { DiscordImageSize } from "../types/misc/image_size.ts"; -import { EditGlobalApplicationCommand } from "../types/mod.ts"; +import type { DiscordImageFormat } from "../types/misc/image_format.ts"; +import type { DiscordImageSize } from "../types/misc/image_size.ts"; import { SLASH_COMMANDS_NAME_REGEX } from "./constants.ts"; import { validateLength } from "./validate_length.ts"; From 6439bc92ed34f682311ec128ed2d44a93b93f783 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 12:43:20 +0200 Subject: [PATCH 102/148] wsssssss --- src/ws/events.ts | 2 +- src/ws/handle_discord_payload.ts | 2 +- src/ws/handle_on_message.ts | 6 +++--- src/ws/start_gateway.ts | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ws/events.ts b/src/ws/events.ts index a64d7e474..1a9a03e6d 100644 --- a/src/ws/events.ts +++ b/src/ws/events.ts @@ -1,4 +1,4 @@ -import { DiscordGatewayPayload } from "../types/gateway/gateway_payload.ts"; +import type { DiscordGatewayPayload } from "../types/gateway/gateway_payload.ts"; import { DiscordenoShard } from "./ws.ts"; /** The handler for logging different actions happening inside the ws. User can override and put custom handling per event. */ diff --git a/src/ws/handle_discord_payload.ts b/src/ws/handle_discord_payload.ts index a1ba8ddb8..3a21169a1 100644 --- a/src/ws/handle_discord_payload.ts +++ b/src/ws/handle_discord_payload.ts @@ -1,4 +1,4 @@ -import { DiscordGatewayPayload } from "../types/gateway/gateway_payload.ts"; +import type { DiscordGatewayPayload } from "../types/gateway/gateway_payload.ts"; import { ws } from "./ws.ts"; /** Handler for processing all dispatch payloads that should be sent/forwarded to another server/vps/process. */ diff --git a/src/ws/handle_on_message.ts b/src/ws/handle_on_message.ts index 055b6e203..2dee79979 100644 --- a/src/ws/handle_on_message.ts +++ b/src/ws/handle_on_message.ts @@ -1,9 +1,9 @@ import { eventHandlers } from "../bot.ts"; import { handlers } from "../handlers/mod.ts"; import { DiscordGatewayOpcodes } from "../types/codes/gateway_opcodes.ts"; -import { DiscordGatewayPayload } from "../types/gateway/gateway_payload.ts"; -import { DiscordHello } from "../types/gateway/hello.ts"; -import { DiscordReady } from "../types/gateway/ready.ts"; +import type { DiscordGatewayPayload } from "../types/gateway/gateway_payload.ts"; +import type { DiscordHello } from "../types/gateway/hello.ts"; +import type { DiscordReady } from "../types/gateway/ready.ts"; import { delay, snakeKeysToCamelCase } from "../util/utils.ts"; import { decompressWith } from "./deps.ts"; import { identify } from "./identify.ts"; diff --git a/src/ws/start_gateway.ts b/src/ws/start_gateway.ts index e057a91d8..11062276f 100644 --- a/src/ws/start_gateway.ts +++ b/src/ws/start_gateway.ts @@ -1,5 +1,5 @@ import { DiscordGatewayIntents } from "../types/gateway/gateway_intents.ts"; -import { GetGatewayBot } from "../types/gateway/get_gateway_bot.ts"; +import type { GetGatewayBot } from "../types/gateway/get_gateway_bot.ts"; import { snakeKeysToCamelCase } from "../util/utils.ts"; import { StartGatewayOptions } from "./start_gateway_options.ts"; import { ws } from "./ws.ts"; From 53dcb65c245036a799a4c9d91a45a27ac9775df8 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 12:43:46 +0200 Subject: [PATCH 103/148] cache --- src/cache.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cache.ts b/src/cache.ts index 3beadbb7b..6da6e43ed 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -1,10 +1,10 @@ // deno-lint-ignore-file require-await no-explicit-any prefer-const -import { DiscordenoChannel } from "./structures/channel.ts"; -import { DiscordenoGuild } from "./structures/guild.ts"; -import { DiscordenoMember } from "./structures/member.ts"; -import { DiscordenoMessage } from "./structures/message.ts"; -import { Emoji } from "./types/emojis/emoji.ts"; -import { PresenceUpdate } from "./types/misc/presence_update.ts"; +import type { DiscordenoChannel } from "./structures/channel.ts"; +import type { DiscordenoGuild } from "./structures/guild.ts"; +import type { DiscordenoMember } from "./structures/member.ts"; +import type { DiscordenoMessage } from "./structures/message.ts"; +import type { Emoji } from "./types/emojis/emoji.ts"; +import type { PresenceUpdate } from "./types/misc/presence_update.ts"; import { Collection } from "./util/collection.ts"; export const cache = { From e00138d0d375dc5731c8c437b93f825e5bc9467e Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 12:45:05 +0200 Subject: [PATCH 104/148] last but not least the bot --- src/bot.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bot.ts b/src/bot.ts index f23043674..ae0dc92ff 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -1,6 +1,6 @@ import { getGatewayBot } from "./helpers/misc/get_gateway_bot.ts"; import { rest } from "./rest/rest.ts"; -import { EventHandlers } from "./types/discordeno/eventHandlers.ts"; +import type { 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"; From 8544a3e48cd0f1d937ef9a934826e0046d4470db Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 13:02:29 +0100 Subject: [PATCH 105/148] fix: CONTRIBUTING invalid discord server invite link --- .github/CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 42ad9a86c..fa2fcc399 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -1,7 +1,7 @@ # Contributing - Read the [style guide](#style-guide). -- Ask for help on the [official Discord server](https:) +- Ask for help on the [official Discord server](https://discord.gg/5vBgXk3UcZ) - If you are going to work on an issue, mention so in the issue comments before you start working on the issue. - If you are going to work on a new feature, create an issue and discuss with From 5b9f3e110b4022ec3669ee6e977c9294786fa33a Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 13:04:36 +0100 Subject: [PATCH 106/148] fix: type design has changed now --- .github/CONTRIBUTING.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index fa2fcc399..609f329d2 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -38,10 +38,9 @@ ## Types Guide -- Must use snake case (according to Discord API). +- Must use camel case (same property name as in the docs just in camel case). - Each field or property must be accompanied with a reasonable JSDoc comment right above its type definition. -- The name of the type must be prefixed with `Discord`. - Must be placed inside of the types module (in `src/types` directory). Example: @@ -61,6 +60,4 @@ export interface User { flags?: number; premiumType?: number; } - -export type DiscordUser = SnakeCasedPropertiesDeep; ``` From 5c64d4a1ac19791514ff2883d23b54e267ea584d Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 14:48:50 +0200 Subject: [PATCH 107/148] this back --- src/structures/member.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/structures/member.ts b/src/structures/member.ts index e3d46d3bc..ebeb2fc4c 100644 --- a/src/structures/member.ts +++ b/src/structures/member.ts @@ -152,10 +152,12 @@ export async function createDiscordenoMember( // User was never cached before member.guilds.set(guildId, { - ...data, + nick: data.nick, roles: data.roles.map((id) => snowflakeToBigint(id)), joinedAt: Date.parse(joinedAt), premiumSince: premiumSince ? Date.parse(premiumSince) : undefined, + deaf: data.deaf, + mute: data.mute, }); return member; From 63c994e500c4b2133112a11b89937ac9161d12fe Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 17:40:59 +0200 Subject: [PATCH 108/148] silly me --- src/structures/guild.ts | 1 + src/structures/member.ts | 1 + src/structures/message.ts | 1 + src/structures/role.ts | 1 + 4 files changed, 4 insertions(+) diff --git a/src/structures/guild.ts b/src/structures/guild.ts index 3fdc6c030..a6373c1a2 100644 --- a/src/structures/guild.ts +++ b/src/structures/guild.ts @@ -237,6 +237,7 @@ export async function createDiscordenoGuild( voiceStates: createNewProp( new Collection(voiceStateStructs.map((vs) => [vs.userId, vs])), ), + bitfield: createNewProp(bitfield), }); // ONLY ADD TO QUEUE WHEN BOT IS NOT FULLY ONLINE diff --git a/src/structures/member.ts b/src/structures/member.ts index af316bad3..d592dcabd 100644 --- a/src/structures/member.ts +++ b/src/structures/member.ts @@ -137,6 +137,7 @@ export async function createDiscordenoMember( ...props, /** The guild related data mapped by guild id */ guilds: createNewProp(new Collection()), + bitfield: createNewProp(bitfield), }); const cached = await cacheHandlers.get("members", snowflakeToBigint(user.id)); diff --git a/src/structures/message.ts b/src/structures/message.ts index 601ab63ca..af8832351 100644 --- a/src/structures/message.ts +++ b/src/structures/message.ts @@ -234,6 +234,7 @@ export async function createDiscordenoMessage(data: Message) { } : undefined, ), + bitfield: createNewProp(bitfield), }); return message; diff --git a/src/structures/role.ts b/src/structures/role.ts index 46b0d8870..58536c499 100644 --- a/src/structures/role.ts +++ b/src/structures/role.ts @@ -138,6 +138,7 @@ export async function createDiscordenoRole( integrationId: createNewProp( tags.integrationId ? snowflakeToBigint(tags.integrationId) : undefined, ), + bitfield: createNewProp(bitfield), }); return role; From e942aea490790618ba28b0c081be46488a9b9af2 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 17:42:31 +0200 Subject: [PATCH 109/148] add threadd types --- src/helpers/channels/start_typing.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/helpers/channels/start_typing.ts b/src/helpers/channels/start_typing.ts index 2a7a09d79..4f65aa771 100644 --- a/src/helpers/channels/start_typing.ts +++ b/src/helpers/channels/start_typing.ts @@ -19,6 +19,9 @@ export async function startTyping(channelId: bigint) { DiscordChannelTypes.Dm, DiscordChannelTypes.GuildNews, DiscordChannelTypes.GuildText, + DiscordChannelTypes.GuildNewsThread, + DiscordChannelTypes.GuildPivateThread, + DiscordChannelTypes.GuildPublicThread, ].includes(channel.type) ) { throw new Error(Errors.CHANNEL_NOT_TEXT_BASED); From 4dc0e636e098dc31a3fa5ddc8b20d0c35ac3eb1f Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 18:34:27 +0200 Subject: [PATCH 110/148] edit webhook default original --- src/helpers/webhooks/edit_webhook_message.ts | 7 ++++--- src/util/constants.ts | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/helpers/webhooks/edit_webhook_message.ts b/src/helpers/webhooks/edit_webhook_message.ts index d49ca7dfb..f1565263b 100644 --- a/src/helpers/webhooks/edit_webhook_message.ts +++ b/src/helpers/webhooks/edit_webhook_message.ts @@ -9,8 +9,7 @@ import { endpoints } from "../../util/constants.ts"; export async function editWebhookMessage( webhookId: bigint, webhookToken: string, - messageId: bigint, - options: EditWebhookMessage, + options: EditWebhookMessage & { messageId?: bigint }, ) { if (options.content && options.content.length > 2000) { throw Error(Errors.MESSAGE_MAX_LENGTH); @@ -62,7 +61,9 @@ export async function editWebhookMessage( const result = await rest.runMethod( "patch", - endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId), + options.messageId + ? endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, options.messageId) + : endpoints.WEBHOOK_MESSAGE_ORIGINAL(webhookId, webhookToken), { ...options, allowedMentions: options.allowedMentions }, ); diff --git a/src/util/constants.ts b/src/util/constants.ts index 132f802f7..24f86e828 100644 --- a/src/util/constants.ts +++ b/src/util/constants.ts @@ -138,6 +138,8 @@ export const endpoints = { `${baseEndpoints.BASE_URL}/webhooks/${webhookId}`, WEBHOOK_MESSAGE: (webhookId: bigint, token: string, messageId: bigint) => `${baseEndpoints.BASE_URL}/webhooks/${webhookId}/${token}/messages/${messageId}`, + WEBHOOK_MESSAGE_ORIGINAL: (webhookId: bigint, token: string) => + `${baseEndpoints.BASE_URL}/webhooks/${webhookId}/${token}/messages/@original`, WEBHOOK_SLACK: (webhookId: bigint, token: string) => `${baseEndpoints.BASE_URL}/webhooks/${webhookId}/${token}/slack`, WEBHOOK_GITHUB: (webhookId: bigint, token: string) => From d87d66649eff3270420ba3ed1bbcda4afed0f6c4 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 21:02:16 +0200 Subject: [PATCH 111/148] big to small --- src/types/audit_log/audit_log_events.ts | 70 +++++++++---------- src/types/channels/overwrite_types.ts | 4 +- src/types/gateway/gateway_intents.ts | 30 ++++---- .../default_message_notification_levels.ts | 4 +- .../guilds/explicit_content_filter_levels.ts | 6 +- .../get_guild_widget_image_style_options.ts | 10 +-- src/types/guilds/guild_features.ts | 32 ++++----- src/types/guilds/mfa_levels.ts | 4 +- src/types/guilds/premium_tiers.ts | 8 +-- src/types/guilds/system_channel_flags.ts | 6 +- src/types/guilds/verification_levels.ts | 10 +-- .../application_command_option_types.ts | 18 ++--- src/types/invites/target_types.ts | 4 +- src/types/messages/message_activity_types.ts | 8 +-- .../messages/message_sticker_format_types.ts | 6 +- src/types/misc/activity_flags.ts | 12 ++-- src/types/teams/team_membership_states.ts | 4 +- 17 files changed, 118 insertions(+), 118 deletions(-) diff --git a/src/types/audit_log/audit_log_events.ts b/src/types/audit_log/audit_log_events.ts index 0620c1465..88f35fa3f 100644 --- a/src/types/audit_log/audit_log_events.ts +++ b/src/types/audit_log/audit_log_events.ts @@ -1,40 +1,40 @@ /** https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-audit-log-events */ export enum DiscordAuditLogEvents { - GUILD_UPDATE = 1, - CHANNEL_CREATE = 10, - CHANNEL_UPDATE, - CHANNEL_DELETE, - CHANNEL_OVERWRITE_CREATE, - CHANNEL_OVERWRITE_UPDATE, - CHANNEL_OVERWRITE_DELETE, - MEMBER_KICK = 20, - MEMBER_PRUNE, - MEMBER_BAN_ADD, - MEMBER_BAN_REMOVE, - MEMBER_UPDATE, - MEMBER_ROLE_UPDATE, - MEMBER_MOVE, - MEMBER_DISCONNECT, - BOT_ADD, - ROLE_CREATE = 30, - ROLE_UPDATE, - ROLE_DELETE, - INVITE_CREATE = 40, - INVITE_UPDATE, - INVITE_DELETE, - WEBHOOK_CREATE = 50, - WEBHOOK_UPDATE, - WEBHOOK_DELETE, - EMOJI_CREATE = 60, - EMOJI_UPDATE, - EMOJI_DELETE, - MESSAGE_DELETE = 72, - MESSAGE_BULK_DELETE, - MESSAGE_PIN, - MESSAGE_UNPIN, - INTEGRATION_CREATE = 80, - INTEGRATION_UPDATE, - INTEGRATION_DELETE, + GuildUpdate = 1, + ChannelCreate = 10, + ChannelUpdate, + ChannelDelete, + ChannelOverwriteCreate, + ChannelOverwriteUpdate, + ChannelOverwriteDelete, + MemberKick = 20, + MemberPrune, + MemberBanAdd, + MemberBanRemove, + MemberUpdate, + MemberRoleUpdate, + MemberMove, + MemberDisconnect, + BotAdd, + RoleCreate = 30, + RoleUpdate, + RoleDelete, + InviteCreate = 40, + InviteUpdate, + InviteDelete, + WebhookCreate = 50, + WebhookUpdate, + WebhookDelete, + EmojiCreate = 60, + EmojiUpdate, + EmojiDelete, + MessageDelete = 72, + MessageBulkDelete, + MessagePin, + MessageUnpin, + IntegrationCreate = 80, + IntegrationUpdate, + IntegrationDelete, } export type AuditLogEvents = DiscordAuditLogEvents; diff --git a/src/types/channels/overwrite_types.ts b/src/types/channels/overwrite_types.ts index 5ee32e76d..9e4de3406 100644 --- a/src/types/channels/overwrite_types.ts +++ b/src/types/channels/overwrite_types.ts @@ -1,6 +1,6 @@ export enum DiscordOverwriteTypes { - ROLE, - MEMBER, + Role, + Member, } export type OverwriteTypes = DiscordOverwriteTypes; diff --git a/src/types/gateway/gateway_intents.ts b/src/types/gateway/gateway_intents.ts index 533556a17..cb7f43944 100644 --- a/src/types/gateway/gateway_intents.ts +++ b/src/types/gateway/gateway_intents.ts @@ -11,63 +11,63 @@ export enum DiscordGatewayIntents { * - CHANNEL_DELETE * - CHANNEL_PINS_UPDATE */ - GUILDS = 1 << 0, + Guilds = 1 << 0, /** * - GUILD_MEMBER_ADD * - GUILD_MEMBER_UPDATE * - GUILD_MEMBER_REMOVE */ - GUILD_MEMBERS = 1 << 1, + GuildMembers = 1 << 1, /** * - GUILD_BAN_ADD * - GUILD_BAN_REMOVE */ - GUILD_BANS = 1 << 2, + GuildBans = 1 << 2, /** * - GUILD_EMOJIS_UPDATE */ - GUILD_EMOJIS = 1 << 3, + GuildEmojis = 1 << 3, /** * - GUILD_INTEGRATIONS_UPDATE * - INTEGRATION_CREATE * - INTEGRATION_UPDATE * - INTEGRATION_DELETE */ - GUILD_INTEGRATIONS = 1 << 4, + GuildIntegrations = 1 << 4, /** Enables the following events: * - WEBHOOKS_UPDATE */ - GUILD_WEBHOOKS = 1 << 5, + GuildWebhooks = 1 << 5, /** * - INVITE_CREATE * - INVITE_DELETE */ - GUILD_INVITES = 1 << 6, + GuildInvites = 1 << 6, /** * - VOICE_STATE_UPDATE */ - GUILD_VOICE_STATES = 1 << 7, + GuildVoiceStates = 1 << 7, /** * - PRESENCE_UPDATE */ - GUILD_PRESENCES = 1 << 8, + GuildPresences = 1 << 8, /** * - MESSAGE_CREATE * - MESSAGE_UPDATE * - MESSAGE_DELETE */ - GUILD_MESSAGES = 1 << 9, + GuildMessages = 1 << 9, /** * - MESSAGE_REACTION_ADD * - MESSAGE_REACTION_REMOVE * - MESSAGE_REACTION_REMOVE_ALL * - MESSAGE_REACTION_REMOVE_EMOJI */ - GUILD_MESSAGE_REACTIONS = 1 << 10, + GuildMessageReactions = 1 << 10, /** * - TYPING_START */ - GUILD_MESSAGE_TYPING = 1 << 11, + GuildMessageTyping = 1 << 11, /** * - CHANNEL_CREATE * - MESSAGE_CREATE @@ -75,18 +75,18 @@ export enum DiscordGatewayIntents { * - MESSAGE_DELETE * - CHANNEL_PINS_UPDATE */ - DIRECT_MESSAGES = 1 << 12, + DirectMessages = 1 << 12, /** * - MESSAGE_REACTION_ADD * - MESSAGE_REACTION_REMOVE * - MESSAGE_REACTION_REMOVE_ALL * - MESSAGE_REACTION_REMOVE_EMOJI */ - DIRECT_MESSAGE_REACTIONS = 1 << 13, + DirectMessageReactions = 1 << 13, /** * - TYPING_START */ - DIRECT_MESSAGE_TYPING = 1 << 14, + DirectMessageTyping = 1 << 14, } export type Intents = DiscordGatewayIntents; diff --git a/src/types/guilds/default_message_notification_levels.ts b/src/types/guilds/default_message_notification_levels.ts index 5c639ebde..8c3ced807 100644 --- a/src/types/guilds/default_message_notification_levels.ts +++ b/src/types/guilds/default_message_notification_levels.ts @@ -1,9 +1,9 @@ /** https://discord.com/developers/docs/resources/guild#guild-object-default-message-notification-level */ export enum DiscordDefaultMessageNotificationLevels { /** Members will receive notifications for all messages by default */ - ALL_MESSAGES, + AllMessages, /** Members will receive notifications only for messages that @mention them by default */ - ONLY_MENTIONS, + OnlyMentions, } export type DefaultMessageNotificationLevels = diff --git a/src/types/guilds/explicit_content_filter_levels.ts b/src/types/guilds/explicit_content_filter_levels.ts index 0fac226ed..583a2cdf4 100644 --- a/src/types/guilds/explicit_content_filter_levels.ts +++ b/src/types/guilds/explicit_content_filter_levels.ts @@ -1,11 +1,11 @@ /** https://discord.com/developers/docs/resources/guild#guild-object-explicit-content-filter-level */ export enum DiscordExplicitContentFilterLevels { /** Media content will not be scanned */ - DISABLED, + Disabled, /** Media content sent by members without roles will be scanned */ - MEMBERS_WITHOUT_ROLES, + MembersWithoutRoles, /** Media content sent by all members will be scanned */ - ALL_MEMBERS, + AllMembers, } export type ExplicitContentFilterLevels = DiscordExplicitContentFilterLevels; diff --git a/src/types/guilds/get_guild_widget_image_style_options.ts b/src/types/guilds/get_guild_widget_image_style_options.ts index b5c36c335..27aa6d044 100644 --- a/src/types/guilds/get_guild_widget_image_style_options.ts +++ b/src/types/guilds/get_guild_widget_image_style_options.ts @@ -1,15 +1,15 @@ /** https://discord.com/developers/docs/resources/guild#get-guild-widget-image-widget-style-options */ export enum DiscordGetGuildWidgetImageStyleOptions { /** Shield style widget with Discord icon and guild members online count */ - SHIELD = "shield", + Shield = "shield", /** Large image with guild icon, name and online count. "POWERED BY DISCORD" as the footer of the widget */ - BANNER_1 = "banner1", + Banner1 = "banner1", /** Smaller widget style with guild icon, name and online count. Split on the right with Discord logo */ - BANNER_2 = "banner2", + Banner2 = "banner2", /** Large image with guild icon, name and online count. In the footer, Discord logo on the left and "Chat Now" on the right */ - BANNER_3 = "banner3", + Banner3 = "banner3", /** Large Discord logo at the top of the widget. Guild icon, name and online count in the middle portion of the widget and a "JOIN MY SERVER" button at the bottom */ - BANNER_4 = "banner4", + Banner4 = "banner4", } export type GetGuildWidgetImageStyleOptions = diff --git a/src/types/guilds/guild_features.ts b/src/types/guilds/guild_features.ts index c507bb5be..75582bb3f 100644 --- a/src/types/guilds/guild_features.ts +++ b/src/types/guilds/guild_features.ts @@ -1,37 +1,37 @@ /** https://discord.com/developers/docs/resources/guild#guild-object-guild-features */ export enum DiscordGuildFeatures { /** Guild has access to set an invite splash background */ - INVITE_SPLASH = "INVITE_SPLASH", + InviteSplash = "INVITE_SPLASH", /** Guild has access to set 384kbps bitrate in voice (previously VIP voice servers) */ - VIP_REGIONS = "VIP_REGIONS", + VipRegions = "VIP_REGIONS", /** Guild has access to set a vanity URL */ - VANITY_URL = "VANITY_URL", + VanityUrl = "VANITY_URL", /** Guild is verified */ - VERIFIED = "VERIFIED", + Verified = "VERIFIED", /** Guild is partnered */ - PARTNERED = "PARTNERED", + Partnered = "PARTNERED", /** Guild can enable welcome screen, Membership Screening, stage channels and discovery, and recives community updates */ - COMMUNITY = "COMMUNITY", + Community = "COMMUNITY", /** Guild has access to use commerce features (i.e. create store channels) */ - COMMERCE = "COMMERCE", + Commerce = "COMMERCE", /** Guild has access to create news channels */ - NEWS = "NEWS", + News = "NEWS", /** Guild is able to be discovered in the directory */ - DISCOVERABLE = "DISCOVERABLE", + Discoverable = "DISCOVERABLE", /** guild cannot be discoverable */ - DISCOVERABLE_DISABLED = "DISCOVERABLE_DISABLED", + DiscoverableDisabled = "DISCOVERABLE_DISABLED", /** Guild is able to be featured in the directory */ - FEATURABLE = "FEATURABLE", + Feature = "FEATURABLE", /** Guild has access to set an animated guild icon */ - ANIMATED_ICON = "ANIMATED_ICON", + AnimatedIcon = "ANIMATED_ICON", /** Guild has access to set a guild banner image */ - BANNER = "BANNER", + Banner = "BANNER", /** Guild has enabled the welcome screen */ - WELCOME_SCREEN_ENABLED = "WELCOME_SCREEN_ENABLED", + WelcomeScreenEnabled = "WELCOME_SCREEN_ENABLED", /** Guild has enabled [Membership Screening](https://discord.com/developers/docs/resources/guild#membership-screening-object) */ - MEMBER_VERIFICATION_GATE_ENABLED = "MEMBER_VERIFICATION_GATE_ENABLED", + MemberVerificationGateEnabled = "MEMBER_VERIFICATION_GATE_ENABLED", /** Guild can be previewed before joining via Membership Screening or the directory */ - PREVIEW_ENABLED = "PREVIEW_ENABLED", + PreviewEnabled = "PREVIEW_ENABLED", } export type GuildFeatures = DiscordGuildFeatures; diff --git a/src/types/guilds/mfa_levels.ts b/src/types/guilds/mfa_levels.ts index 12ef1ad7a..cb664b8ae 100644 --- a/src/types/guilds/mfa_levels.ts +++ b/src/types/guilds/mfa_levels.ts @@ -1,9 +1,9 @@ /** https://discord.com/developers/docs/resources/guild#guild-object-mfa-level */ export enum DiscordMfaLevels { /** Guild has no MFA/2FA requirement for moderation actions */ - NONE, + None, /** Guild has a 2FA requirement for moderation actions */ - ELEVATED, + Elevated, } export type MfaLevels = DiscordMfaLevels; diff --git a/src/types/guilds/premium_tiers.ts b/src/types/guilds/premium_tiers.ts index 755c87e00..f6df334ec 100644 --- a/src/types/guilds/premium_tiers.ts +++ b/src/types/guilds/premium_tiers.ts @@ -1,13 +1,13 @@ /** https://discord.com/developers/docs/resources/guild#guild-object-premium-tier */ export enum DiscordPremiumTiers { /** Guild has not unlocked any Server Boost perks */ - NONE, + None, /** Guild has unlocked Server Boost level 1 perks */ - TIER_1, + Tier1, /** Guild has unlocked Server Boost level 2 perks */ - TIER_2, + Tier2, /** Guild has unlocked Server Boost level 3 perks */ - TIER_3, + Tier3, } export type PremiumTiers = DiscordPremiumTiers; diff --git a/src/types/guilds/system_channel_flags.ts b/src/types/guilds/system_channel_flags.ts index a2aebd752..81a5e2e79 100644 --- a/src/types/guilds/system_channel_flags.ts +++ b/src/types/guilds/system_channel_flags.ts @@ -1,11 +1,11 @@ /** https://discord.com/developers/docs/resources/guild#guild-object-system-channel-flags */ export enum DiscordSystemChannelFlags { /** Suppress member join notifications */ - SUPPRESS_JOIN_NOTIFICATIONS = 1 << 0, + SuppressJoinNotifications = 1 << 0, /** Suppress server boost notifications */ - SUPPRESS_PREMIUM_SUBSCRIPTIONS = 1 << 1, + SuppressPremiumSubscriptions = 1 << 1, /** Suppress server setup tips */ - SUPPRESS_GUILD_REMINDER_NOTIFICATIONS = 1 << 2, + SuppressGuildReminderNotifications = 1 << 2, } export type SystemChannelFlags = DiscordSystemChannelFlags; diff --git a/src/types/guilds/verification_levels.ts b/src/types/guilds/verification_levels.ts index 5e4e5f98e..5afa2f4d8 100644 --- a/src/types/guilds/verification_levels.ts +++ b/src/types/guilds/verification_levels.ts @@ -1,15 +1,15 @@ /** https://discord.com/developers/docs/resources/guild#guild-object-verification-level */ export enum DiscordVerificationLevels { /** Unrestricted */ - NONE, + None, /** Must have verified email on account */ - LOW, + Low, /** Must be registered on Discord for longer than 5 minutes */ - MEDIUM, + Medium, /** Must be a member of the server for longer than 10 minutes */ - HIGH, + High, /** Must have a verified phone number */ - VERY_HIGH, + VeryHigh, } export type VerificationLevels = DiscordVerificationLevels; diff --git a/src/types/interactions/application_command_option_types.ts b/src/types/interactions/application_command_option_types.ts index da0f2ed76..efae7bf80 100644 --- a/src/types/interactions/application_command_option_types.ts +++ b/src/types/interactions/application_command_option_types.ts @@ -1,14 +1,14 @@ /** https://discord.com/developers/docs/interactions/slash-commands#applicationcommandoptiontype */ export enum DiscordApplicationCommandOptionTypes { - SUB_COMMAND = 1, - SUB_COMMAND_GROUP, - STRING, - INTEGER, - BOOLEAN, - USER, - CHANNEL, - ROLE, - MENTIONABLE, + SubCommand = 1, + SubCommandGroup, + String, + Integer, + Boolean, + User, + Channel, + Role, + Mentionable, } export type ApplicationCommandOptionTypes = diff --git a/src/types/invites/target_types.ts b/src/types/invites/target_types.ts index c8f16d0ac..0d3153072 100644 --- a/src/types/invites/target_types.ts +++ b/src/types/invites/target_types.ts @@ -1,7 +1,7 @@ /** https://discord.com/developers/docs/resources/invite#invite-object-target-user-types */ export enum DiscordTargetTypes { - STREAM = 1, - EMBEDDED_APPLICATION, + Stream = 1, + EmbeddedApplication, } export type TargetTypes = DiscordTargetTypes; diff --git a/src/types/messages/message_activity_types.ts b/src/types/messages/message_activity_types.ts index 5340111b9..91944ae0f 100644 --- a/src/types/messages/message_activity_types.ts +++ b/src/types/messages/message_activity_types.ts @@ -1,9 +1,9 @@ /** https://discord.com/developers/docs/resources/channel#message-object-message-activity-types */ export enum DiscordMessageActivityTypes { - JOIN = 1, - SPECTATE, - LISTEN, - JOIN_REQUEST, + Join = 1, + Spectate, + Listen, + JoinRequest, } export type MessageActivityTypes = DiscordMessageActivityTypes; diff --git a/src/types/messages/message_sticker_format_types.ts b/src/types/messages/message_sticker_format_types.ts index 3a2baa629..7193cb245 100644 --- a/src/types/messages/message_sticker_format_types.ts +++ b/src/types/messages/message_sticker_format_types.ts @@ -1,8 +1,8 @@ /** https://discord.com/developers/docs/resources/channel#message-object-message-sticker-format-types */ export enum DiscordMessageStickerFormatTypes { - PNG = 1, - APNG, - LOTTIE, + Png = 1, + Apng, + Lottie, } export type MessageStickerFormatTypes = DiscordMessageStickerFormatTypes; diff --git a/src/types/misc/activity_flags.ts b/src/types/misc/activity_flags.ts index 7b0abdd40..a51521231 100644 --- a/src/types/misc/activity_flags.ts +++ b/src/types/misc/activity_flags.ts @@ -1,11 +1,11 @@ /** https://discord.com/developers/docs/topics/gateway#activity-object-activity-flags */ export enum DiscordActivityFlags { - INSTANCE = 1 << 0, - JOIN = 1 << 1, - SPECTATE = 1 << 2, - JOIN_REQUEST = 1 << 3, - SYNC = 1 << 4, - PLAY = 1 << 5, + Instance = 1 << 0, + Join = 1 << 1, + Spectate = 1 << 2, + JoinRequest = 1 << 3, + Sync = 1 << 4, + Play = 1 << 5, } export type ActivityFlags = DiscordActivityFlags; diff --git a/src/types/teams/team_membership_states.ts b/src/types/teams/team_membership_states.ts index 151fb4868..b1bc70c8d 100644 --- a/src/types/teams/team_membership_states.ts +++ b/src/types/teams/team_membership_states.ts @@ -1,7 +1,7 @@ /** https://discord.com/developers/docs/topics/teams#data-models-membership-state-enum */ export enum DiscordTeamMembershipStates { - INVITED = 1, - ACCEPTED, + Invited = 1, + Accepted, } export type TeamMembershipStates = DiscordTeamMembershipStates; From aefd5c75f5488e8351a0df7fdb2c75becd2e9603 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 21:05:43 +0200 Subject: [PATCH 112/148] fix changes --- src/handlers/channels/CHANNEL_DELETE.ts | 2 +- src/helpers/channels/clone_channel.ts | 2 +- src/helpers/channels/start_typing.ts | 2 +- src/helpers/members/fetch_members.ts | 2 +- src/helpers/members/get_members.ts | 2 +- src/helpers/messages/send_message.ts | 2 +- src/structures/guild.ts | 4 ++-- src/types/channels/channel_types.ts | 2 +- src/util/utils.ts | 8 ++++---- tests/channels/channel_overwrite_has_permission.ts | 2 +- tests/channels/clone_channel.ts | 2 +- tests/channels/create_channel.ts | 2 +- tests/channels/delete_channel_overwrite.ts | 2 +- tests/channels/edit_channel_overwrite.ts | 4 ++-- tests/channels/is_channel_synced.ts | 2 +- tests/ws/start_bot.ts | 9 ++++----- 16 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/handlers/channels/CHANNEL_DELETE.ts b/src/handlers/channels/CHANNEL_DELETE.ts index 511aae6c9..a2e07b828 100644 --- a/src/handlers/channels/CHANNEL_DELETE.ts +++ b/src/handlers/channels/CHANNEL_DELETE.ts @@ -37,7 +37,7 @@ export async function handleChannelDelete(data: DiscordGatewayPayload) { if ( [ DiscordChannelTypes.GuildText, - DiscordChannelTypes.Dm, + DiscordChannelTypes.DM, DiscordChannelTypes.GroupDm, DiscordChannelTypes.GuildNews, ].includes(payload.type) diff --git a/src/helpers/channels/clone_channel.ts b/src/helpers/channels/clone_channel.ts index 632fc770f..6a3696fac 100644 --- a/src/helpers/channels/clone_channel.ts +++ b/src/helpers/channels/clone_channel.ts @@ -14,7 +14,7 @@ export async function cloneChannel(channelId: bigint, reason?: string) { //Check for DM channel if ( - channelToClone.type === DiscordChannelTypes.Dm || + channelToClone.type === DiscordChannelTypes.DM || channelToClone.type === DiscordChannelTypes.GroupDm ) { throw new Error(Errors.CHANNEL_NOT_IN_GUILD); diff --git a/src/helpers/channels/start_typing.ts b/src/helpers/channels/start_typing.ts index 4f65aa771..8a48c8ccc 100644 --- a/src/helpers/channels/start_typing.ts +++ b/src/helpers/channels/start_typing.ts @@ -16,7 +16,7 @@ export async function startTyping(channelId: bigint) { if (channel) { if ( ![ - DiscordChannelTypes.Dm, + DiscordChannelTypes.DM, DiscordChannelTypes.GuildNews, DiscordChannelTypes.GuildText, DiscordChannelTypes.GuildNewsThread, diff --git a/src/helpers/members/fetch_members.ts b/src/helpers/members/fetch_members.ts index eca4c7720..2781bafa1 100644 --- a/src/helpers/members/fetch_members.ts +++ b/src/helpers/members/fetch_members.ts @@ -24,7 +24,7 @@ export function fetchMembers( // You can request 1 member without the intent if ( (!options?.limit || options.limit > 1) && - !(ws.identifyPayload.intents & DiscordGatewayIntents.GUILD_MEMBERS) + !(ws.identifyPayload.intents & DiscordGatewayIntents.GuildMembers) ) { throw new Error(Errors.MISSING_INTENT_GUILD_MEMBERS); } diff --git a/src/helpers/members/get_members.ts b/src/helpers/members/get_members.ts index 6a7c95dd4..2305d0cbc 100644 --- a/src/helpers/members/get_members.ts +++ b/src/helpers/members/get_members.ts @@ -24,7 +24,7 @@ export async function getMembers( guildId: bigint, options?: ListGuildMembers & { addToCache?: boolean }, ) { - if (!(ws.identifyPayload.intents && DiscordGatewayIntents.GUILD_MEMBERS)) { + if (!(ws.identifyPayload.intents && DiscordGatewayIntents.GuildMembers)) { throw new Error(Errors.MISSING_INTENT_GUILD_MEMBERS); } diff --git a/src/helpers/messages/send_message.ts b/src/helpers/messages/send_message.ts index ff80dfb53..4e1249b0c 100644 --- a/src/helpers/messages/send_message.ts +++ b/src/helpers/messages/send_message.ts @@ -26,7 +26,7 @@ export async function sendMessage( if (channel) { if ( ![ - DiscordChannelTypes.Dm, + DiscordChannelTypes.DM, DiscordChannelTypes.GuildNews, DiscordChannelTypes.GuildText, DiscordChannelTypes.GuildPublicThread, diff --git a/src/structures/guild.ts b/src/structures/guild.ts index e90f0f5b2..02da59f03 100644 --- a/src/structures/guild.ts +++ b/src/structures/guild.ts @@ -92,10 +92,10 @@ const baseGuild: Partial = { return cache.members.get(this.ownerId!); }, get partnered() { - return Boolean(this.features?.includes(DiscordGuildFeatures.PARTNERED)); + return Boolean(this.features?.includes(DiscordGuildFeatures.Partnered)); }, get verified() { - return Boolean(this.features?.includes(DiscordGuildFeatures.VERIFIED)); + return Boolean(this.features?.includes(DiscordGuildFeatures.Verified)); }, bannerURL(size, format) { return guildBannerURL(this.id!, this.banner!, size, format); diff --git a/src/types/channels/channel_types.ts b/src/types/channels/channel_types.ts index 26a3ce5e4..aec5aed04 100644 --- a/src/types/channels/channel_types.ts +++ b/src/types/channels/channel_types.ts @@ -3,7 +3,7 @@ export enum DiscordChannelTypes { /** A text channel within a server */ GuildText, /** A direct message between users */ - Dm, + DM, /** A voice channel within a server */ GuildVoice, /** A direct message between multiple users */ diff --git a/src/util/utils.ts b/src/util/utils.ts index c37bcb0fd..4b81719c6 100644 --- a/src/util/utils.ts +++ b/src/util/utils.ts @@ -130,11 +130,11 @@ function validateSlashOptionChoices( } if ( - (optionType === DiscordApplicationCommandOptionTypes.STRING && + (optionType === DiscordApplicationCommandOptionTypes.String && (typeof choice.value !== "string" || choice.value.length < 1 || choice.value.length > 100)) || - (optionType === DiscordApplicationCommandOptionTypes.INTEGER && + (optionType === DiscordApplicationCommandOptionTypes.Integer && typeof choice.value !== "number") ) { throw new Error(Errors.INVALID_SLASH_OPTIONS_CHOICES); @@ -152,8 +152,8 @@ function validateSlashOptions(options: ApplicationCommandOption[]) { if ( option.choices?.length && (option.choices.length > 25 || - (option.type !== DiscordApplicationCommandOptionTypes.STRING && - option.type !== DiscordApplicationCommandOptionTypes.INTEGER)) + (option.type !== DiscordApplicationCommandOptionTypes.String && + option.type !== DiscordApplicationCommandOptionTypes.Integer)) ) { throw new Error(Errors.INVALID_SLASH_OPTIONS_CHOICES); } diff --git a/tests/channels/channel_overwrite_has_permission.ts b/tests/channels/channel_overwrite_has_permission.ts index 71d3402b3..ff84e4add 100644 --- a/tests/channels/channel_overwrite_has_permission.ts +++ b/tests/channels/channel_overwrite_has_permission.ts @@ -53,7 +53,7 @@ Deno.test({ permissionOverwrites: [ { id: bigintToSnowflake(botId), - type: DiscordOverwriteTypes.MEMBER, + type: DiscordOverwriteTypes.Member, allow: ["VIEW_CHANNEL"], deny: [], }, diff --git a/tests/channels/clone_channel.ts b/tests/channels/clone_channel.ts index 4b526da61..9838a7698 100644 --- a/tests/channels/clone_channel.ts +++ b/tests/channels/clone_channel.ts @@ -141,7 +141,7 @@ Deno.test({ permissionOverwrites: [ { id: bigintToSnowflake(botId), - type: DiscordOverwriteTypes.MEMBER, + type: DiscordOverwriteTypes.Member, allow: ["VIEW_CHANNEL"], deny: [], }, diff --git a/tests/channels/create_channel.ts b/tests/channels/create_channel.ts index fbc85d1d5..63b44ec7e 100644 --- a/tests/channels/create_channel.ts +++ b/tests/channels/create_channel.ts @@ -160,7 +160,7 @@ Deno.test({ permissionOverwrites: [ { id: bigintToSnowflake(botId), - type: DiscordOverwriteTypes.MEMBER, + type: DiscordOverwriteTypes.Member, allow: ["VIEW_CHANNEL"], deny: [], }, diff --git a/tests/channels/delete_channel_overwrite.ts b/tests/channels/delete_channel_overwrite.ts index fc033dff3..d5337c631 100644 --- a/tests/channels/delete_channel_overwrite.ts +++ b/tests/channels/delete_channel_overwrite.ts @@ -56,7 +56,7 @@ Deno.test({ permissionOverwrites: [ { id: bigintToSnowflake(botId), - type: DiscordOverwriteTypes.MEMBER, + type: DiscordOverwriteTypes.Member, allow: ["VIEW_CHANNEL"], deny: [], }, diff --git a/tests/channels/edit_channel_overwrite.ts b/tests/channels/edit_channel_overwrite.ts index b1482b4f5..e74c244cd 100644 --- a/tests/channels/edit_channel_overwrite.ts +++ b/tests/channels/edit_channel_overwrite.ts @@ -35,7 +35,7 @@ async function ifItFailsBlameWolf(options: CreateGuildChannel) { } await editChannelOverwrite(channel.guildId, channel.id, botId, { - type: DiscordOverwriteTypes.MEMBER, + type: DiscordOverwriteTypes.Member, allow: ["VIEW_CHANNEL", "ADD_REACTIONS"], deny: [], }); @@ -71,7 +71,7 @@ Deno.test({ permissionOverwrites: [ { id: bigintToSnowflake(botId), - type: DiscordOverwriteTypes.MEMBER, + type: DiscordOverwriteTypes.Member, allow: ["VIEW_CHANNEL"], deny: [], }, diff --git a/tests/channels/is_channel_synced.ts b/tests/channels/is_channel_synced.ts index c341b3374..6a4d96db7 100644 --- a/tests/channels/is_channel_synced.ts +++ b/tests/channels/is_channel_synced.ts @@ -18,7 +18,7 @@ Deno.test({ permissionOverwrites: [ { id: bigintToSnowflake(botId), - type: DiscordOverwriteTypes.MEMBER, + type: DiscordOverwriteTypes.Member, allow: ["VIEW_CHANNEL"], deny: [], }, diff --git a/tests/ws/start_bot.ts b/tests/ws/start_bot.ts index a68b2d0fc..266da17e9 100644 --- a/tests/ws/start_bot.ts +++ b/tests/ws/start_bot.ts @@ -36,11 +36,10 @@ Deno.test({ await startBot({ token, intents: [ - "GUILD_MESSAGES", - "GUILDS", - "GUILD_EMOJIS", - "GUILD_MESSAGE_REACTIONS", - "GUILD_EMOJIS", + "GuildMessages", + "Guilds", + "GuildEmojis", + "GuildMessageReactions", ], }); From ff1eb2e6f2db4524b8fec75d9371626cb21d1135 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 22:04:01 +0200 Subject: [PATCH 113/148] add: getWebhookMessage --- src/helpers/webhooks/get_webhook_message.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/helpers/webhooks/get_webhook_message.ts diff --git a/src/helpers/webhooks/get_webhook_message.ts b/src/helpers/webhooks/get_webhook_message.ts new file mode 100644 index 000000000..eddee7609 --- /dev/null +++ b/src/helpers/webhooks/get_webhook_message.ts @@ -0,0 +1,18 @@ +import { rest } from "../../rest/rest.ts"; +import { structures } from "../../structures/mod.ts"; +import { Message } from "../../types/messages/message.ts"; +import { endpoints } from "../../util/constants.ts"; + +/** Returns a previousy-sent webhook message from the same token. Returns a message object on success. */ +export async function getWebhookMessage( + webhookId: bigint, + webhookToken: string, + messageId: bigint, +) { + const result = await rest.runMethod( + "get", + endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId), + ); + + return await structures.createDiscordenoMessage(result); +} From dd8baf93f5672b754809566d72a4723e21d85f6c Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 22:06:32 +0200 Subject: [PATCH 114/148] add: getOriginalinteractionResponse --- .../commands/get_original_interaction_response.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/helpers/commands/get_original_interaction_response.ts diff --git a/src/helpers/commands/get_original_interaction_response.ts b/src/helpers/commands/get_original_interaction_response.ts new file mode 100644 index 000000000..b6009c94f --- /dev/null +++ b/src/helpers/commands/get_original_interaction_response.ts @@ -0,0 +1,15 @@ +import { applicationId } from "../../bot.ts"; +import { rest } from "../../rest/rest.ts"; +import { structures } from "../../structures/mod.ts"; +import type { Message } from "../../types/messages/message.ts"; +import { endpoints } from "../../util/constants.ts"; + +/** Returns the initial Interactio response. Functions the same as Get Webhook Message */ +export async function getOriginalInteractionResponse(token: string) { + const result = await rest.runMethod( + "get", + endpoints.INTERACTION_ORIGINAL_ID_TOKEN(applicationId, token), + ); + + return await structures.createDiscordenoMessage(result); +} From 38b8ea5532f5995b969f92e4a2ee6f7ca11820cf Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 22:06:40 +0200 Subject: [PATCH 115/148] fix: imports use type --- src/helpers/webhooks/get_webhook_message.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/webhooks/get_webhook_message.ts b/src/helpers/webhooks/get_webhook_message.ts index eddee7609..d59fc02a7 100644 --- a/src/helpers/webhooks/get_webhook_message.ts +++ b/src/helpers/webhooks/get_webhook_message.ts @@ -1,6 +1,6 @@ import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; -import { Message } from "../../types/messages/message.ts"; +import type { Message } from "../../types/messages/message.ts"; import { endpoints } from "../../util/constants.ts"; /** Returns a previousy-sent webhook message from the same token. Returns a message object on success. */ From 09d6177b5fa2e3979ee67df1d4536e21750b5340 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 22:07:43 +0200 Subject: [PATCH 116/148] add: new handlers mod export --- src/helpers/mod.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/helpers/mod.ts b/src/helpers/mod.ts index 6d0aea748..903614119 100644 --- a/src/helpers/mod.ts +++ b/src/helpers/mod.ts @@ -19,6 +19,7 @@ import { deleteSlashCommand } from "./commands/delete_slash_command.ts"; import { deleteSlashResponse } from "./commands/delete_slash_response.ts"; import { editSlashCommandPermissions } from "./commands/edit_slash_command_permissions.ts"; import { editSlashResponse } from "./commands/edit_slash_response.ts"; +import { getOriginalInteractionResponse } from "./commands/get_original_interaction_response.ts"; import { getSlashCommand } from "./commands/get_slash_command.ts"; import { getSlashCommands } from "./commands/get_slash_commands.ts"; import { getSlashCommandPermission } from "./commands/get_slash_command_permission.ts"; @@ -111,6 +112,9 @@ import { editGuildTemplate } from "./templates/edit_guild_template.ts"; import { getGuildTemplates } from "./templates/get_guild_templates.ts"; import { getTemplate } from "./templates/get_template.ts"; import { syncGuildTemplate } from "./templates/sync_guild_template.ts"; +// Type Guards +import { isActionRow } from "./type_guards/is_action_row.ts"; +import { isButton } from "./type_guards/is_button.ts"; import { createWebhook } from "./webhooks/create_webhook.ts"; import { deleteWebhook } from "./webhooks/delete_webhook.ts"; import { deleteWebhookMessage } from "./webhooks/delete_webhook_message.ts"; @@ -118,13 +122,11 @@ import { deleteWebhookWithToken } from "./webhooks/delete_webhook_with_token.ts" import { editWebhook } from "./webhooks/edit_webhook.ts"; import { editWebhookMessage } from "./webhooks/edit_webhook_message.ts"; import { editWebhookWithToken } from "./webhooks/edit_webhook_with_token.ts"; -import { sendWebhook } from "./webhooks/send_webhook.ts"; import { getWebhook } from "./webhooks/get_webhook.ts"; import { getWebhooks } from "./webhooks/get_webhooks.ts"; +import { getWebhookMessage } from "./webhooks/get_webhook_message.ts"; import { getWebhookWithToken } from "./webhooks/get_webhook_with_token.ts"; -// Type Guards -import { isActionRow } from "./type_guards/is_action_row.ts"; -import { isButton } from "./type_guards/is_button.ts"; +import { sendWebhook } from "./webhooks/send_webhook.ts"; export { addDiscoverySubcategory, @@ -205,6 +207,7 @@ export { getMembers, getMessage, getMessages, + getOriginalInteractionResponse, getPins, getPruneCount, getReactions, @@ -218,6 +221,7 @@ export { getVanityURL, getVoiceRegions, getWebhook, + getWebhookMessage, getWebhooks, getWebhookWithToken, getWelcomeScreen, @@ -289,6 +293,7 @@ export let helpers = { getSlashCommands, upsertSlashCommand, upsertSlashCommands, + getOriginalInteractionResponse, // emojis createEmoji, deleteEmoji, @@ -396,6 +401,7 @@ export let helpers = { getWebhookWithToken, getWebhook, getWebhooks, + getWebhookMessage, }; export type Helpers = typeof helpers; From b0ea2549ad42ba0b13017c1976f158972f7c8052 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 22:12:04 +0200 Subject: [PATCH 117/148] getinvites add options --- src/helpers/invites/get_invite.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/helpers/invites/get_invite.ts b/src/helpers/invites/get_invite.ts index f0781e927..12772f327 100644 --- a/src/helpers/invites/get_invite.ts +++ b/src/helpers/invites/get_invite.ts @@ -1,11 +1,14 @@ import { rest } from "../../rest/rest.ts"; +import { GetInvite } from "../../types/invites/get_invite.ts"; import type { Invite } from "../../types/invites/invite.ts"; import { endpoints } from "../../util/constants.ts"; +import { camelKeysToSnakeCase } from "../../util/utils.ts"; /** Returns an invite for the given code or throws an error if the invite doesn't exists. */ -export async function getInvite(inviteCode: string) { +export async function getInvite(inviteCode: string, options: GetInvite) { return await rest.runMethod( "get", endpoints.INVITE(inviteCode), + camelKeysToSnakeCase(options), ); } From 2d25f275a9cfc94f01fd62d02a8f0b0e405291bc Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 22:20:14 +0200 Subject: [PATCH 118/148] nonce has been removed --- src/types/messages/create_message.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/types/messages/create_message.ts b/src/types/messages/create_message.ts index fa1704f90..c59ef410f 100644 --- a/src/types/messages/create_message.ts +++ b/src/types/messages/create_message.ts @@ -8,13 +8,11 @@ import { MessageComponents } from "./components/message_components.ts"; export interface CreateMessage { /** The message contents (up to 2000 characters) */ content?: string; - /** A nonce that can be used for optimistic message sending */ - nonce?: number | string; /** true if this is a TTS message */ tts?: boolean; /** Embedded `rich` content */ embed?: Embed; - /** Allowed mentions for a message */ + /** Allowed mentions for the message */ allowedMentions?: AllowedMentions; /** Include to make your message a reply */ messageReference?: MessageReference; From 3694c377ebdb641cbf8d76e13af8c94c639a00a2 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 22:20:36 +0200 Subject: [PATCH 119/148] Update send_message.ts --- src/helpers/messages/send_message.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/helpers/messages/send_message.ts b/src/helpers/messages/send_message.ts index ff80dfb53..7e5b815dd 100644 --- a/src/helpers/messages/send_message.ts +++ b/src/helpers/messages/send_message.ts @@ -145,13 +145,6 @@ export async function sendMessage( } } - if ( - content.nonce && - !validateLength(content.nonce.toString(), { max: 25 }) - ) { - throw new Error(Errors.NONCE_TOO_LONG); - } - const result = await rest.runMethod( "post", endpoints.CHANNEL_MESSAGES(channelId), From 3ecfaef780358b9e93fec53a498840e04c5df653 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 22:22:41 +0200 Subject: [PATCH 120/148] edit message can now have files --- src/types/messages/edit_message.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/types/messages/edit_message.ts b/src/types/messages/edit_message.ts index 41169bc55..0ca2f06d9 100644 --- a/src/types/messages/edit_message.ts +++ b/src/types/messages/edit_message.ts @@ -1,4 +1,5 @@ import { Embed } from "../embeds/embed.ts"; +import { FileContent } from "../misc/file_content.ts"; import { AllowedMentions } from "./allowed_mentions.ts"; import { Attachment } from "./attachment.ts"; @@ -10,6 +11,8 @@ export interface EditMessage { embed?: Embed | null; /** Edit the flags of the message (only `SUPRESS_EMBEDS` can currently be set/unset) */ flags?: 4 | null; + /** The contents of the file being sent/edited */ + file?: FileContent | FileContent[] | null; /** Allowed mentions for the message */ allowedMentions?: AllowedMentions | null; /** Attached files to keep */ From 147453cd1e7f155946a0910a8201b1389968ad0b Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 22:22:53 +0200 Subject: [PATCH 121/148] fix files can be nullable --- src/types/webhooks/edit_webhook_message.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/types/webhooks/edit_webhook_message.ts b/src/types/webhooks/edit_webhook_message.ts index 6317c70fe..d8fc7ba3c 100644 --- a/src/types/webhooks/edit_webhook_message.ts +++ b/src/types/webhooks/edit_webhook_message.ts @@ -1,7 +1,7 @@ import { Embed } from "../embeds/embed.ts"; import { AllowedMentions } from "../messages/allowed_mentions.ts"; -import { FileContent } from "../misc/file_content.ts"; import { Attachment } from "../messages/attachment.ts"; +import { FileContent } from "../misc/file_content.ts"; /** https://discord.com/developers/docs/resources/webhook#edit-webhook-message-jsonform-params */ export interface EditWebhookMessage { @@ -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[] | null; /** Allowed mentions for the message */ allowedMentions?: AllowedMentions | null; /** Attached files to keep */ From c5cf4ba3533734aa3b485ee6d8737e3fcc30cf40 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 22:24:37 +0200 Subject: [PATCH 122/148] Update get_invite.ts --- src/helpers/invites/get_invite.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/helpers/invites/get_invite.ts b/src/helpers/invites/get_invite.ts index 12772f327..8e5b177e4 100644 --- a/src/helpers/invites/get_invite.ts +++ b/src/helpers/invites/get_invite.ts @@ -5,10 +5,10 @@ import { endpoints } from "../../util/constants.ts"; import { camelKeysToSnakeCase } from "../../util/utils.ts"; /** Returns an invite for the given code or throws an error if the invite doesn't exists. */ -export async function getInvite(inviteCode: string, options: GetInvite) { +export async function getInvite(inviteCode: string, options?: GetInvite) { return await rest.runMethod( "get", endpoints.INVITE(inviteCode), - camelKeysToSnakeCase(options), + camelKeysToSnakeCase(options ?? {}), ); } From d16280512cbdfa0179f3df8fc8bc9081c6056e4f Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 22:36:00 +0200 Subject: [PATCH 123/148] add: webhook thread support --- src/helpers/webhooks/send_webhook.ts | 6 +++--- src/types/webhooks/execute_webhook.ts | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/helpers/webhooks/send_webhook.ts b/src/helpers/webhooks/send_webhook.ts index e627e485a..20cd92e46 100644 --- a/src/helpers/webhooks/send_webhook.ts +++ b/src/helpers/webhooks/send_webhook.ts @@ -66,9 +66,9 @@ export async function sendWebhook( const result = await rest.runMethod( "post", - `${endpoints.WEBHOOK(webhookId, webhookToken)}${ - options.wait ? "?wait=true" : "" - }`, + `${endpoints.WEBHOOK(webhookId, webhookToken)}?wait=${ + options.wait ? "true" : "false" + }${options.threadId ? `&thread_id=${options.threadId}` : ""}`, { ...options, allowed_mentions: options.allowedMentions, diff --git a/src/types/webhooks/execute_webhook.ts b/src/types/webhooks/execute_webhook.ts index 9268f21bf..bce114c30 100644 --- a/src/types/webhooks/execute_webhook.ts +++ b/src/types/webhooks/execute_webhook.ts @@ -7,6 +7,8 @@ import { SnakeCasedPropertiesDeep } from "../util.ts"; export interface ExecuteWebhook { /** Waits for server confirmation of message send before response, and returns the created message body (defaults to `false`; when `false` a message that is not saved does not return an error) */ wait?: boolean; + /** Send a message to the specified thread within a webhook's channel. The thread will automatically be unarchived. */ + threadId?: bigint; /** The message contents (up to 2000 characters) */ content?: string; /** Override the default username of the webhook */ From 3a017f48d7bbc27cdf7af60b8634959a3d3c9fb7 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Wed, 5 May 2021 08:30:18 -0400 Subject: [PATCH 124/148] Delete test.ts --- test.ts | 75 --------------------------------------------------------- 1 file changed, 75 deletions(-) delete mode 100644 test.ts diff --git a/test.ts b/test.ts deleted file mode 100644 index 540dc8902..000000000 --- a/test.ts +++ /dev/null @@ -1,75 +0,0 @@ -const config = { - maxConcurrency: 16, - maxShards: 1120, - maxClusters: 140, - shardsPerCluster: 8, -}; - -function sleep(ms: number) { - return new Promise((resolve) => setTimeout(resolve, ms)); -} - -function organizeClusters() { - const clusters = new Map(); - const buckets = new Map(); - const shardClusters = new Map(); - let cluster = 0; - - for (let i = 0; i < config.maxShards; i++) { - const shards = clusters.get(cluster); - if (!shards) clusters.set(cluster, [i]); - else { - if (shards.length < config.shardsPerCluster) shards.push(i); - else { - cluster++; - clusters.set(cluster, [i]); - } - } - - shardClusters.set(i, cluster); - } - - for (let i = 0; i < config.maxShards; i++) { - const bucketID = i % config.maxConcurrency; - const bucket = buckets.get(bucketID); - if (!bucket) { - buckets.set(bucketID, [i]); - } else { - bucket.push(i); - } - } - - return { clusters, buckets }; -} - -function startup() { - const { clusters, buckets } = organizeClusters(); - - // SPREAD THIS OUT TO DIFFERENT CLUSTERS TO BEGIN STARTING UP - // FOREACH will have this concurrently - buckets.forEach(async (bucket, bucketID) => { - for (const queue of bucket) { - for (const shardID of queue) { - console.log( - `Bucket ID:`, - bucketID, - "Cluster ID:", - clusters.get(shardID), - "Shard ID:", - shardID, - ); - redis.publish( - "sharder", - JSON.stringify({ clusterID: clusters.get(shardID), shardID }), - ); - } - - // AFTER THIS QUEUE IS CREATED WE WAIT FOR ALL SHARDS TO LOAD BEFORE NEXT CLUSTER - // 5 SECONDS PER SHARD + EXTRA 10 TO BE SAFE - await sleep(config.shardsPerCluster * 5000 + 10000); - } - }); -} - -startup(); -setInterval(startup, 60000 * 5); From 02eb2de8f2458f41c6309a0d83e11179b4c4a955 Mon Sep 17 00:00:00 2001 From: rigormorrtiss Date: Wed, 5 May 2021 17:26:10 +0400 Subject: [PATCH 125/148] add(tests): validateSlashCommands (#899) * test(util): add missing tests for validateSlashCommands() * Summarize the name of the test suites * Add more tests * Concise and correct the suite name --- tests/deps.ts | 1 + tests/util/utils.ts | 54 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/tests/deps.ts b/tests/deps.ts index 9e4747cff..8ecc89d22 100644 --- a/tests/deps.ts +++ b/tests/deps.ts @@ -2,4 +2,5 @@ export { assertArrayIncludes, assertEquals, assertExists, + assertThrows, } from "https://deno.land/std@0.90.0/testing/asserts.ts"; diff --git a/tests/util/utils.ts b/tests/util/utils.ts index c8a0fb686..128d602a2 100644 --- a/tests/util/utils.ts +++ b/tests/util/utils.ts @@ -1,8 +1,11 @@ +import { ApplicationCommandOption } from "../../src/types/interactions/application_command_option.ts"; +import { DiscordApplicationCommandOptionTypes } from "../../src/types/interactions/application_command_option_types.ts"; import { camelKeysToSnakeCase, snakeKeysToCamelCase, + validateSlashCommands, } from "../../src/util/utils.ts"; -import { assertEquals } from "../deps.ts"; +import { assertEquals, assertThrows } from "../deps.ts"; const testSnakeObject = { // deno-lint-ignore camelcase @@ -74,3 +77,52 @@ Deno.test({ assertEquals(resultTwo, someElseOther); }, }); + +Deno.test({ + name: "[utils] validateSlashCommands(): validates name", + fn() { + assertThrows(() => + validateSlashCommands([{ + // The maximum length of the name of an application command is 32. + name: "a".repeat(33), + }]) + ); + + validateSlashCommands([{ + name: "workingname", + }]); + }, +}); + +Deno.test({ + name: "[utils] validateSlashCommands(): validates description", + fn() { + assertThrows(() => + // The maximum length of the description of an application command is 100. + validateSlashCommands([{ description: "a".repeat(101) }]) + ); + + validateSlashCommands([{ + description: "valid description (should not throw)", + }]); + }, +}); + +Deno.test({ + name: "[utils] validateSlashCommands(): validates number of options", + fn() { + const option = { + name: "option1", + description: "The description of the application command's option.", + type: DiscordApplicationCommandOptionTypes.STRING, + }; + // The maximum number of options an application command can "accomodate" is 25. + const options: ApplicationCommandOption[] = Array(26).fill(option); + + assertThrows(() => validateSlashCommands([{ options }])); + + validateSlashCommands([{ + options: [option], + }]); + }, +}); From 774d7649f5bc78c43eb1714325a8f6fe1e742070 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 5 May 2021 15:54:41 +0200 Subject: [PATCH 126/148] Update send_webhook.ts --- src/helpers/webhooks/send_webhook.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/helpers/webhooks/send_webhook.ts b/src/helpers/webhooks/send_webhook.ts index 20cd92e46..cb90615ed 100644 --- a/src/helpers/webhooks/send_webhook.ts +++ b/src/helpers/webhooks/send_webhook.ts @@ -66,9 +66,9 @@ export async function sendWebhook( const result = await rest.runMethod( "post", - `${endpoints.WEBHOOK(webhookId, webhookToken)}?wait=${ - options.wait ? "true" : "false" - }${options.threadId ? `&thread_id=${options.threadId}` : ""}`, + `${endpoints.WEBHOOK(webhookId, webhookToken)}?wait=${options.wait}${ + options.threadId ? `&thread_id=${options.threadId}` : "" + }`, { ...options, allowed_mentions: options.allowedMentions, From be6ff0abd7ea62a1b83a07153d07b1e45885c93a Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 5 May 2021 15:55:40 +0200 Subject: [PATCH 127/148] remove initial cache members queue --- src/structures/guild.ts | 22 ++-------------------- src/util/cache_members.ts | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 20 deletions(-) create mode 100644 src/util/cache_members.ts diff --git a/src/structures/guild.ts b/src/structures/guild.ts index e90f0f5b2..acf0c511a 100644 --- a/src/structures/guild.ts +++ b/src/structures/guild.ts @@ -26,6 +26,7 @@ import type { DiscordImageFormat } from "../types/misc/image_format.ts"; import type { DiscordImageSize } from "../types/misc/image_size.ts"; import type { PresenceUpdate } from "../types/misc/presence_update.ts"; import { snowflakeToBigint } from "../util/bigint.ts"; +import { cacheMembers } from "../util/cache_members.ts"; import { Collection } from "../util/collection.ts"; import { createNewProp } from "../util/utils.ts"; import { DiscordenoChannel } from "./channel.ts"; @@ -34,7 +35,6 @@ import { structures } from "./mod.ts"; import { DiscordenoRole } from "./role.ts"; import { DiscordenoVoiceState } from "./voice_state.ts"; -export const initialMemberLoadQueue = new Map(); const GUILD_SNOWFLAKES = [ "id", "ownerId", @@ -241,25 +241,7 @@ export async function createDiscordenoGuild( bitfield: createNewProp(bitfield), }); - // ONLY ADD TO QUEUE WHEN BOT IS NOT FULLY ONLINE - if (!cache.isReady) initialMemberLoadQueue.set(guild.id, members); - // BOT IS ONLINE, JUST DIRECTLY ADD MEMBERS - else { - await Promise.allSettled( - members.map(async (member) => { - const discordenoMember = await structures.createDiscordenoMember( - member as GuildMemberWithUser, - guild.id, - ); - - return cacheHandlers.set( - "members", - discordenoMember.id, - discordenoMember, - ); - }), - ); - } + await cacheMembers(guild.id, members as GuildMemberWithUser[]); return guild; } diff --git a/src/util/cache_members.ts b/src/util/cache_members.ts new file mode 100644 index 000000000..4bee5cd45 --- /dev/null +++ b/src/util/cache_members.ts @@ -0,0 +1,35 @@ +import { cacheHandlers } from "../cache.ts"; +import { structures } from "../structures/mod.ts"; +import { GuildMemberWithUser } from "../types/guilds/guild_member.ts"; + +const memberQueue = new Map(); + +export async function cacheMembers( + guildId: bigint, + members: GuildMemberWithUser[], +) { + return Promise.allSettled( + members.map((member) => { + const queue = memberQueue.get(member.user.id); + + if (queue) return queue.push(member); + + memberQueue.set(member.user.id, [member]); + return startQueue(guildId, member.user.id); + }), + ); +} + +async function startQueue(guildId: bigint, memberId: string) { + const queue = memberQueue.get(memberId); + if (!queue) return; + + while (queue.length) { + const discordenoMember = await structures.createDiscordenoMember( + queue.shift()!, + guildId, + ); + + await cacheHandlers.set("members", discordenoMember.id, discordenoMember); + } +} From c4842cde698ff37460154075bcdfb97cb5490a15 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 5 May 2021 15:56:32 +0200 Subject: [PATCH 128/148] add cache members export --- src/util/mod.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util/mod.ts b/src/util/mod.ts index 9af7e2b53..5adeab630 100644 --- a/src/util/mod.ts +++ b/src/util/mod.ts @@ -1,4 +1,5 @@ export * from "./bigint.ts"; +export * from "./cache_members.ts"; export * from "./collection.ts"; export * from "./constants.ts"; export * from "./loop_object.ts"; From 828447e94e611ae155aed6f5cf89188a7401ce54 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 5 May 2021 16:27:02 +0200 Subject: [PATCH 129/148] Update READY.ts --- src/handlers/misc/READY.ts | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/src/handlers/misc/READY.ts b/src/handlers/misc/READY.ts index 0ff0afa34..d9f2e2246 100644 --- a/src/handlers/misc/READY.ts +++ b/src/handlers/misc/READY.ts @@ -1,10 +1,7 @@ import { eventHandlers, setApplicationId, setBotId } from "../../bot.ts"; -import { cache, cacheHandlers } from "../../cache.ts"; -import { initialMemberLoadQueue } from "../../structures/guild.ts"; -import { structures } from "../../structures/mod.ts"; +import { cache } from "../../cache.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { Ready } from "../../types/gateway/ready.ts"; -import type { GuildMemberWithUser } from "../../types/mod.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; import { ws } from "../../ws/ws.ts"; @@ -92,28 +89,6 @@ async function loaded(shardId: number) { } else { cache.isReady = true; eventHandlers.ready?.(); - - // All the members that came in on guild creates should now be processed 1 by 1 - for (const [guildId, members] of initialMemberLoadQueue.entries()) { - eventHandlers.debug?.( - "loop", - "Running for of loop in READY file for loading members.", - ); - await Promise.allSettled( - members.map(async (member) => { - const discordenoMember = await structures.createDiscordenoMember( - member as GuildMemberWithUser, - guildId, - ); - - return cacheHandlers.set( - "members", - discordenoMember.id, - discordenoMember, - ); - }), - ); - } } } } From 287e9317f4a8ad5d7d841f82fd65a0c51073cdcd Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 5 May 2021 17:15:38 +0200 Subject: [PATCH 130/148] better --- src/util/cache_members.ts | 60 ++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/src/util/cache_members.ts b/src/util/cache_members.ts index 4bee5cd45..cdace7ad3 100644 --- a/src/util/cache_members.ts +++ b/src/util/cache_members.ts @@ -1,35 +1,55 @@ +import { eventHandlers } from "../bot.ts"; import { cacheHandlers } from "../cache.ts"; import { structures } from "../structures/mod.ts"; import { GuildMemberWithUser } from "../types/guilds/guild_member.ts"; -const memberQueue = new Map(); +const guildMemberQueue = new Map< + bigint, + { members: GuildMemberWithUser[]; resolve?: (value?: unknown) => void } +>(); +let processingQueue = false; export async function cacheMembers( guildId: bigint, members: GuildMemberWithUser[], ) { - return Promise.allSettled( - members.map((member) => { - const queue = memberQueue.get(member.user.id); - - if (queue) return queue.push(member); - - memberQueue.set(member.user.id, [member]); - return startQueue(guildId, member.user.id); - }), - ); + return new Promise((resolve) => { + guildMemberQueue.set(guildId, { members, resolve }); + startQueue(); + }); } -async function startQueue(guildId: bigint, memberId: string) { - const queue = memberQueue.get(memberId); - if (!queue) return; +async function startQueue() { + if (processingQueue) return; - while (queue.length) { - const discordenoMember = await structures.createDiscordenoMember( - queue.shift()!, - guildId, - ); + processingQueue = true; - await cacheHandlers.set("members", discordenoMember.id, discordenoMember); + while (guildMemberQueue.size) { + eventHandlers.debug?.("loop", "Running whille loop in cache_members file."); + const [guildId, queue]: [ + bigint, + { members: GuildMemberWithUser[]; resolve: (value?: unknown) => void }, + ] = guildMemberQueue.entries().next().value; + + await Promise.allSettled([ + queue.members.map(async (member) => { + const discordenoMember = await structures.createDiscordenoMember( + member, + guildId, + ); + + await cacheHandlers.set( + "members", + discordenoMember.id, + discordenoMember, + ); + }), + ]); + + queue.resolve?.(); + + guildMemberQueue.delete(guildId); } + + processingQueue = false; } From bbf61cd951da2a688003078a3a7104ec5695193a Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 5 May 2021 17:16:18 +0200 Subject: [PATCH 131/148] jdo --- src/util/cache_members.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util/cache_members.ts b/src/util/cache_members.ts index cdace7ad3..d28c91863 100644 --- a/src/util/cache_members.ts +++ b/src/util/cache_members.ts @@ -9,6 +9,7 @@ const guildMemberQueue = new Map< >(); let processingQueue = false; +/** Cache all guild members without need to worry about overwriting something. */ export async function cacheMembers( guildId: bigint, members: GuildMemberWithUser[], From c0c99e1b7b4e63bab594a47002ca0eec109ceffc Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 5 May 2021 17:48:31 +0200 Subject: [PATCH 132/148] Update application_command_interaction_data_option.ts --- ...ication_command_interaction_data_option.ts | 83 ++++++++++++++++++- 1 file changed, 79 insertions(+), 4 deletions(-) diff --git a/src/types/interactions/application_command_interaction_data_option.ts b/src/types/interactions/application_command_interaction_data_option.ts index 99421663d..10275553d 100644 --- a/src/types/interactions/application_command_interaction_data_option.ts +++ b/src/types/interactions/application_command_interaction_data_option.ts @@ -1,13 +1,88 @@ +import { Channel } from "../channels/channel.ts"; +import { Role } from "../permissions/role.ts"; +import { User } from "../users/user.ts"; import { DiscordApplicationCommandOptionTypes } from "./application_command_option_types.ts"; /** https://discord.com/developers/docs/interactions/slash-commands#interaction-applicationcommandinteractiondataoption */ -export interface ApplicationCommandInteractionDataOption { +export type ApplicationCommandInteractionDataOption = + | ApplicationCommandInteractionDataOptionSubCommand + | ApplicationCommandInteractionDataOptionSubCommandGroup + | ApplicationCommandInteractionDataOptionString + | ApplicationCommandInteractionDataOptionInteger + | ApplicationCommandInteractionDataOptionBoolean + | ApplicationCommandInteractionDataOptionUser + | ApplicationCommandInteractionDataOptionChannel + | ApplicationCommandInteractionDataOptionRole + | ApplicationCommandInteractionDataOptionMentionable; + +interface ApplicationCommandInteractionDataOptionBase< + T extends DiscordApplicationCommandOptionTypes, + V = unknown, +> { /** The name of the parameter */ name: string; - /** value of DiscordApplicationCommandOptionTypes */ - type: DiscordApplicationCommandOptionTypes; + /** Type of the option */ + type: T; /** The value of the pair */ - value?: DiscordApplicationCommandOptionTypes; + value: V; +} + +export interface ApplicationCommandInteractionDataOptionSubCommand + extends + ApplicationCommandInteractionDataOptionBase< + DiscordApplicationCommandOptionTypes.SUB_COMMAND + > { /** Present if this option is a group or subcommand */ options?: ApplicationCommandInteractionDataOption[]; } + +export interface ApplicationCommandInteractionDataOptionSubCommandGroup + extends + ApplicationCommandInteractionDataOptionBase< + DiscordApplicationCommandOptionTypes.SUB_COMMAND_GROUP + > { + /** Present if this option is a group or subcommand */ + options?: ApplicationCommandInteractionDataOption[]; +} + +export type ApplicationCommandInteractionDataOptionString = + ApplicationCommandInteractionDataOptionBase< + DiscordApplicationCommandOptionTypes.STRING, + string + >; + +export type ApplicationCommandInteractionDataOptionInteger = + ApplicationCommandInteractionDataOptionBase< + DiscordApplicationCommandOptionTypes.INTEGER, + number + >; + +export type ApplicationCommandInteractionDataOptionBoolean = + ApplicationCommandInteractionDataOptionBase< + DiscordApplicationCommandOptionTypes.BOOLEAN, + boolean + >; + +export type ApplicationCommandInteractionDataOptionUser = + ApplicationCommandInteractionDataOptionBase< + DiscordApplicationCommandOptionTypes.USER, + User + >; + +export type ApplicationCommandInteractionDataOptionChannel = + ApplicationCommandInteractionDataOptionBase< + DiscordApplicationCommandOptionTypes.CHANNEL, + Channel + >; + +export type ApplicationCommandInteractionDataOptionRole = + ApplicationCommandInteractionDataOptionBase< + DiscordApplicationCommandOptionTypes.ROLE, + Role + >; + +export type ApplicationCommandInteractionDataOptionMentionable = + ApplicationCommandInteractionDataOptionBase< + DiscordApplicationCommandOptionTypes.MENTIONABLE, + bigint + >; From fd62aaaaa27aa441dc50bb54c896a5f79d39b6f9 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 5 May 2021 17:50:00 +0200 Subject: [PATCH 133/148] these are bigints --- .../application_command_interaction_data_option.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/types/interactions/application_command_interaction_data_option.ts b/src/types/interactions/application_command_interaction_data_option.ts index 10275553d..c9817fab9 100644 --- a/src/types/interactions/application_command_interaction_data_option.ts +++ b/src/types/interactions/application_command_interaction_data_option.ts @@ -1,6 +1,3 @@ -import { Channel } from "../channels/channel.ts"; -import { Role } from "../permissions/role.ts"; -import { User } from "../users/user.ts"; import { DiscordApplicationCommandOptionTypes } from "./application_command_option_types.ts"; /** https://discord.com/developers/docs/interactions/slash-commands#interaction-applicationcommandinteractiondataoption */ @@ -66,19 +63,19 @@ export type ApplicationCommandInteractionDataOptionBoolean = export type ApplicationCommandInteractionDataOptionUser = ApplicationCommandInteractionDataOptionBase< DiscordApplicationCommandOptionTypes.USER, - User + bigint >; export type ApplicationCommandInteractionDataOptionChannel = ApplicationCommandInteractionDataOptionBase< DiscordApplicationCommandOptionTypes.CHANNEL, - Channel + bigint >; export type ApplicationCommandInteractionDataOptionRole = ApplicationCommandInteractionDataOptionBase< DiscordApplicationCommandOptionTypes.ROLE, - Role + bigint >; export type ApplicationCommandInteractionDataOptionMentionable = From 4533e6356bf1c589199e6f72d012a7e38126c51e Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 5 May 2021 17:51:23 +0200 Subject: [PATCH 134/148] this is not async anymore --- src/handlers/misc/READY.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/handlers/misc/READY.ts b/src/handlers/misc/READY.ts index d9f2e2246..8fef56ae0 100644 --- a/src/handlers/misc/READY.ts +++ b/src/handlers/misc/READY.ts @@ -52,7 +52,7 @@ async function checkReady(payload: Ready, shardId: number, now: number) { if (Date.now() - now > 10000) { eventHandlers.shardFailedToLoad?.(shardId, shard.unavailableGuildIds); // Force execute the loaded function to prevent infinite loop - await loaded(shardId); + loaded(shardId); } else { // Not all guilds were loaded but 10 seconds haven't passed so check again setTimeout(async () => { @@ -65,11 +65,11 @@ async function checkReady(payload: Ready, shardId: number, now: number) { } } else { // All guilds were loaded - await loaded(shardId); + loaded(shardId); } } -async function loaded(shardId: number) { +function loaded(shardId: number) { const shard = ws.shards.get(shardId); if (!shard) return; @@ -84,7 +84,7 @@ async function loaded(shardId: number) { "loop", `3. Running setTimeout in CHANNEL_DELTE file.`, ); - await loaded(shardId); + loaded(shardId); }, 2000); } else { cache.isReady = true; From 8e870ec637804a12698004328cb388e04d28c3ef Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 5 May 2021 18:03:34 +0200 Subject: [PATCH 135/148] fix the new test --- tests/util/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/util/utils.ts b/tests/util/utils.ts index 128d602a2..4cf2ef05e 100644 --- a/tests/util/utils.ts +++ b/tests/util/utils.ts @@ -114,7 +114,7 @@ Deno.test({ const option = { name: "option1", description: "The description of the application command's option.", - type: DiscordApplicationCommandOptionTypes.STRING, + type: DiscordApplicationCommandOptionTypes.String, }; // The maximum number of options an application command can "accomodate" is 25. const options: ApplicationCommandOption[] = Array(26).fill(option); From 7e37a90bb9631cde629d08387e19b3e200f60988 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 5 May 2021 18:09:39 +0200 Subject: [PATCH 136/148] more things --- src/handlers/misc/READY.ts | 10 +++++----- src/util/cache_members.ts | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/handlers/misc/READY.ts b/src/handlers/misc/READY.ts index 8fef56ae0..d6c077300 100644 --- a/src/handlers/misc/READY.ts +++ b/src/handlers/misc/READY.ts @@ -32,18 +32,18 @@ export function handleReady( ); // Start ready check in 2 seconds - setTimeout(async () => { + setTimeout(() => { eventHandlers.debug?.( "loop", `1. Running setTimeout in READY file.`, ); - await checkReady(payload, shardId, now); + checkReady(payload, shardId, now); }, 2000); } // Don't pass the shard itself because unavailableGuilds won't be updated by the GUILD_CREATE event /** This function checks if the shard is fully loaded */ -async function checkReady(payload: Ready, shardId: number, now: number) { +function checkReady(payload: Ready, shardId: number, now: number) { const shard = ws.shards.get(shardId); if (!shard) return; @@ -55,12 +55,12 @@ async function checkReady(payload: Ready, shardId: number, now: number) { loaded(shardId); } else { // Not all guilds were loaded but 10 seconds haven't passed so check again - setTimeout(async () => { + setTimeout(() => { eventHandlers.debug?.( "loop", `2. Running setTimeout in READY file.`, ); - await checkReady(payload, shardId, now); + checkReady(payload, shardId, now); }, 2000); } } else { diff --git a/src/util/cache_members.ts b/src/util/cache_members.ts index d28c91863..c2b9b81d6 100644 --- a/src/util/cache_members.ts +++ b/src/util/cache_members.ts @@ -10,6 +10,7 @@ const guildMemberQueue = new Map< let processingQueue = false; /** Cache all guild members without need to worry about overwriting something. */ +// deno-lint-ignore require-await export async function cacheMembers( guildId: bigint, members: GuildMemberWithUser[], From b892bdaa9d0127d51e128a165cd36dc596ec5aad Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 5 May 2021 18:13:18 +0200 Subject: [PATCH 137/148] deno extension has bad linter --- src/handlers/misc/READY.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/handlers/misc/READY.ts b/src/handlers/misc/READY.ts index d6c077300..56188fdd7 100644 --- a/src/handlers/misc/READY.ts +++ b/src/handlers/misc/READY.ts @@ -79,10 +79,10 @@ function loaded(shardId: number) { if (shardId === ws.lastShardId - 1) { // Still some shards are loading so wait another 2 seconds for them if (ws.shards.some((shard) => !shard.ready)) { - setTimeout(async () => { + setTimeout(() => { eventHandlers.debug?.( "loop", - `3. Running setTimeout in CHANNEL_DELTE file.`, + `3. Running setTimeout in READY file.`, ); loaded(shardId); }, 2000); From 1d92fcc09fff4cae2406c8cb8210e95ae8aa3f79 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 5 May 2021 18:14:14 +0200 Subject: [PATCH 138/148] Update application_command_interaction_data_option.ts --- ...lication_command_interaction_data_option.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/types/interactions/application_command_interaction_data_option.ts b/src/types/interactions/application_command_interaction_data_option.ts index c9817fab9..67189716e 100644 --- a/src/types/interactions/application_command_interaction_data_option.ts +++ b/src/types/interactions/application_command_interaction_data_option.ts @@ -27,7 +27,7 @@ interface ApplicationCommandInteractionDataOptionBase< export interface ApplicationCommandInteractionDataOptionSubCommand extends ApplicationCommandInteractionDataOptionBase< - DiscordApplicationCommandOptionTypes.SUB_COMMAND + DiscordApplicationCommandOptionTypes.SubCommand > { /** Present if this option is a group or subcommand */ options?: ApplicationCommandInteractionDataOption[]; @@ -36,7 +36,7 @@ export interface ApplicationCommandInteractionDataOptionSubCommand export interface ApplicationCommandInteractionDataOptionSubCommandGroup extends ApplicationCommandInteractionDataOptionBase< - DiscordApplicationCommandOptionTypes.SUB_COMMAND_GROUP + DiscordApplicationCommandOptionTypes.SubCommandGroup > { /** Present if this option is a group or subcommand */ options?: ApplicationCommandInteractionDataOption[]; @@ -44,42 +44,42 @@ export interface ApplicationCommandInteractionDataOptionSubCommandGroup export type ApplicationCommandInteractionDataOptionString = ApplicationCommandInteractionDataOptionBase< - DiscordApplicationCommandOptionTypes.STRING, + DiscordApplicationCommandOptionTypes.String, string >; export type ApplicationCommandInteractionDataOptionInteger = ApplicationCommandInteractionDataOptionBase< - DiscordApplicationCommandOptionTypes.INTEGER, + DiscordApplicationCommandOptionTypes.Integer, number >; export type ApplicationCommandInteractionDataOptionBoolean = ApplicationCommandInteractionDataOptionBase< - DiscordApplicationCommandOptionTypes.BOOLEAN, + DiscordApplicationCommandOptionTypes.Boolean, boolean >; export type ApplicationCommandInteractionDataOptionUser = ApplicationCommandInteractionDataOptionBase< - DiscordApplicationCommandOptionTypes.USER, + DiscordApplicationCommandOptionTypes.User, bigint >; export type ApplicationCommandInteractionDataOptionChannel = ApplicationCommandInteractionDataOptionBase< - DiscordApplicationCommandOptionTypes.CHANNEL, + DiscordApplicationCommandOptionTypes.Channel, bigint >; export type ApplicationCommandInteractionDataOptionRole = ApplicationCommandInteractionDataOptionBase< - DiscordApplicationCommandOptionTypes.ROLE, + DiscordApplicationCommandOptionTypes.Role, bigint >; export type ApplicationCommandInteractionDataOptionMentionable = ApplicationCommandInteractionDataOptionBase< - DiscordApplicationCommandOptionTypes.MENTIONABLE, + DiscordApplicationCommandOptionTypes.Mentionable, bigint >; From 6f280e77811e58ad5290a9f8fc458a4f3cce3570 Mon Sep 17 00:00:00 2001 From: rigormorrtiss Date: Wed, 5 May 2021 20:19:28 +0400 Subject: [PATCH 139/148] change(types): move error & file_content to discordeno/ (#903) * refactor(types): move errors, file_content module to types/discordeno * refactor(types): move error & file_content module to discordeno/ * Update and fix import statements --- src/helpers/channels/clone_channel.ts | 2 +- src/helpers/channels/delete_channel.ts | 2 +- src/helpers/channels/start_typing.ts | 2 +- src/helpers/channels/threads/get_thread_members.ts | 2 +- src/helpers/channels/threads/remove_from_thread.ts | 2 +- src/helpers/channels/threads/start_thread.ts | 2 +- src/helpers/commands/edit_slash_response.ts | 2 +- src/helpers/emojis/get_emoji.ts | 2 +- src/helpers/emojis/get_emojis.ts | 2 +- src/helpers/guilds/get_prune_count.ts | 2 +- src/helpers/guilds/get_widget.ts | 2 +- src/helpers/guilds/get_widget_image_url.ts | 2 +- src/helpers/invites/create_invite.ts | 2 +- src/helpers/invites/delete_invite.ts | 2 +- src/helpers/members/edit_bot_profile.ts | 2 +- src/helpers/members/edit_member.ts | 2 +- src/helpers/members/fetch_members.ts | 2 +- src/helpers/members/get_members.ts | 2 +- src/helpers/members/kick_member.ts | 2 +- src/helpers/members/prune_members.ts | 2 +- src/helpers/members/search_members.ts | 2 +- src/helpers/messages/delete_messages.ts | 2 +- src/helpers/messages/edit_message.ts | 2 +- src/helpers/messages/send_message.ts | 2 +- src/helpers/roles/add_role.ts | 2 +- src/helpers/roles/remove_role.ts | 2 +- src/helpers/webhooks/create_webhook.ts | 2 +- src/helpers/webhooks/edit_webhook_message.ts | 2 +- src/helpers/webhooks/send_webhook.ts | 2 +- src/rest/create_request_body.ts | 2 +- src/structures/role.ts | 2 +- src/types/{misc => discordeno}/errors.ts | 0 src/types/{misc => discordeno}/file_content.ts | 0 src/types/messages/create_message.ts | 2 +- src/types/mod.ts | 4 ++-- src/types/webhooks/edit_webhook_message.ts | 2 +- src/types/webhooks/execute_webhook.ts | 2 +- src/util/permissions.ts | 2 +- src/util/utils.ts | 2 +- 39 files changed, 38 insertions(+), 38 deletions(-) rename src/types/{misc => discordeno}/errors.ts (100%) rename src/types/{misc => discordeno}/file_content.ts (100%) diff --git a/src/helpers/channels/clone_channel.ts b/src/helpers/channels/clone_channel.ts index 6a3696fac..c2864a2c9 100644 --- a/src/helpers/channels/clone_channel.ts +++ b/src/helpers/channels/clone_channel.ts @@ -1,7 +1,7 @@ import { cacheHandlers } from "../../cache.ts"; import { DiscordChannelTypes } from "../../types/channels/channel_types.ts"; import type { CreateGuildChannel } from "../../types/guilds/create_guild_channel.ts"; -import { Errors } from "../../types/misc/errors.ts"; +import { Errors } from "../../types/discordeno/errors.ts"; import { bigintToSnowflake } from "../../util/bigint.ts"; import { calculatePermissions } from "../../util/permissions.ts"; import { createChannel } from "./create_channel.ts"; diff --git a/src/helpers/channels/delete_channel.ts b/src/helpers/channels/delete_channel.ts index 8634f827f..ed443c78a 100644 --- a/src/helpers/channels/delete_channel.ts +++ b/src/helpers/channels/delete_channel.ts @@ -1,6 +1,6 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; -import { Errors } from "../../types/misc/errors.ts"; +import { Errors } from "../../types/discordeno/errors.ts"; import { ChannelTypes } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/channels/start_typing.ts b/src/helpers/channels/start_typing.ts index 8a48c8ccc..486253f08 100644 --- a/src/helpers/channels/start_typing.ts +++ b/src/helpers/channels/start_typing.ts @@ -1,7 +1,7 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { DiscordChannelTypes } from "../../types/channels/channel_types.ts"; -import { Errors } from "../../types/misc/errors.ts"; +import { Errors } from "../../types/discordeno/errors.ts"; import { endpoints } from "../../util/constants.ts"; import { botHasChannelPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/channels/threads/get_thread_members.ts b/src/helpers/channels/threads/get_thread_members.ts index 34c1d0e13..89fe6a2ed 100644 --- a/src/helpers/channels/threads/get_thread_members.ts +++ b/src/helpers/channels/threads/get_thread_members.ts @@ -1,7 +1,7 @@ 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 { Errors } from "../../../types/discordeno/errors.ts"; import { endpoints } from "../../../util/constants.ts"; // TODO(threads): it seems like the documented return type is wrong diff --git a/src/helpers/channels/threads/remove_from_thread.ts b/src/helpers/channels/threads/remove_from_thread.ts index 9e967a843..917c36000 100644 --- a/src/helpers/channels/threads/remove_from_thread.ts +++ b/src/helpers/channels/threads/remove_from_thread.ts @@ -1,7 +1,7 @@ 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 { Errors } from "../../../types/discordeno/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. */ diff --git a/src/helpers/channels/threads/start_thread.ts b/src/helpers/channels/threads/start_thread.ts index dc4f8bbde..60f2fc372 100644 --- a/src/helpers/channels/threads/start_thread.ts +++ b/src/helpers/channels/threads/start_thread.ts @@ -2,7 +2,7 @@ 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 { Errors } from "../../../types/discordeno/errors.ts"; import { endpoints } from "../../../util/constants.ts"; import { camelKeysToSnakeCase } from "../../../util/utils.ts"; diff --git a/src/helpers/commands/edit_slash_response.ts b/src/helpers/commands/edit_slash_response.ts index 9857805e6..2c60d7836 100644 --- a/src/helpers/commands/edit_slash_response.ts +++ b/src/helpers/commands/edit_slash_response.ts @@ -3,7 +3,7 @@ import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import type { DiscordenoEditWebhookMessage } from "../../types/discordeno/edit_webhook_message.ts"; import { DiscordAllowedMentionsTypes } from "../../types/messages/allowed_mentions_types.ts"; -import { Errors } from "../../types/misc/errors.ts"; +import { Errors } from "../../types/discordeno/errors.ts"; import { endpoints } from "../../util/constants.ts"; /** To edit your response to a slash command. If a messageId is not provided it will default to editing the original response. */ diff --git a/src/helpers/emojis/get_emoji.ts b/src/helpers/emojis/get_emoji.ts index 9679ee86a..ceba22536 100644 --- a/src/helpers/emojis/get_emoji.ts +++ b/src/helpers/emojis/get_emoji.ts @@ -1,7 +1,7 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import type { Emoji } from "../../types/emojis/emoji.ts"; -import { Errors } from "../../types/misc/errors.ts"; +import { Errors } from "../../types/discordeno/errors.ts"; import { endpoints } from "../../util/constants.ts"; /** diff --git a/src/helpers/emojis/get_emojis.ts b/src/helpers/emojis/get_emojis.ts index e3dfa30fd..049f2a809 100644 --- a/src/helpers/emojis/get_emojis.ts +++ b/src/helpers/emojis/get_emojis.ts @@ -2,7 +2,7 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import type { Emoji } from "../../types/emojis/emoji.ts"; -import { Errors } from "../../types/misc/errors.ts"; +import { Errors } from "../../types/discordeno/errors.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; diff --git a/src/helpers/guilds/get_prune_count.ts b/src/helpers/guilds/get_prune_count.ts index fe25797d6..aaba70777 100644 --- a/src/helpers/guilds/get_prune_count.ts +++ b/src/helpers/guilds/get_prune_count.ts @@ -1,6 +1,6 @@ import { rest } from "../../rest/rest.ts"; import type { GetGuildPruneCountQuery } from "../../types/guilds/get_guild_prune_count.ts"; -import { Errors } from "../../types/misc/errors.ts"; +import { Errors } from "../../types/discordeno/errors.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; import { camelKeysToSnakeCase } from "../../util/utils.ts"; diff --git a/src/helpers/guilds/get_widget.ts b/src/helpers/guilds/get_widget.ts index 9a31b2c30..58659bacb 100644 --- a/src/helpers/guilds/get_widget.ts +++ b/src/helpers/guilds/get_widget.ts @@ -1,7 +1,7 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import type { GuildWidgetDetails } from "../../types/guilds/guild_widget_details.ts"; -import { Errors } from "../../types/misc/errors.ts"; +import { Errors } from "../../types/discordeno/errors.ts"; import { endpoints } from "../../util/constants.ts"; /** Returns the widget for the guild. */ diff --git a/src/helpers/guilds/get_widget_image_url.ts b/src/helpers/guilds/get_widget_image_url.ts index e754b0aba..d33413872 100644 --- a/src/helpers/guilds/get_widget_image_url.ts +++ b/src/helpers/guilds/get_widget_image_url.ts @@ -1,6 +1,6 @@ import { cacheHandlers } from "../../cache.ts"; import type { GetGuildWidgetImageQuery } from "../../types/guilds/get_guild_widget_image.ts"; -import { Errors } from "../../types/misc/errors.ts"; +import { Errors } from "../../types/discordeno/errors.ts"; import { endpoints } from "../../util/constants.ts"; /** Returns the widget image URL for the guild. */ diff --git a/src/helpers/invites/create_invite.ts b/src/helpers/invites/create_invite.ts index e6e3e6008..8266d1271 100644 --- a/src/helpers/invites/create_invite.ts +++ b/src/helpers/invites/create_invite.ts @@ -1,7 +1,7 @@ import { rest } from "../../rest/rest.ts"; import type { CreateChannelInvite } from "../../types/invites/create_channel_invite.ts"; import type { Invite } from "../../types/invites/invite.ts"; -import { Errors } from "../../types/misc/errors.ts"; +import { Errors } from "../../types/discordeno/errors.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/invites/delete_invite.ts b/src/helpers/invites/delete_invite.ts index 01d1d1c48..ba88f94c5 100644 --- a/src/helpers/invites/delete_invite.ts +++ b/src/helpers/invites/delete_invite.ts @@ -1,7 +1,7 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import type { Invite } from "../../types/invites/invite.ts"; -import { Errors } from "../../types/misc/errors.ts"; +import { Errors } from "../../types/discordeno/errors.ts"; import { endpoints } from "../../util/constants.ts"; import { botHasChannelPermissions, diff --git a/src/helpers/members/edit_bot_profile.ts b/src/helpers/members/edit_bot_profile.ts index 719351636..11efed089 100644 --- a/src/helpers/members/edit_bot_profile.ts +++ b/src/helpers/members/edit_bot_profile.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { Errors } from "../../types/misc/errors.ts"; +import { Errors } from "../../types/discordeno/errors.ts"; import type { User } from "../../types/users/user.ts"; import { endpoints } from "../../util/constants.ts"; import { urlToBase64 } from "../../util/utils.ts"; diff --git a/src/helpers/members/edit_member.ts b/src/helpers/members/edit_member.ts index 8b28e890b..e16958e89 100644 --- a/src/helpers/members/edit_member.ts +++ b/src/helpers/members/edit_member.ts @@ -3,7 +3,7 @@ import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import type { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; import type { ModifyGuildMember } from "../../types/guilds/modify_guild_member.ts"; -import { Errors } from "../../types/misc/errors.ts"; +import { Errors } from "../../types/discordeno/errors.ts"; import type { PermissionStrings } from "../../types/permissions/permission_strings.ts"; import { bigintToSnowflake } from "../../util/bigint.ts"; import { endpoints } from "../../util/constants.ts"; diff --git a/src/helpers/members/fetch_members.ts b/src/helpers/members/fetch_members.ts index 2781bafa1..ba94ca136 100644 --- a/src/helpers/members/fetch_members.ts +++ b/src/helpers/members/fetch_members.ts @@ -3,7 +3,7 @@ import { DiscordenoMember } from "../../structures/member.ts"; import { DiscordGatewayOpcodes } from "../../types/codes/gateway_opcodes.ts"; import { DiscordGatewayIntents } from "../../types/gateway/gateway_intents.ts"; import type { RequestGuildMembers } from "../../types/guilds/request_guild_members.ts"; -import { Errors } from "../../types/misc/errors.ts"; +import { Errors } from "../../types/discordeno/errors.ts"; import { Collection } from "../../util/collection.ts"; import { sendShardMessage } from "../../ws/send_shard_message.ts"; import { ws } from "../../ws/ws.ts"; diff --git a/src/helpers/members/get_members.ts b/src/helpers/members/get_members.ts index 2305d0cbc..15d8975c4 100644 --- a/src/helpers/members/get_members.ts +++ b/src/helpers/members/get_members.ts @@ -6,7 +6,7 @@ import { structures } from "../../structures/mod.ts"; import { DiscordGatewayIntents } from "../../types/gateway/gateway_intents.ts"; import type { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; import type { ListGuildMembers } from "../../types/guilds/list_guild_members.ts"; -import { Errors } from "../../types/misc/errors.ts"; +import { Errors } from "../../types/discordeno/errors.ts"; import { bigintToSnowflake } from "../../util/bigint.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; diff --git a/src/helpers/members/kick_member.ts b/src/helpers/members/kick_member.ts index 4b1151574..421cd9b5a 100644 --- a/src/helpers/members/kick_member.ts +++ b/src/helpers/members/kick_member.ts @@ -1,6 +1,6 @@ import { botId } from "../../bot.ts"; import { rest } from "../../rest/rest.ts"; -import { Errors } from "../../types/misc/errors.ts"; +import { Errors } from "../../types/discordeno/errors.ts"; import { endpoints } from "../../util/constants.ts"; import { highestRole, diff --git a/src/helpers/members/prune_members.ts b/src/helpers/members/prune_members.ts index a59860ad5..05e950a97 100644 --- a/src/helpers/members/prune_members.ts +++ b/src/helpers/members/prune_members.ts @@ -1,6 +1,6 @@ import { rest } from "../../rest/rest.ts"; import type { BeginGuildPrune } from "../../types/guilds/begin_guild_prune.ts"; -import { Errors } from "../../types/misc/errors.ts"; +import { Errors } from "../../types/discordeno/errors.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; import { camelKeysToSnakeCase } from "../../util/utils.ts"; diff --git a/src/helpers/members/search_members.ts b/src/helpers/members/search_members.ts index 6258c69de..6a9d2fede 100644 --- a/src/helpers/members/search_members.ts +++ b/src/helpers/members/search_members.ts @@ -4,7 +4,7 @@ import { DiscordenoMember } from "../../structures/member.ts"; import { structures } from "../../structures/mod.ts"; import type { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; import type { SearchGuildMembers } from "../../types/members/search_guild_members.ts"; -import { Errors } from "../../types/misc/errors.ts"; +import { Errors } from "../../types/discordeno/errors.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; diff --git a/src/helpers/messages/delete_messages.ts b/src/helpers/messages/delete_messages.ts index b8b3683a8..afed2cc95 100644 --- a/src/helpers/messages/delete_messages.ts +++ b/src/helpers/messages/delete_messages.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { Errors } from "../../types/misc/errors.ts"; +import { Errors } from "../../types/discordeno/errors.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/messages/edit_message.ts b/src/helpers/messages/edit_message.ts index b76a55974..637133b08 100644 --- a/src/helpers/messages/edit_message.ts +++ b/src/helpers/messages/edit_message.ts @@ -4,7 +4,7 @@ import { DiscordenoMessage } from "../../structures/message.ts"; import { structures } from "../../structures/mod.ts"; import { EditMessage } from "../../types/messages/edit_message.ts"; import type { Message } from "../../types/messages/message.ts"; -import { Errors } from "../../types/misc/errors.ts"; +import { Errors } from "../../types/discordeno/errors.ts"; import type { PermissionStrings } from "../../types/permissions/permission_strings.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/messages/send_message.ts b/src/helpers/messages/send_message.ts index cdfac97a4..2de5fcb1e 100644 --- a/src/helpers/messages/send_message.ts +++ b/src/helpers/messages/send_message.ts @@ -6,7 +6,7 @@ import { DiscordAllowedMentionsTypes } from "../../types/messages/allowed_mentio import { ButtonStyles } from "../../types/messages/components/button_styles.ts"; import type { CreateMessage } from "../../types/messages/create_message.ts"; import type { Message } from "../../types/messages/message.ts"; -import { Errors } from "../../types/misc/errors.ts"; +import { Errors } from "../../types/discordeno/errors.ts"; import type { PermissionStrings } from "../../types/permissions/permission_strings.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/roles/add_role.ts b/src/helpers/roles/add_role.ts index b207ad9c8..a080f01ba 100644 --- a/src/helpers/roles/add_role.ts +++ b/src/helpers/roles/add_role.ts @@ -1,6 +1,6 @@ import { botId } from "../../bot.ts"; import { rest } from "../../rest/rest.ts"; -import { Errors } from "../../types/misc/errors.ts"; +import { Errors } from "../../types/discordeno/errors.ts"; import { endpoints } from "../../util/constants.ts"; import { isHigherPosition, diff --git a/src/helpers/roles/remove_role.ts b/src/helpers/roles/remove_role.ts index 645cd990f..feb3c923b 100644 --- a/src/helpers/roles/remove_role.ts +++ b/src/helpers/roles/remove_role.ts @@ -1,6 +1,6 @@ import { botId } from "../../bot.ts"; import { rest } from "../../rest/rest.ts"; -import { Errors } from "../../types/misc/errors.ts"; +import { Errors } from "../../types/discordeno/errors.ts"; import { endpoints } from "../../util/constants.ts"; import { isHigherPosition, diff --git a/src/helpers/webhooks/create_webhook.ts b/src/helpers/webhooks/create_webhook.ts index a83c25147..14055633d 100644 --- a/src/helpers/webhooks/create_webhook.ts +++ b/src/helpers/webhooks/create_webhook.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { Errors } from "../../types/misc/errors.ts"; +import { Errors } from "../../types/discordeno/errors.ts"; import type { CreateWebhook } from "../../types/webhooks/create_webhook.ts"; import type { Webhook } from "../../types/webhooks/webhook.ts"; import { endpoints } from "../../util/constants.ts"; diff --git a/src/helpers/webhooks/edit_webhook_message.ts b/src/helpers/webhooks/edit_webhook_message.ts index f1565263b..c066d2933 100644 --- a/src/helpers/webhooks/edit_webhook_message.ts +++ b/src/helpers/webhooks/edit_webhook_message.ts @@ -2,7 +2,7 @@ import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordAllowedMentionsTypes } from "../../types/messages/allowed_mentions_types.ts"; import type { Message } from "../../types/messages/message.ts"; -import { Errors } from "../../types/misc/errors.ts"; +import { Errors } from "../../types/discordeno/errors.ts"; import type { EditWebhookMessage } from "../../types/webhooks/edit_webhook_message.ts"; import { endpoints } from "../../util/constants.ts"; diff --git a/src/helpers/webhooks/send_webhook.ts b/src/helpers/webhooks/send_webhook.ts index cb90615ed..ab96626df 100644 --- a/src/helpers/webhooks/send_webhook.ts +++ b/src/helpers/webhooks/send_webhook.ts @@ -2,7 +2,7 @@ import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordAllowedMentionsTypes } from "../../types/messages/allowed_mentions_types.ts"; import type { Message } from "../../types/messages/message.ts"; -import { Errors } from "../../types/misc/errors.ts"; +import { Errors } from "../../types/discordeno/errors.ts"; import type { ExecuteWebhook } from "../../types/webhooks/execute_webhook.ts"; import { endpoints } from "../../util/constants.ts"; diff --git a/src/rest/create_request_body.ts b/src/rest/create_request_body.ts index 76f01a7ec..595ada4a3 100644 --- a/src/rest/create_request_body.ts +++ b/src/rest/create_request_body.ts @@ -1,4 +1,4 @@ -import type { FileContent } from "../types/misc/file_content.ts"; +import type { FileContent } from "../types/discordeno/file_content.ts"; import { USER_AGENT } from "../util/constants.ts"; import { rest, RestPayload, RestRequest } from "./rest.ts"; diff --git a/src/structures/role.ts b/src/structures/role.ts index 58536c499..6af4de9d4 100644 --- a/src/structures/role.ts +++ b/src/structures/role.ts @@ -3,7 +3,7 @@ import { cache } from "../cache.ts"; import { deleteRole } from "../helpers/roles/delete_role.ts"; import { editRole } from "../helpers/roles/edit_role.ts"; import { CreateGuildRole } from "../types/guilds/create_guild_role.ts"; -import { Errors } from "../types/misc/errors.ts"; +import { Errors } from "../types/discordeno/errors.ts"; import type { Role } from "../types/permissions/role.ts"; import { snowflakeToBigint } from "../util/bigint.ts"; import { Collection } from "../util/collection.ts"; diff --git a/src/types/misc/errors.ts b/src/types/discordeno/errors.ts similarity index 100% rename from src/types/misc/errors.ts rename to src/types/discordeno/errors.ts diff --git a/src/types/misc/file_content.ts b/src/types/discordeno/file_content.ts similarity index 100% rename from src/types/misc/file_content.ts rename to src/types/discordeno/file_content.ts diff --git a/src/types/messages/create_message.ts b/src/types/messages/create_message.ts index c59ef410f..5bee7b6ae 100644 --- a/src/types/messages/create_message.ts +++ b/src/types/messages/create_message.ts @@ -1,7 +1,7 @@ import { Embed } from "../embeds/embed.ts"; import { AllowedMentions } from "../messages/allowed_mentions.ts"; import { MessageReference } from "../messages/message_reference.ts"; -import { FileContent } from "../misc/file_content.ts"; +import { FileContent } from "../discordeno/file_content.ts"; import { SnakeCasedPropertiesDeep } from "../util.ts"; import { MessageComponents } from "./components/message_components.ts"; diff --git a/src/types/mod.ts b/src/types/mod.ts index bc4d06750..61ed15cc6 100644 --- a/src/types/mod.ts +++ b/src/types/mod.ts @@ -168,8 +168,8 @@ export * from "./misc/activity_secrets.ts"; export * from "./misc/activity_timestamps.ts"; export * from "./misc/activity_types.ts"; export * from "./misc/client_status.ts"; -export * from "./misc/errors.ts"; -export * from "./misc/file_content.ts"; +export * from "./discordeno/errors.ts"; +export * from "./discordeno/file_content.ts"; export * from "./misc/image_format.ts"; export * from "./misc/image_size.ts"; export * from "./misc/presence_update.ts"; diff --git a/src/types/webhooks/edit_webhook_message.ts b/src/types/webhooks/edit_webhook_message.ts index d8fc7ba3c..ea18f54a5 100644 --- a/src/types/webhooks/edit_webhook_message.ts +++ b/src/types/webhooks/edit_webhook_message.ts @@ -1,7 +1,7 @@ import { Embed } from "../embeds/embed.ts"; import { AllowedMentions } from "../messages/allowed_mentions.ts"; import { Attachment } from "../messages/attachment.ts"; -import { FileContent } from "../misc/file_content.ts"; +import { FileContent } from "../discordeno/file_content.ts"; /** https://discord.com/developers/docs/resources/webhook#edit-webhook-message-jsonform-params */ export interface EditWebhookMessage { diff --git a/src/types/webhooks/execute_webhook.ts b/src/types/webhooks/execute_webhook.ts index bce114c30..c8c47639d 100644 --- a/src/types/webhooks/execute_webhook.ts +++ b/src/types/webhooks/execute_webhook.ts @@ -1,6 +1,6 @@ import { Embed } from "../embeds/embed.ts"; import { AllowedMentions } from "../messages/allowed_mentions.ts"; -import { FileContent } from "../misc/file_content.ts"; +import { FileContent } from "../discordeno/file_content.ts"; import { SnakeCasedPropertiesDeep } from "../util.ts"; /** https://discord.com/developers/docs/resources/webhook#execute-webhook */ diff --git a/src/util/permissions.ts b/src/util/permissions.ts index fec52ffb8..b2f5c71f8 100644 --- a/src/util/permissions.ts +++ b/src/util/permissions.ts @@ -5,7 +5,7 @@ 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 { Errors } from "../types/discordeno/errors.ts"; import { DiscordBitwisePermissionFlags } from "../types/permissions/bitwise_permission_flags.ts"; import type { PermissionStrings } from "../types/permissions/permission_strings.ts"; diff --git a/src/util/utils.ts b/src/util/utils.ts index 4b81719c6..8ae7511f9 100644 --- a/src/util/utils.ts +++ b/src/util/utils.ts @@ -5,7 +5,7 @@ import type { ApplicationCommandOptionChoice } from "../types/interactions/appli import { DiscordApplicationCommandOptionTypes } from "../types/interactions/application_command_option_types.ts"; import type { CreateGlobalApplicationCommand } from "../types/interactions/create_global_application_command.ts"; import type { EditGlobalApplicationCommand } from "../types/interactions/edit_global_application_command.ts"; -import { Errors } from "../types/misc/errors.ts"; +import { Errors } from "../types/discordeno/errors.ts"; import type { DiscordImageFormat } from "../types/misc/image_format.ts"; import type { DiscordImageSize } from "../types/misc/image_size.ts"; import { SLASH_COMMANDS_NAME_REGEX } from "./constants.ts"; From 7d4d6dfab50680c82d4a83d49c0d964ff1be7c6a Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 5 May 2021 18:20:50 +0200 Subject: [PATCH 140/148] rig --- src/types/messages/edit_message.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/messages/edit_message.ts b/src/types/messages/edit_message.ts index 0ca2f06d9..7009b9a1c 100644 --- a/src/types/messages/edit_message.ts +++ b/src/types/messages/edit_message.ts @@ -1,5 +1,5 @@ +import { FileContent } from "../discordeno/file_content.ts"; import { Embed } from "../embeds/embed.ts"; -import { FileContent } from "../misc/file_content.ts"; import { AllowedMentions } from "./allowed_mentions.ts"; import { Attachment } from "./attachment.ts"; From ee2e263d63daa6912c9286ef488b797f5c3375ec Mon Sep 17 00:00:00 2001 From: ITOH Date: Wed, 5 May 2021 17:21:39 +0100 Subject: [PATCH 141/148] fix: Intents enum now in PascalCase --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 66aac30ef..5d456f74f 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ import { startBot } from "https://deno.land/x/discordeno/mod.ts"; startBot({ token: "BOT TOKEN", - intents: ["GUILDS", "GUILD_MESSAGES"], + intents: ["Guilds", "GuildMessages"], eventHandlers: { ready() { console.log("Successfully connected to gateway"); From 7ff0d242ffe1f31c1e1402b20d923e192123a7c4 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 5 May 2021 20:06:32 +0200 Subject: [PATCH 142/148] hopefully the last dir change --- src/cache.ts | 2 +- .../commands/APPLICATION_COMMAND_CREATE.ts | 2 +- .../commands/APPLICATION_COMMAND_DELETE.ts | 2 +- .../commands/APPLICATION_COMMAND_UPDATE.ts | 2 +- .../guilds/GUILD_INTEGRATIONS_UPDATE.ts | 2 +- .../integrations/INTEGRATION_CREATE.ts | 2 +- .../integrations/INTEGRATION_DELETE.ts | 2 +- .../integrations/INTEGRATION_UPDATE.ts | 2 +- .../interactions/INTERACTION_CREATE.ts | 2 +- src/handlers/messages/MESSAGE_CREATE.ts | 2 +- src/handlers/messages/MESSAGE_REACTION_ADD.ts | 3 +- src/handlers/misc/PRESENCE_UPDATE.ts | 2 +- src/helpers/channels/create_channel.ts | 4 +- src/helpers/channels/edit_channel.ts | 4 +- .../channels/threads/get_archived_threads.ts | 4 +- src/helpers/channels/threads/start_thread.ts | 4 +- .../edit_slash_command_permissions.ts | 18 --- src/helpers/discovery/edit_discovery.ts | 4 +- src/helpers/guilds/edit_welcome_screen.ts | 4 +- src/helpers/guilds/get_audit_logs.ts | 4 +- src/helpers/guilds/get_prune_count.ts | 6 +- src/helpers/guilds/update_bot_voice_state.ts | 4 +- src/helpers/guilds/update_user_voice_state.ts | 4 +- src/helpers/integrations/get_integrations.ts | 2 +- .../batch_edit_slash_command_permissions.ts | 12 +- .../commands/create_slash_command.ts | 17 ++- .../commands/delete_slash_command.ts | 6 +- .../commands/delete_slash_response.ts | 6 +- .../edit_slash_command_permissions.ts | 18 +++ .../commands/edit_slash_response.ts | 14 +-- .../commands/get_slash_command.ts | 8 +- .../commands/get_slash_command_permission.ts | 8 +- .../commands/get_slash_command_permissions.ts | 8 +- .../commands/get_slash_commands.ts | 10 +- .../commands/upsert_slash_command.ts | 12 +- .../commands/upsert_slash_commands.ts | 12 +- .../get_original_interaction_response.ts | 0 .../send_interaction_response.ts | 0 src/helpers/invites/get_invite.ts | 4 +- src/helpers/members/ban_member.ts | 4 +- src/helpers/members/edit_member.ts | 8 +- src/helpers/members/fetch_members.ts | 4 +- src/helpers/members/get_member.ts | 2 +- src/helpers/members/get_members.ts | 6 +- src/helpers/members/prune_members.ts | 6 +- src/helpers/members/search_members.ts | 4 +- src/helpers/messages/send_message.ts | 6 +- .../{members => misc}/edit_bot_profile.ts | 0 src/helpers/mod.ts | 30 ++--- src/rest/run_method.ts | 4 +- src/structures/guild.ts | 6 +- src/structures/member.ts | 4 +- src/structures/message.ts | 2 +- src/structures/voice_state.ts | 2 +- src/types/{misc => activity}/activity.ts | 0 .../{misc => activity}/activity_assets.ts | 0 .../{misc => activity}/activity_button.ts | 0 .../{misc => activity}/activity_emoji.ts | 0 .../{misc => activity}/activity_flags.ts | 0 .../{misc => activity}/activity_party.ts | 0 .../{misc => activity}/activity_secrets.ts | 0 .../{misc => activity}/activity_timestamps.ts | 0 .../{misc => activity}/activity_types.ts | 0 src/types/{misc => activity}/client_status.ts | 0 .../{misc => activity}/presence_update.ts | 0 src/types/audit_log/audit_log.ts | 2 +- src/types/discordeno/create_slash_command.ts | 2 +- src/types/discordeno/eventHandlers.ts | 4 +- src/types/gateway/status_update.ts | 2 +- src/types/guilds/guild.ts | 4 +- .../guild_integrations_update.ts | 0 .../integration.ts | 0 .../integration_account.ts | 0 .../integration_application.ts | 0 .../integration_create_update.ts | 0 .../integration_delete.ts | 0 .../integration_expire_behaviors.ts | 0 .../{ => commands}/application_command.ts | 0 .../application_command_callback_data.ts | 4 +- ...pplication_command_create_update_delete.ts | 0 .../application_command_interaction_data.ts | 0 ...ication_command_interaction_data_option.ts | 0 ...ation_command_interaction_data_resolved.ts | 8 +- .../application_command_option.ts | 0 .../application_command_option_choice.ts | 0 .../application_command_option_types.ts | 0 .../application_command_permission_types.ts | 0 .../application_command_permissions.ts | 0 .../create_global_application_command.ts | 0 .../create_guild_application_command.ts | 0 .../edit_global_application_command.ts | 0 .../edit_guild_application_command.ts | 0 .../guild_application_command_permissions.ts | 0 src/types/interactions/interaction.ts | 4 +- .../interactions/interaction_guild_member.ts | 2 +- .../interactions/interaction_response.ts | 2 +- src/types/{guilds => members}/guild_member.ts | 0 src/types/members/guild_member_add.ts | 2 +- src/types/members/guild_members_chunk.ts | 4 +- .../{guilds => members}/list_guild_members.ts | 0 .../modify_current_user_nick.ts | 0 .../request_guild_members.ts | 0 src/types/messages/message.ts | 2 +- src/types/messages/message_reaction_add.ts | 2 +- src/types/misc/typing_start.ts | 2 +- src/types/mod.ts | 105 +++++++++++------- src/types/users/connection.ts | 2 +- src/types/voice/voice_state.ts | 2 +- src/util/cache_members.ts | 2 +- src/util/utils.ts | 26 ++--- src/ws/handle_on_message.ts | 4 +- src/ws/start_gateway.ts | 4 +- tests/util/utils.ts | 16 +-- 113 files changed, 267 insertions(+), 250 deletions(-) delete mode 100644 src/helpers/commands/edit_slash_command_permissions.ts rename src/helpers/{ => interactions}/commands/batch_edit_slash_command_permissions.ts (54%) rename src/helpers/{ => interactions}/commands/create_slash_command.ts (72%) rename src/helpers/{ => interactions}/commands/delete_slash_command.ts (66%) rename src/helpers/{ => interactions}/commands/delete_slash_response.ts (76%) create mode 100644 src/helpers/interactions/commands/edit_slash_command_permissions.ts rename src/helpers/{ => interactions}/commands/edit_slash_response.ts (80%) rename src/helpers/{ => interactions}/commands/get_slash_command.ts (61%) rename src/helpers/{ => interactions}/commands/get_slash_command_permission.ts (57%) rename src/helpers/{ => interactions}/commands/get_slash_command_permissions.ts (55%) rename src/helpers/{ => interactions}/commands/get_slash_commands.ts (55%) rename src/helpers/{ => interactions}/commands/upsert_slash_command.ts (52%) rename src/helpers/{ => interactions}/commands/upsert_slash_commands.ts (58%) rename src/helpers/{commands => interactions}/get_original_interaction_response.ts (100%) rename src/helpers/{commands => interactions}/send_interaction_response.ts (100%) rename src/helpers/{members => misc}/edit_bot_profile.ts (100%) rename src/types/{misc => activity}/activity.ts (100%) rename src/types/{misc => activity}/activity_assets.ts (100%) rename src/types/{misc => activity}/activity_button.ts (100%) rename src/types/{misc => activity}/activity_emoji.ts (100%) rename src/types/{misc => activity}/activity_flags.ts (100%) rename src/types/{misc => activity}/activity_party.ts (100%) rename src/types/{misc => activity}/activity_secrets.ts (100%) rename src/types/{misc => activity}/activity_timestamps.ts (100%) rename src/types/{misc => activity}/activity_types.ts (100%) rename src/types/{misc => activity}/client_status.ts (100%) rename src/types/{misc => activity}/presence_update.ts (100%) rename src/types/{integration => integrations}/guild_integrations_update.ts (100%) rename src/types/{integration => integrations}/integration.ts (100%) rename src/types/{integration => integrations}/integration_account.ts (100%) rename src/types/{integration => integrations}/integration_application.ts (100%) rename src/types/{integration => integrations}/integration_create_update.ts (100%) rename src/types/{integration => integrations}/integration_delete.ts (100%) rename src/types/{integration => integrations}/integration_expire_behaviors.ts (100%) rename src/types/interactions/{ => commands}/application_command.ts (100%) rename src/types/interactions/{ => commands}/application_command_callback_data.ts (80%) rename src/types/interactions/{ => commands}/application_command_create_update_delete.ts (100%) rename src/types/interactions/{ => commands}/application_command_interaction_data.ts (100%) rename src/types/interactions/{ => commands}/application_command_interaction_data_option.ts (100%) rename src/types/interactions/{ => commands}/application_command_interaction_data_resolved.ts (68%) rename src/types/interactions/{ => commands}/application_command_option.ts (100%) rename src/types/interactions/{ => commands}/application_command_option_choice.ts (100%) rename src/types/interactions/{ => commands}/application_command_option_types.ts (100%) rename src/types/interactions/{ => commands}/application_command_permission_types.ts (100%) rename src/types/interactions/{ => commands}/application_command_permissions.ts (100%) rename src/types/interactions/{ => commands}/create_global_application_command.ts (100%) rename src/types/interactions/{ => commands}/create_guild_application_command.ts (100%) rename src/types/interactions/{ => commands}/edit_global_application_command.ts (100%) rename src/types/interactions/{ => commands}/edit_guild_application_command.ts (100%) rename src/types/interactions/{ => commands}/guild_application_command_permissions.ts (100%) rename src/types/{guilds => members}/guild_member.ts (100%) rename src/types/{guilds => members}/list_guild_members.ts (100%) rename src/types/{guilds => members}/modify_current_user_nick.ts (100%) rename src/types/{guilds => members}/request_guild_members.ts (100%) diff --git a/src/cache.ts b/src/cache.ts index 6da6e43ed..3abdab3c9 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -3,8 +3,8 @@ import type { DiscordenoChannel } from "./structures/channel.ts"; import type { DiscordenoGuild } from "./structures/guild.ts"; import type { DiscordenoMember } from "./structures/member.ts"; import type { DiscordenoMessage } from "./structures/message.ts"; +import type { PresenceUpdate } from "./types/activity/presence_update.ts"; import type { Emoji } from "./types/emojis/emoji.ts"; -import type { PresenceUpdate } from "./types/misc/presence_update.ts"; import { Collection } from "./util/collection.ts"; export const cache = { diff --git a/src/handlers/commands/APPLICATION_COMMAND_CREATE.ts b/src/handlers/commands/APPLICATION_COMMAND_CREATE.ts index c52eddfa1..bcfa4270e 100644 --- a/src/handlers/commands/APPLICATION_COMMAND_CREATE.ts +++ b/src/handlers/commands/APPLICATION_COMMAND_CREATE.ts @@ -2,7 +2,7 @@ import { eventHandlers } from "../../bot.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { ApplicationCommandCreateUpdateDelete, -} from "../../types/interactions/application_command_create_update_delete.ts"; +} from "../../types/interactions/commands/application_command_create_update_delete.ts"; export function handleApplicationCommandCreate( data: DiscordGatewayPayload, diff --git a/src/handlers/commands/APPLICATION_COMMAND_DELETE.ts b/src/handlers/commands/APPLICATION_COMMAND_DELETE.ts index 674b23330..5a9fe3e23 100644 --- a/src/handlers/commands/APPLICATION_COMMAND_DELETE.ts +++ b/src/handlers/commands/APPLICATION_COMMAND_DELETE.ts @@ -2,7 +2,7 @@ import { eventHandlers } from "../../bot.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { ApplicationCommandCreateUpdateDelete, -} from "../../types/interactions/application_command_create_update_delete.ts"; +} from "../../types/interactions/commands/application_command_create_update_delete.ts"; export function handleApplicationCommandDelete(data: DiscordGatewayPayload) { eventHandlers.applicationCommandDelete?.( diff --git a/src/handlers/commands/APPLICATION_COMMAND_UPDATE.ts b/src/handlers/commands/APPLICATION_COMMAND_UPDATE.ts index b5ac20ee3..b1940c91c 100644 --- a/src/handlers/commands/APPLICATION_COMMAND_UPDATE.ts +++ b/src/handlers/commands/APPLICATION_COMMAND_UPDATE.ts @@ -2,7 +2,7 @@ import { eventHandlers } from "../../bot.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { ApplicationCommandCreateUpdateDelete, -} from "../../types/interactions/application_command_create_update_delete.ts"; +} from "../../types/interactions/commands/application_command_create_update_delete.ts"; export function handleApplicationCommandUpdate(data: DiscordGatewayPayload) { eventHandlers.applicationCommandUpdate?.( diff --git a/src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts b/src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts index 136db1a4d..0175c6843 100644 --- a/src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts +++ b/src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts @@ -1,7 +1,7 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import type { GuildIntegrationsUpdate } from "../../types/integration/guild_integrations_update.ts"; +import type { GuildIntegrationsUpdate } from "../../types/integrations/guild_integrations_update.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleGuildIntegrationsUpdate( diff --git a/src/handlers/integrations/INTEGRATION_CREATE.ts b/src/handlers/integrations/INTEGRATION_CREATE.ts index 147831a5a..7b6f31937 100644 --- a/src/handlers/integrations/INTEGRATION_CREATE.ts +++ b/src/handlers/integrations/INTEGRATION_CREATE.ts @@ -2,7 +2,7 @@ import { eventHandlers } from "../../bot.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { IntegrationCreateUpdate, -} from "../../types/integration/integration_create_update.ts"; +} from "../../types/integrations/integration_create_update.ts"; export function handleIntegrationCreate( data: DiscordGatewayPayload, diff --git a/src/handlers/integrations/INTEGRATION_DELETE.ts b/src/handlers/integrations/INTEGRATION_DELETE.ts index d7fcbe088..207bf339a 100644 --- a/src/handlers/integrations/INTEGRATION_DELETE.ts +++ b/src/handlers/integrations/INTEGRATION_DELETE.ts @@ -1,6 +1,6 @@ import { eventHandlers } from "../../bot.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import type { IntegrationDelete } from "../../types/integration/integration_delete.ts"; +import type { IntegrationDelete } from "../../types/integrations/integration_delete.ts"; export function handleIntegrationDelete(data: DiscordGatewayPayload) { eventHandlers.integrationDelete?.( diff --git a/src/handlers/integrations/INTEGRATION_UPDATE.ts b/src/handlers/integrations/INTEGRATION_UPDATE.ts index 4ce7fa940..d9953a982 100644 --- a/src/handlers/integrations/INTEGRATION_UPDATE.ts +++ b/src/handlers/integrations/INTEGRATION_UPDATE.ts @@ -2,7 +2,7 @@ import { eventHandlers } from "../../bot.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { IntegrationCreateUpdate, -} from "../../types/integration/integration_create_update.ts"; +} from "../../types/integrations/integration_create_update.ts"; export function handleIntegrationUpdate(data: DiscordGatewayPayload) { eventHandlers.integrationUpdate?.( diff --git a/src/handlers/interactions/INTERACTION_CREATE.ts b/src/handlers/interactions/INTERACTION_CREATE.ts index 6c5a03913..6ce6996ec 100644 --- a/src/handlers/interactions/INTERACTION_CREATE.ts +++ b/src/handlers/interactions/INTERACTION_CREATE.ts @@ -2,8 +2,8 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { structures } from "../../structures/mod.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import type { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; import type { Interaction } from "../../types/interactions/interaction.ts"; +import type { GuildMemberWithUser } from "../../types/members/guild_member.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleInteractionCreate(data: DiscordGatewayPayload) { diff --git a/src/handlers/messages/MESSAGE_CREATE.ts b/src/handlers/messages/MESSAGE_CREATE.ts index 5492f8664..2f9dbfb8a 100644 --- a/src/handlers/messages/MESSAGE_CREATE.ts +++ b/src/handlers/messages/MESSAGE_CREATE.ts @@ -2,7 +2,7 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { structures } from "../../structures/mod.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import type { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; +import type { GuildMemberWithUser } from "../../types/members/guild_member.ts"; import type { Message } from "../../types/messages/message.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; diff --git a/src/handlers/messages/MESSAGE_REACTION_ADD.ts b/src/handlers/messages/MESSAGE_REACTION_ADD.ts index 1bd69cf8c..8dc959bae 100644 --- a/src/handlers/messages/MESSAGE_REACTION_ADD.ts +++ b/src/handlers/messages/MESSAGE_REACTION_ADD.ts @@ -6,7 +6,6 @@ import type { 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; @@ -56,7 +55,7 @@ export async function handleMessageReactionAdd(data: DiscordGatewayPayload) { } eventHandlers.reactionAdd?.( - snakeKeysToCamelCase(payload), + payload, message, ); } diff --git a/src/handlers/misc/PRESENCE_UPDATE.ts b/src/handlers/misc/PRESENCE_UPDATE.ts index d1c2127c9..c54f2db1c 100644 --- a/src/handlers/misc/PRESENCE_UPDATE.ts +++ b/src/handlers/misc/PRESENCE_UPDATE.ts @@ -1,7 +1,7 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; +import type { PresenceUpdate } from "../../types/activity/presence_update.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import type { PresenceUpdate } from "../../types/misc/presence_update.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handlePresenceUpdate(data: DiscordGatewayPayload) { diff --git a/src/helpers/channels/create_channel.ts b/src/helpers/channels/create_channel.ts index ec5288575..83aad09d5 100644 --- a/src/helpers/channels/create_channel.ts +++ b/src/helpers/channels/create_channel.ts @@ -12,7 +12,7 @@ import { calculateBits, requireOverwritePermissions, } from "../../util/permissions.ts"; -import { camelKeysToSnakeCase } from "../../util/utils.ts"; +import { snakelize } from "../../util/utils.ts"; /** Create a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */ export async function createChannel( @@ -34,7 +34,7 @@ export async function createChannel( "post", endpoints.GUILD_CHANNELS(guildId), { - ...camelKeysToSnakeCase(options ?? {}), + ...snakelize(options ?? {}), permission_overwrites: options?.permissionOverwrites?.map((perm) => ({ ...perm, allow: calculateBits(perm.allow), diff --git a/src/helpers/channels/edit_channel.ts b/src/helpers/channels/edit_channel.ts index d22feab6e..b0c4247db 100644 --- a/src/helpers/channels/edit_channel.ts +++ b/src/helpers/channels/edit_channel.ts @@ -12,7 +12,7 @@ import { requireBotChannelPermissions, requireOverwritePermissions, } from "../../util/permissions.ts"; -import { camelKeysToSnakeCase, hasOwnProperty } from "../../util/utils.ts"; +import { hasOwnProperty, snakelize } from "../../util/utils.ts"; //TODO: implement DM group channel edit //TODO(threads): check thread perms @@ -88,7 +88,7 @@ export async function editChannel( } const payload = { - ...camelKeysToSnakeCase>(options), + ...snakelize>(options), // deno-lint-ignore camelcase permission_overwrites: hasOwnProperty(options, "permissionOverwrites") diff --git a/src/helpers/channels/threads/get_archived_threads.ts b/src/helpers/channels/threads/get_archived_threads.ts index 4a4de2927..afff32710 100644 --- a/src/helpers/channels/threads/get_archived_threads.ts +++ b/src/helpers/channels/threads/get_archived_threads.ts @@ -1,7 +1,7 @@ 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"; +import { snakelize } from "../../../util/utils.ts"; export async function getArchivedThreads( channelId: bigint, @@ -19,6 +19,6 @@ export async function getArchivedThreads( : options?.type === "private" ? endpoints.THREAD_ARCHIVED_PRIVATE(channelId) : endpoints.THREAD_ARCHIVED_PUBLIC(channelId), - camelKeysToSnakeCase(options ?? {}), + snakelize(options ?? {}), ); } diff --git a/src/helpers/channels/threads/start_thread.ts b/src/helpers/channels/threads/start_thread.ts index 60f2fc372..0a6f90e2e 100644 --- a/src/helpers/channels/threads/start_thread.ts +++ b/src/helpers/channels/threads/start_thread.ts @@ -4,7 +4,7 @@ import { ChannelTypes } from "../../../types/channels/channel_types.ts"; import { StartThread } from "../../../types/channels/threads/start_thread.ts"; import { Errors } from "../../../types/discordeno/errors.ts"; import { endpoints } from "../../../util/constants.ts"; -import { camelKeysToSnakeCase } from "../../../util/utils.ts"; +import { snakelize } 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. @@ -33,6 +33,6 @@ export async function startThread( options?.messageId ? endpoints.THREAD_START_PUBLIC(channelId, options.messageId) : endpoints.THREAD_START_PRIVATE(channelId), - camelKeysToSnakeCase(options), + snakelize(options), ); } diff --git a/src/helpers/commands/edit_slash_command_permissions.ts b/src/helpers/commands/edit_slash_command_permissions.ts deleted file mode 100644 index bbaae3bc4..000000000 --- a/src/helpers/commands/edit_slash_command_permissions.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { applicationId } from "../../bot.ts"; -import { rest } from "../../rest/rest.ts"; -import type { ApplicationCommandPermissions } from "../../types/interactions/application_command_permissions.ts"; -import { endpoints } from "../../util/constants.ts"; -import { camelKeysToSnakeCase } from "../../util/utils.ts"; - -/** Edits command permissions for a specific command for your application in a guild. */ -export async function editSlashCommandPermissions( - guildId: bigint, - commandId: bigint, - options: ApplicationCommandPermissions[], -) { - return await rest.runMethod( - "put", - endpoints.COMMANDS_PERMISSION(applicationId, guildId, commandId), - { permissions: camelKeysToSnakeCase(options) }, - ); -} diff --git a/src/helpers/discovery/edit_discovery.ts b/src/helpers/discovery/edit_discovery.ts index 71f7e3ab5..e4b48f6f2 100644 --- a/src/helpers/discovery/edit_discovery.ts +++ b/src/helpers/discovery/edit_discovery.ts @@ -3,7 +3,7 @@ import type { DiscoveryMetadata } from "../../types/discovery/discovery_metadata import type { ModifyGuildDiscoveryMetadata } from "../../types/discovery/modify_guild_discovery_metadata.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; -import { camelKeysToSnakeCase } from "../../util/utils.ts"; +import { snakelize } 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( @@ -15,6 +15,6 @@ export async function editDiscovery( return await rest.runMethod( "patch", endpoints.DISCOVERY_MODIFY(guildId), - camelKeysToSnakeCase(data), + snakelize(data), ); } diff --git a/src/helpers/guilds/edit_welcome_screen.ts b/src/helpers/guilds/edit_welcome_screen.ts index 29114dea3..07034cef5 100644 --- a/src/helpers/guilds/edit_welcome_screen.ts +++ b/src/helpers/guilds/edit_welcome_screen.ts @@ -2,7 +2,7 @@ import { rest } from "../../rest/rest.ts"; import type { ModifyGuildWelcomeScreen } from "../../types/guilds/modify_guild_welcome_screen.ts"; import type { WelcomeScreen } from "../../types/guilds/welcome_screen.ts"; import { endpoints } from "../../util/constants.ts"; -import { camelKeysToSnakeCase } from "../../util/utils.ts"; +import { snakelize } from "../../util/utils.ts"; export async function editWelcomeScreen( guildId: bigint, @@ -11,6 +11,6 @@ export async function editWelcomeScreen( return await rest.runMethod( "patch", endpoints.GUILD_WELCOME_SCREEN(guildId), - camelKeysToSnakeCase(options), + snakelize(options), ); } diff --git a/src/helpers/guilds/get_audit_logs.ts b/src/helpers/guilds/get_audit_logs.ts index a090fbf49..a82cce811 100644 --- a/src/helpers/guilds/get_audit_logs.ts +++ b/src/helpers/guilds/get_audit_logs.ts @@ -3,7 +3,7 @@ import type { AuditLog } from "../../types/audit_log/audit_log.ts"; import type { GetGuildAuditLog } from "../../types/audit_log/get_guild_audit_log.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; -import { camelKeysToSnakeCase } from "../../util/utils.ts"; +import { snakelize } from "../../util/utils.ts"; /** Returns the audit logs for the guild. Requires VIEW AUDIT LOGS permission */ export async function getAuditLogs( @@ -15,7 +15,7 @@ export async function getAuditLogs( return await rest.runMethod( "get", endpoints.GUILD_AUDIT_LOGS(guildId), - camelKeysToSnakeCase({ + snakelize({ ...options, limit: options.limit && options.limit >= 1 && options.limit <= 100 ? options.limit diff --git a/src/helpers/guilds/get_prune_count.ts b/src/helpers/guilds/get_prune_count.ts index aaba70777..327516a5d 100644 --- a/src/helpers/guilds/get_prune_count.ts +++ b/src/helpers/guilds/get_prune_count.ts @@ -1,9 +1,9 @@ import { rest } from "../../rest/rest.ts"; -import type { GetGuildPruneCountQuery } from "../../types/guilds/get_guild_prune_count.ts"; import { Errors } from "../../types/discordeno/errors.ts"; +import type { GetGuildPruneCountQuery } from "../../types/guilds/get_guild_prune_count.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; -import { camelKeysToSnakeCase } from "../../util/utils.ts"; +import { snakelize } 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( @@ -20,7 +20,7 @@ export async function getPruneCount( const result = await rest.runMethod( "get", endpoints.GUILD_PRUNE(guildId), - camelKeysToSnakeCase(options ?? {}), + snakelize(options ?? {}), ); return result.pruned as number; diff --git a/src/helpers/guilds/update_bot_voice_state.ts b/src/helpers/guilds/update_bot_voice_state.ts index 60426da49..8043de974 100644 --- a/src/helpers/guilds/update_bot_voice_state.ts +++ b/src/helpers/guilds/update_bot_voice_state.ts @@ -3,7 +3,7 @@ import type { UpdateSelfVoiceState, } from "../../types/guilds/update_self_voice_state.ts"; import { endpoints } from "../../util/constants.ts"; -import { camelKeysToSnakeCase } from "../../util/utils.ts"; +import { snakelize } from "../../util/utils.ts"; /** * Updates the current user's voice state. @@ -21,6 +21,6 @@ export async function updateBotVoiceState( return await rest.runMethod( "patch", endpoints.UPDATE_VOICE_STATE(guildId), - camelKeysToSnakeCase(data), + snakelize(data), ); } diff --git a/src/helpers/guilds/update_user_voice_state.ts b/src/helpers/guilds/update_user_voice_state.ts index 6a8e47ebd..38191274b 100644 --- a/src/helpers/guilds/update_user_voice_state.ts +++ b/src/helpers/guilds/update_user_voice_state.ts @@ -3,7 +3,7 @@ import type { UpdateOthersVoiceState, } from "../../types/guilds/update_others_voice_state.ts"; import { endpoints } from "../../util/constants.ts"; -import { camelKeysToSnakeCase } from "../../util/utils.ts"; +import { snakelize } from "../../util/utils.ts"; /** * Updates another user's voice state. @@ -22,6 +22,6 @@ export function updateVoiceState( return rest.runMethod( "patch", endpoints.UPDATE_VOICE_STATE(guildId, userId), - camelKeysToSnakeCase(data), + snakelize(data), ); } diff --git a/src/helpers/integrations/get_integrations.ts b/src/helpers/integrations/get_integrations.ts index 1947d3317..340bf8421 100644 --- a/src/helpers/integrations/get_integrations.ts +++ b/src/helpers/integrations/get_integrations.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import type { Integration } from "../../types/integration/integration.ts"; +import type { Integration } from "../../types/integrations/integration.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/commands/batch_edit_slash_command_permissions.ts b/src/helpers/interactions/commands/batch_edit_slash_command_permissions.ts similarity index 54% rename from src/helpers/commands/batch_edit_slash_command_permissions.ts rename to src/helpers/interactions/commands/batch_edit_slash_command_permissions.ts index 8be782bff..f8b957019 100644 --- a/src/helpers/commands/batch_edit_slash_command_permissions.ts +++ b/src/helpers/interactions/commands/batch_edit_slash_command_permissions.ts @@ -1,8 +1,8 @@ -import { applicationId } from "../../bot.ts"; -import { rest } from "../../rest/rest.ts"; -import type { ApplicationCommandPermissions } from "../../types/interactions/application_command_permissions.ts"; -import { endpoints } from "../../util/constants.ts"; -import { camelKeysToSnakeCase } from "../../util/utils.ts"; +import { applicationId } from "../../../bot.ts"; +import { rest } from "../../../rest/rest.ts"; +import type { ApplicationCommandPermissions } from "../../../types/interactions/commands/application_command_permissions.ts"; +import { endpoints } from "../../../util/constants.ts"; +import { snakelize } 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( @@ -12,6 +12,6 @@ export async function batchEditSlashCommandPermissions( return await rest.runMethod( "put", endpoints.COMMANDS_PERMISSIONS(applicationId, guildId), - camelKeysToSnakeCase(options), + snakelize(options), ); } diff --git a/src/helpers/commands/create_slash_command.ts b/src/helpers/interactions/commands/create_slash_command.ts similarity index 72% rename from src/helpers/commands/create_slash_command.ts rename to src/helpers/interactions/commands/create_slash_command.ts index b5241f556..2d9c1ebf6 100644 --- a/src/helpers/commands/create_slash_command.ts +++ b/src/helpers/interactions/commands/create_slash_command.ts @@ -1,12 +1,9 @@ -import { applicationId } from "../../bot.ts"; -import { rest } from "../../rest/rest.ts"; -import type { ApplicationCommand } from "../../types/interactions/application_command.ts"; -import type { CreateGlobalApplicationCommand } from "../../types/interactions/create_global_application_command.ts"; -import { endpoints } from "../../util/constants.ts"; -import { - camelKeysToSnakeCase, - validateSlashCommands, -} from "../../util/utils.ts"; +import { applicationId } from "../../../bot.ts"; +import { rest } from "../../../rest/rest.ts"; +import type { ApplicationCommand } from "../../../types/interactions/commands/application_command.ts"; +import type { CreateGlobalApplicationCommand } from "../../../types/interactions/commands/create_global_application_command.ts"; +import { endpoints } from "../../../util/constants.ts"; +import { snakelize, validateSlashCommands } from "../../../util/utils.ts"; /** * There are two kinds of Slash Commands: global commands and guild commands. Global commands are available for every guild that adds your app; guild commands are specific to the guild you specify when making them. Command names are unique per application within each scope (global and guild). That means: @@ -30,6 +27,6 @@ export async function createSlashCommand( guildId ? endpoints.COMMANDS_GUILD(applicationId, guildId) : endpoints.COMMANDS(applicationId), - camelKeysToSnakeCase(options), + snakelize(options), ); } diff --git a/src/helpers/commands/delete_slash_command.ts b/src/helpers/interactions/commands/delete_slash_command.ts similarity index 66% rename from src/helpers/commands/delete_slash_command.ts rename to src/helpers/interactions/commands/delete_slash_command.ts index 0468ad3e5..d7fd746cb 100644 --- a/src/helpers/commands/delete_slash_command.ts +++ b/src/helpers/interactions/commands/delete_slash_command.ts @@ -1,6 +1,6 @@ -import { applicationId } from "../../bot.ts"; -import { rest } from "../../rest/rest.ts"; -import { endpoints } from "../../util/constants.ts"; +import { applicationId } from "../../../bot.ts"; +import { rest } from "../../../rest/rest.ts"; +import { endpoints } from "../../../util/constants.ts"; /** Deletes a slash command. */ export async function deleteSlashCommand( diff --git a/src/helpers/commands/delete_slash_response.ts b/src/helpers/interactions/commands/delete_slash_response.ts similarity index 76% rename from src/helpers/commands/delete_slash_response.ts rename to src/helpers/interactions/commands/delete_slash_response.ts index 7e6d7d991..d772f6e64 100644 --- a/src/helpers/commands/delete_slash_response.ts +++ b/src/helpers/interactions/commands/delete_slash_response.ts @@ -1,6 +1,6 @@ -import { applicationId } from "../../bot.ts"; -import { rest } from "../../rest/rest.ts"; -import { endpoints } from "../../util/constants.ts"; +import { applicationId } from "../../../bot.ts"; +import { rest } from "../../../rest/rest.ts"; +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( diff --git a/src/helpers/interactions/commands/edit_slash_command_permissions.ts b/src/helpers/interactions/commands/edit_slash_command_permissions.ts new file mode 100644 index 000000000..6bbe374a7 --- /dev/null +++ b/src/helpers/interactions/commands/edit_slash_command_permissions.ts @@ -0,0 +1,18 @@ +import { applicationId } from "../../../bot.ts"; +import { rest } from "../../../rest/rest.ts"; +import type { ApplicationCommandPermissions } from "../../../types/interactions/commands/application_command_permissions.ts"; +import { endpoints } from "../../../util/constants.ts"; +import { snakelize } from "../../../util/utils.ts"; + +/** Edits command permissions for a specific command for your application in a guild. */ +export async function editSlashCommandPermissions( + guildId: bigint, + commandId: bigint, + options: ApplicationCommandPermissions[], +) { + return await rest.runMethod( + "put", + endpoints.COMMANDS_PERMISSION(applicationId, guildId, commandId), + { permissions: snakelize(options) }, + ); +} diff --git a/src/helpers/commands/edit_slash_response.ts b/src/helpers/interactions/commands/edit_slash_response.ts similarity index 80% rename from src/helpers/commands/edit_slash_response.ts rename to src/helpers/interactions/commands/edit_slash_response.ts index 2c60d7836..13ea278a7 100644 --- a/src/helpers/commands/edit_slash_response.ts +++ b/src/helpers/interactions/commands/edit_slash_response.ts @@ -1,10 +1,10 @@ -import { applicationId } from "../../bot.ts"; -import { rest } from "../../rest/rest.ts"; -import { structures } from "../../structures/mod.ts"; -import type { DiscordenoEditWebhookMessage } from "../../types/discordeno/edit_webhook_message.ts"; -import { DiscordAllowedMentionsTypes } from "../../types/messages/allowed_mentions_types.ts"; -import { Errors } from "../../types/discordeno/errors.ts"; -import { endpoints } from "../../util/constants.ts"; +import { applicationId } from "../../../bot.ts"; +import { rest } from "../../../rest/rest.ts"; +import { structures } from "../../../structures/mod.ts"; +import type { DiscordenoEditWebhookMessage } from "../../../types/discordeno/edit_webhook_message.ts"; +import { Errors } from "../../../types/discordeno/errors.ts"; +import { DiscordAllowedMentionsTypes } from "../../../types/messages/allowed_mentions_types.ts"; +import { endpoints } from "../../../util/constants.ts"; /** To edit your response to a slash command. If a messageId is not provided it will default to editing the original response. */ export async function editSlashResponse( diff --git a/src/helpers/commands/get_slash_command.ts b/src/helpers/interactions/commands/get_slash_command.ts similarity index 61% rename from src/helpers/commands/get_slash_command.ts rename to src/helpers/interactions/commands/get_slash_command.ts index 846b47bf0..65bebb020 100644 --- a/src/helpers/commands/get_slash_command.ts +++ b/src/helpers/interactions/commands/get_slash_command.ts @@ -1,7 +1,7 @@ -import { applicationId } from "../../bot.ts"; -import { rest } from "../../rest/rest.ts"; -import type { ApplicationCommand } from "../../types/interactions/application_command.ts"; -import { endpoints } from "../../util/constants.ts"; +import { applicationId } from "../../../bot.ts"; +import { rest } from "../../../rest/rest.ts"; +import type { ApplicationCommand } from "../../../types/interactions/commands/application_command.ts"; +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: bigint, guildId?: bigint) { diff --git a/src/helpers/commands/get_slash_command_permission.ts b/src/helpers/interactions/commands/get_slash_command_permission.ts similarity index 57% rename from src/helpers/commands/get_slash_command_permission.ts rename to src/helpers/interactions/commands/get_slash_command_permission.ts index f07c92f18..0c3391d39 100644 --- a/src/helpers/commands/get_slash_command_permission.ts +++ b/src/helpers/interactions/commands/get_slash_command_permission.ts @@ -1,7 +1,7 @@ -import { applicationId } from "../../bot.ts"; -import { rest } from "../../rest/rest.ts"; -import type { GuildApplicationCommandPermissions } from "../../types/interactions/guild_application_command_permissions.ts"; -import { endpoints } from "../../util/constants.ts"; +import { applicationId } from "../../../bot.ts"; +import { rest } from "../../../rest/rest.ts"; +import type { GuildApplicationCommandPermissions } from "../../../types/interactions/commands/guild_application_command_permissions.ts"; +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( diff --git a/src/helpers/commands/get_slash_command_permissions.ts b/src/helpers/interactions/commands/get_slash_command_permissions.ts similarity index 55% rename from src/helpers/commands/get_slash_command_permissions.ts rename to src/helpers/interactions/commands/get_slash_command_permissions.ts index 07c12fb8f..f40dd9576 100644 --- a/src/helpers/commands/get_slash_command_permissions.ts +++ b/src/helpers/interactions/commands/get_slash_command_permissions.ts @@ -1,7 +1,7 @@ -import { applicationId } from "../../bot.ts"; -import { rest } from "../../rest/rest.ts"; -import type { GuildApplicationCommandPermissions } from "../../types/interactions/guild_application_command_permissions.ts"; -import { endpoints } from "../../util/constants.ts"; +import { applicationId } from "../../../bot.ts"; +import { rest } from "../../../rest/rest.ts"; +import type { GuildApplicationCommandPermissions } from "../../../types/interactions/commands/guild_application_command_permissions.ts"; +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: bigint) { diff --git a/src/helpers/commands/get_slash_commands.ts b/src/helpers/interactions/commands/get_slash_commands.ts similarity index 55% rename from src/helpers/commands/get_slash_commands.ts rename to src/helpers/interactions/commands/get_slash_commands.ts index c4f4c8eff..15163ad88 100644 --- a/src/helpers/commands/get_slash_commands.ts +++ b/src/helpers/interactions/commands/get_slash_commands.ts @@ -1,8 +1,8 @@ -import { applicationId } from "../../bot.ts"; -import { rest } from "../../rest/rest.ts"; -import type { ApplicationCommand } from "../../types/interactions/application_command.ts"; -import { Collection } from "../../util/collection.ts"; -import { endpoints } from "../../util/constants.ts"; +import { applicationId } from "../../../bot.ts"; +import { rest } from "../../../rest/rest.ts"; +import type { ApplicationCommand } from "../../../types/interactions/commands/application_command.ts"; +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?: bigint) { diff --git a/src/helpers/commands/upsert_slash_command.ts b/src/helpers/interactions/commands/upsert_slash_command.ts similarity index 52% rename from src/helpers/commands/upsert_slash_command.ts rename to src/helpers/interactions/commands/upsert_slash_command.ts index ed2dc20f9..b6eea60e8 100644 --- a/src/helpers/commands/upsert_slash_command.ts +++ b/src/helpers/interactions/commands/upsert_slash_command.ts @@ -1,9 +1,9 @@ -import { applicationId } from "../../bot.ts"; -import { rest } from "../../rest/rest.ts"; -import type { ApplicationCommand } from "../../types/interactions/application_command.ts"; -import type { EditGlobalApplicationCommand } from "../../types/interactions/edit_global_application_command.ts"; -import { endpoints } from "../../util/constants.ts"; -import { validateSlashCommands } from "../../util/utils.ts"; +import { applicationId } from "../../../bot.ts"; +import { rest } from "../../../rest/rest.ts"; +import type { ApplicationCommand } from "../../../types/interactions/commands/application_command.ts"; +import type { EditGlobalApplicationCommand } from "../../../types/interactions/commands/edit_global_application_command.ts"; +import { endpoints } from "../../../util/constants.ts"; +import { validateSlashCommands } from "../../../util/utils.ts"; /** * Edit an existing slash command. If this command did not exist, it will create it. diff --git a/src/helpers/commands/upsert_slash_commands.ts b/src/helpers/interactions/commands/upsert_slash_commands.ts similarity index 58% rename from src/helpers/commands/upsert_slash_commands.ts rename to src/helpers/interactions/commands/upsert_slash_commands.ts index b49c2cb41..6598910f7 100644 --- a/src/helpers/commands/upsert_slash_commands.ts +++ b/src/helpers/interactions/commands/upsert_slash_commands.ts @@ -1,9 +1,9 @@ -import { applicationId } from "../../bot.ts"; -import { rest } from "../../rest/rest.ts"; -import type { ApplicationCommand } from "../../types/interactions/application_command.ts"; -import type { EditGlobalApplicationCommand } from "../../types/interactions/edit_global_application_command.ts"; -import { endpoints } from "../../util/constants.ts"; -import { validateSlashCommands } from "../../util/utils.ts"; +import { applicationId } from "../../../bot.ts"; +import { rest } from "../../../rest/rest.ts"; +import type { ApplicationCommand } from "../../../types/interactions/commands/application_command.ts"; +import type { EditGlobalApplicationCommand } from "../../../types/interactions/commands/edit_global_application_command.ts"; +import { endpoints } from "../../../util/constants.ts"; +import { validateSlashCommands } from "../../../util/utils.ts"; /** * Bulk edit existing slash commands. If a command does not exist, it will create it. diff --git a/src/helpers/commands/get_original_interaction_response.ts b/src/helpers/interactions/get_original_interaction_response.ts similarity index 100% rename from src/helpers/commands/get_original_interaction_response.ts rename to src/helpers/interactions/get_original_interaction_response.ts diff --git a/src/helpers/commands/send_interaction_response.ts b/src/helpers/interactions/send_interaction_response.ts similarity index 100% rename from src/helpers/commands/send_interaction_response.ts rename to src/helpers/interactions/send_interaction_response.ts diff --git a/src/helpers/invites/get_invite.ts b/src/helpers/invites/get_invite.ts index 8e5b177e4..5d916264c 100644 --- a/src/helpers/invites/get_invite.ts +++ b/src/helpers/invites/get_invite.ts @@ -2,13 +2,13 @@ import { rest } from "../../rest/rest.ts"; import { GetInvite } from "../../types/invites/get_invite.ts"; import type { Invite } from "../../types/invites/invite.ts"; import { endpoints } from "../../util/constants.ts"; -import { camelKeysToSnakeCase } from "../../util/utils.ts"; +import { snakelize } from "../../util/utils.ts"; /** Returns an invite for the given code or throws an error if the invite doesn't exists. */ export async function getInvite(inviteCode: string, options?: GetInvite) { return await rest.runMethod( "get", endpoints.INVITE(inviteCode), - camelKeysToSnakeCase(options ?? {}), + snakelize(options ?? {}), ); } diff --git a/src/helpers/members/ban_member.ts b/src/helpers/members/ban_member.ts index 7af64906c..52424f5ff 100644 --- a/src/helpers/members/ban_member.ts +++ b/src/helpers/members/ban_member.ts @@ -2,7 +2,7 @@ import { rest } from "../../rest/rest.ts"; import type { CreateGuildBan } from "../../types/guilds/create_guild_ban.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; -import { camelKeysToSnakeCase } from "../../util/utils.ts"; +import { snakelize } 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( @@ -15,7 +15,7 @@ export async function ban( return await rest.runMethod( "put", endpoints.GUILD_BAN(guildId, id), - camelKeysToSnakeCase(options), + snakelize(options), ); } diff --git a/src/helpers/members/edit_member.ts b/src/helpers/members/edit_member.ts index e16958e89..efeca3ebd 100644 --- a/src/helpers/members/edit_member.ts +++ b/src/helpers/members/edit_member.ts @@ -1,9 +1,9 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; -import type { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; -import type { ModifyGuildMember } from "../../types/guilds/modify_guild_member.ts"; import { Errors } from "../../types/discordeno/errors.ts"; +import type { ModifyGuildMember } from "../../types/guilds/modify_guild_member.ts"; +import type { GuildMemberWithUser } from "../../types/members/guild_member.ts"; import type { PermissionStrings } from "../../types/permissions/permission_strings.ts"; import { bigintToSnowflake } from "../../util/bigint.ts"; import { endpoints } from "../../util/constants.ts"; @@ -11,7 +11,7 @@ import { requireBotChannelPermissions, requireBotGuildPermissions, } from "../../util/permissions.ts"; -import { camelKeysToSnakeCase } from "../../util/utils.ts"; +import { snakelize } from "../../util/utils.ts"; /** Edit the member */ export async function editMember( @@ -73,7 +73,7 @@ export async function editMember( const result = await rest.runMethod( "patch", endpoints.GUILD_MEMBER(guildId, memberId), - camelKeysToSnakeCase({ + snakelize({ ...options, channelId: options.channelId ? bigintToSnowflake(options.channelId) diff --git a/src/helpers/members/fetch_members.ts b/src/helpers/members/fetch_members.ts index ba94ca136..5f02762dd 100644 --- a/src/helpers/members/fetch_members.ts +++ b/src/helpers/members/fetch_members.ts @@ -1,9 +1,9 @@ import { cache } from "../../cache.ts"; import { DiscordenoMember } from "../../structures/member.ts"; import { DiscordGatewayOpcodes } from "../../types/codes/gateway_opcodes.ts"; -import { DiscordGatewayIntents } from "../../types/gateway/gateway_intents.ts"; -import type { RequestGuildMembers } from "../../types/guilds/request_guild_members.ts"; import { Errors } from "../../types/discordeno/errors.ts"; +import { DiscordGatewayIntents } from "../../types/gateway/gateway_intents.ts"; +import type { RequestGuildMembers } from "../../types/members/request_guild_members.ts"; import { Collection } from "../../util/collection.ts"; import { sendShardMessage } from "../../ws/send_shard_message.ts"; import { ws } from "../../ws/ws.ts"; diff --git a/src/helpers/members/get_member.ts b/src/helpers/members/get_member.ts index b2c17db17..e7887bc65 100644 --- a/src/helpers/members/get_member.ts +++ b/src/helpers/members/get_member.ts @@ -1,7 +1,7 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; -import type { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; +import type { GuildMemberWithUser } from "../../types/members/guild_member.ts"; import { endpoints } from "../../util/constants.ts"; /** Returns a guild member object for the specified user. diff --git a/src/helpers/members/get_members.ts b/src/helpers/members/get_members.ts index 15d8975c4..602657df5 100644 --- a/src/helpers/members/get_members.ts +++ b/src/helpers/members/get_members.ts @@ -3,10 +3,10 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { DiscordenoMember } from "../../structures/member.ts"; import { structures } from "../../structures/mod.ts"; -import { DiscordGatewayIntents } from "../../types/gateway/gateway_intents.ts"; -import type { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; -import type { ListGuildMembers } from "../../types/guilds/list_guild_members.ts"; import { Errors } from "../../types/discordeno/errors.ts"; +import { DiscordGatewayIntents } from "../../types/gateway/gateway_intents.ts"; +import type { GuildMemberWithUser } from "../../types/members/guild_member.ts"; +import type { ListGuildMembers } from "../../types/members/list_guild_members.ts"; import { bigintToSnowflake } from "../../util/bigint.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; diff --git a/src/helpers/members/prune_members.ts b/src/helpers/members/prune_members.ts index 05e950a97..523daa2c1 100644 --- a/src/helpers/members/prune_members.ts +++ b/src/helpers/members/prune_members.ts @@ -1,9 +1,9 @@ import { rest } from "../../rest/rest.ts"; -import type { BeginGuildPrune } from "../../types/guilds/begin_guild_prune.ts"; import { Errors } from "../../types/discordeno/errors.ts"; +import type { BeginGuildPrune } from "../../types/guilds/begin_guild_prune.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; -import { camelKeysToSnakeCase } from "../../util/utils.ts"; +import { snakelize } from "../../util/utils.ts"; /** * Begin a prune operation. Requires the KICK_MEMBERS permission. Returns an object with one 'pruned' key indicating the number of members that were removed in the prune operation. For large guilds it's recommended to set the computePruneCount option to false, forcing 'pruned' to null. Fires multiple Guild Member Remove Gateway events. @@ -22,7 +22,7 @@ export async function pruneMembers( const result = await rest.runMethod<{ pruned: number }>( "post", endpoints.GUILD_PRUNE(guildId), - camelKeysToSnakeCase(options), + snakelize(options), ); return result.pruned; diff --git a/src/helpers/members/search_members.ts b/src/helpers/members/search_members.ts index 6a9d2fede..0c27f884a 100644 --- a/src/helpers/members/search_members.ts +++ b/src/helpers/members/search_members.ts @@ -2,9 +2,9 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { DiscordenoMember } from "../../structures/member.ts"; import { structures } from "../../structures/mod.ts"; -import type { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; -import type { SearchGuildMembers } from "../../types/members/search_guild_members.ts"; import { Errors } from "../../types/discordeno/errors.ts"; +import type { GuildMemberWithUser } from "../../types/members/guild_member.ts"; +import type { SearchGuildMembers } from "../../types/members/search_guild_members.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; diff --git a/src/helpers/messages/send_message.ts b/src/helpers/messages/send_message.ts index 2de5fcb1e..6f21f6912 100644 --- a/src/helpers/messages/send_message.ts +++ b/src/helpers/messages/send_message.ts @@ -2,15 +2,15 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordChannelTypes } from "../../types/channels/channel_types.ts"; +import { Errors } from "../../types/discordeno/errors.ts"; import { DiscordAllowedMentionsTypes } from "../../types/messages/allowed_mentions_types.ts"; import { ButtonStyles } from "../../types/messages/components/button_styles.ts"; import type { CreateMessage } from "../../types/messages/create_message.ts"; import type { Message } from "../../types/messages/message.ts"; -import { Errors } from "../../types/discordeno/errors.ts"; import type { PermissionStrings } from "../../types/permissions/permission_strings.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; -import { camelKeysToSnakeCase } from "../../util/utils.ts"; +import { snakelize } from "../../util/utils.ts"; import { validateLength } from "../../util/validate_length.ts"; import { isActionRow } from "../type_guards/is_action_row.ts"; import { isButton } from "../type_guards/is_button.ts"; @@ -148,7 +148,7 @@ export async function sendMessage( const result = await rest.runMethod( "post", endpoints.CHANNEL_MESSAGES(channelId), - camelKeysToSnakeCase({ + snakelize({ ...content, ...(content.messageReference?.messageId ? { diff --git a/src/helpers/members/edit_bot_profile.ts b/src/helpers/misc/edit_bot_profile.ts similarity index 100% rename from src/helpers/members/edit_bot_profile.ts rename to src/helpers/misc/edit_bot_profile.ts diff --git a/src/helpers/mod.ts b/src/helpers/mod.ts index 903614119..c0a814870 100644 --- a/src/helpers/mod.ts +++ b/src/helpers/mod.ts @@ -13,20 +13,6 @@ import { getPins } from "./channels/get_pins.ts"; import { isChannelSynced } from "./channels/is_channel_synced.ts"; import { startTyping } from "./channels/start_typing.ts"; import { swapChannels } from "./channels/swap_channels.ts"; -import { batchEditSlashCommandPermissions } from "./commands/batch_edit_slash_command_permissions.ts"; -import { createSlashCommand } from "./commands/create_slash_command.ts"; -import { deleteSlashCommand } from "./commands/delete_slash_command.ts"; -import { deleteSlashResponse } from "./commands/delete_slash_response.ts"; -import { editSlashCommandPermissions } from "./commands/edit_slash_command_permissions.ts"; -import { editSlashResponse } from "./commands/edit_slash_response.ts"; -import { getOriginalInteractionResponse } from "./commands/get_original_interaction_response.ts"; -import { getSlashCommand } from "./commands/get_slash_command.ts"; -import { getSlashCommands } from "./commands/get_slash_commands.ts"; -import { getSlashCommandPermission } from "./commands/get_slash_command_permission.ts"; -import { getSlashCommandPermissions } from "./commands/get_slash_command_permissions.ts"; -import { sendInteractionResponse } from "./commands/send_interaction_response.ts"; -import { upsertSlashCommand } from "./commands/upsert_slash_command.ts"; -import { upsertSlashCommands } from "./commands/upsert_slash_commands.ts"; import { addDiscoverySubcategory } from "./discovery/add_discovery_subcategory.ts"; import { editDiscovery } from "./discovery/edit_discovery.ts"; import { getDiscoveryCategories } from "./discovery/get_discovery_categories.ts"; @@ -62,6 +48,20 @@ import { guildSplashURL } from "./guilds/guild_splash_url.ts"; import { leaveGuild } from "./guilds/leave_guild.ts"; import { deleteIntegration } from "./integrations/delete_integration.ts"; import { getIntegrations } from "./integrations/get_integrations.ts"; +import { batchEditSlashCommandPermissions } from "./interactions/commands/batch_edit_slash_command_permissions.ts"; +import { createSlashCommand } from "./interactions/commands/create_slash_command.ts"; +import { deleteSlashCommand } from "./interactions/commands/delete_slash_command.ts"; +import { deleteSlashResponse } from "./interactions/commands/delete_slash_response.ts"; +import { editSlashCommandPermissions } from "./interactions/commands/edit_slash_command_permissions.ts"; +import { editSlashResponse } from "./interactions/commands/edit_slash_response.ts"; +import { getSlashCommand } from "./interactions/commands/get_slash_command.ts"; +import { getSlashCommands } from "./interactions/commands/get_slash_commands.ts"; +import { getSlashCommandPermission } from "./interactions/commands/get_slash_command_permission.ts"; +import { getSlashCommandPermissions } from "./interactions/commands/get_slash_command_permissions.ts"; +import { upsertSlashCommand } from "./interactions/commands/upsert_slash_command.ts"; +import { upsertSlashCommands } from "./interactions/commands/upsert_slash_commands.ts"; +import { getOriginalInteractionResponse } from "./interactions/get_original_interaction_response.ts"; +import { sendInteractionResponse } from "./interactions/send_interaction_response.ts"; import { createInvite } from "./invites/create_invite.ts"; import { deleteInvite } from "./invites/delete_invite.ts"; import { getChannelInvites } from "./invites/get_channel_invites.ts"; @@ -71,7 +71,6 @@ import { avatarURL } from "./members/avatar_url.ts"; import { ban, banMember } from "./members/ban_member.ts"; import { disconnectMember } from "./members/disconnect_member.ts"; import { editBotNickname } from "./members/edit_bot_nickname.ts"; -import { editBotProfile } from "./members/edit_bot_profile.ts"; import { editMember } from "./members/edit_member.ts"; import { fetchMembers } from "./members/fetch_members.ts"; import { getMember } from "./members/get_member.ts"; @@ -96,6 +95,7 @@ import { removeReaction } from "./messages/remove_reaction.ts"; import { removeReactionEmoji } from "./messages/remove_reaction_emoji.ts"; import { sendMessage } from "./messages/send_message.ts"; import { unpin, unpinMessage } from "./messages/unpin_message.ts"; +import { editBotProfile } from "./misc/edit_bot_profile.ts"; import { editBotStatus } from "./misc/edit_bot_status.ts"; import { getGatewayBot } from "./misc/get_gateway_bot.ts"; import { getUser } from "./misc/get_user.ts"; diff --git a/src/rest/run_method.ts b/src/rest/run_method.ts index 53ff1f34b..5593b89d5 100644 --- a/src/rest/run_method.ts +++ b/src/rest/run_method.ts @@ -1,6 +1,6 @@ import { API_VERSION, BASE_URL, IMAGE_BASE_URL } from "../util/constants.ts"; import { loopObject } from "../util/loop_object.ts"; -import { snakeKeysToCamelCase } from "../util/utils.ts"; +import { camelize } from "../util/utils.ts"; import { rest } from "./rest.ts"; // deno-lint-ignore no-explicit-any @@ -62,7 +62,7 @@ export async function runMethod( method, reject, respond: (data: { status: number; body?: string }) => - resolve(snakeKeysToCamelCase(JSON.parse(data.body || "{}"))), + resolve(camelize(JSON.parse(data.body || "{}"))), }, { bucketId, diff --git a/src/structures/guild.ts b/src/structures/guild.ts index 80253cd91..75bc4a09b 100644 --- a/src/structures/guild.ts +++ b/src/structures/guild.ts @@ -12,19 +12,19 @@ import { leaveGuild } from "../helpers/guilds/leave_guild.ts"; import { getInvites } from "../helpers/invites/get_invites.ts"; import { banMember } from "../helpers/members/ban_member.ts"; import { unbanMember } from "../helpers/members/unban_member.ts"; +import type { PresenceUpdate } from "../types/activity/presence_update.ts"; import { GetGuildAuditLog } from "../types/audit_log/get_guild_audit_log.ts"; import type { Emoji } from "../types/emojis/emoji.ts"; import type { CreateGuildBan } from "../types/guilds/create_guild_ban.ts"; import type { Guild } from "../types/guilds/guild.ts"; import { DiscordGuildFeatures } from "../types/guilds/guild_features.ts"; +import type { ModifyGuild } from "../types/guilds/modify_guild.ts"; import type { GuildMember, GuildMemberWithUser, -} from "../types/guilds/guild_member.ts"; -import type { ModifyGuild } from "../types/guilds/modify_guild.ts"; +} from "../types/members/guild_member.ts"; import type { DiscordImageFormat } from "../types/misc/image_format.ts"; import type { DiscordImageSize } from "../types/misc/image_size.ts"; -import type { PresenceUpdate } from "../types/misc/presence_update.ts"; import { snowflakeToBigint } from "../util/bigint.ts"; import { cacheMembers } from "../util/cache_members.ts"; import { Collection } from "../util/collection.ts"; diff --git a/src/structures/member.ts b/src/structures/member.ts index d592dcabd..3ee3ff30d 100644 --- a/src/structures/member.ts +++ b/src/structures/member.ts @@ -8,11 +8,11 @@ import { sendDirectMessage } from "../helpers/members/send_direct_message.ts"; import { addRole } from "../helpers/roles/add_role.ts"; import { removeRole } from "../helpers/roles/remove_role.ts"; import type { CreateGuildBan } from "../types/guilds/create_guild_ban.ts"; +import type { ModifyGuildMember } from "../types/guilds/modify_guild_member.ts"; import type { GuildMember, GuildMemberWithUser, -} from "../types/guilds/guild_member.ts"; -import type { ModifyGuildMember } from "../types/guilds/modify_guild_member.ts"; +} from "../types/members/guild_member.ts"; import type { CreateMessage } from "../types/messages/create_message.ts"; import type { DiscordImageFormat } from "../types/misc/image_format.ts"; import type { DiscordImageSize } from "../types/misc/image_size.ts"; diff --git a/src/structures/message.ts b/src/structures/message.ts index af8832351..0525d254f 100644 --- a/src/structures/message.ts +++ b/src/structures/message.ts @@ -10,7 +10,7 @@ import { removeAllReactions } from "../helpers/messages/remove_all_reactions.ts" import { removeReaction } from "../helpers/messages/remove_reaction.ts"; import { removeReactionEmoji } from "../helpers/messages/remove_reaction_emoji.ts"; import { sendMessage } from "../helpers/messages/send_message.ts"; -import type { GuildMember } from "../types/guilds/guild_member.ts"; +import type { GuildMember } from "../types/members/guild_member.ts"; import type { CreateMessage } from "../types/messages/create_message.ts"; import type { EditMessage } from "../types/messages/edit_message.ts"; import type { Message } from "../types/messages/message.ts"; diff --git a/src/structures/voice_state.ts b/src/structures/voice_state.ts index 48a7f906b..737b4e335 100644 --- a/src/structures/voice_state.ts +++ b/src/structures/voice_state.ts @@ -1,6 +1,6 @@ import { eventHandlers } from "../bot.ts"; import { cache } from "../cache.ts"; -import type { GuildMember } from "../types/guilds/guild_member.ts"; +import type { GuildMember } from "../types/members/guild_member.ts"; import type { VoiceState } from "../types/voice/voice_state.ts"; import { snowflakeToBigint } from "../util/bigint.ts"; import { createNewProp } from "../util/utils.ts"; diff --git a/src/types/misc/activity.ts b/src/types/activity/activity.ts similarity index 100% rename from src/types/misc/activity.ts rename to src/types/activity/activity.ts diff --git a/src/types/misc/activity_assets.ts b/src/types/activity/activity_assets.ts similarity index 100% rename from src/types/misc/activity_assets.ts rename to src/types/activity/activity_assets.ts diff --git a/src/types/misc/activity_button.ts b/src/types/activity/activity_button.ts similarity index 100% rename from src/types/misc/activity_button.ts rename to src/types/activity/activity_button.ts diff --git a/src/types/misc/activity_emoji.ts b/src/types/activity/activity_emoji.ts similarity index 100% rename from src/types/misc/activity_emoji.ts rename to src/types/activity/activity_emoji.ts diff --git a/src/types/misc/activity_flags.ts b/src/types/activity/activity_flags.ts similarity index 100% rename from src/types/misc/activity_flags.ts rename to src/types/activity/activity_flags.ts diff --git a/src/types/misc/activity_party.ts b/src/types/activity/activity_party.ts similarity index 100% rename from src/types/misc/activity_party.ts rename to src/types/activity/activity_party.ts diff --git a/src/types/misc/activity_secrets.ts b/src/types/activity/activity_secrets.ts similarity index 100% rename from src/types/misc/activity_secrets.ts rename to src/types/activity/activity_secrets.ts diff --git a/src/types/misc/activity_timestamps.ts b/src/types/activity/activity_timestamps.ts similarity index 100% rename from src/types/misc/activity_timestamps.ts rename to src/types/activity/activity_timestamps.ts diff --git a/src/types/misc/activity_types.ts b/src/types/activity/activity_types.ts similarity index 100% rename from src/types/misc/activity_types.ts rename to src/types/activity/activity_types.ts diff --git a/src/types/misc/client_status.ts b/src/types/activity/client_status.ts similarity index 100% rename from src/types/misc/client_status.ts rename to src/types/activity/client_status.ts diff --git a/src/types/misc/presence_update.ts b/src/types/activity/presence_update.ts similarity index 100% rename from src/types/misc/presence_update.ts rename to src/types/activity/presence_update.ts diff --git a/src/types/audit_log/audit_log.ts b/src/types/audit_log/audit_log.ts index 41ccff42b..578a54d73 100644 --- a/src/types/audit_log/audit_log.ts +++ b/src/types/audit_log/audit_log.ts @@ -1,4 +1,4 @@ -import { Integration } from "../integration/integration.ts"; +import { Integration } from "../integrations/integration.ts"; import { User } from "../users/user.ts"; import { Webhook } from "../webhooks/webhook.ts"; import { AuditLogEntry } from "./audit_log_entry.ts"; diff --git a/src/types/discordeno/create_slash_command.ts b/src/types/discordeno/create_slash_command.ts index 969ac33fc..b0008fca1 100644 --- a/src/types/discordeno/create_slash_command.ts +++ b/src/types/discordeno/create_slash_command.ts @@ -1,4 +1,4 @@ -import { CreateGlobalApplicationCommand } from "../interactions/create_global_application_command.ts"; +import { CreateGlobalApplicationCommand } from "../interactions/commands/create_global_application_command.ts"; export interface DiscordenoCreateApplicationCommand extends CreateGlobalApplicationCommand { diff --git a/src/types/discordeno/eventHandlers.ts b/src/types/discordeno/eventHandlers.ts index 5386935ab..c456c91ee 100644 --- a/src/types/discordeno/eventHandlers.ts +++ b/src/types/discordeno/eventHandlers.ts @@ -6,8 +6,8 @@ import { DiscordenoRole } from "../../structures/role.ts"; import { Collection } from "../../util/collection.ts"; import { ThreadMember } from "../channels/threads/thread_member.ts"; import { ThreadMembersUpdate } from "../channels/threads/thread_members_update.ts"; -import { IntegrationCreateUpdate } from "../integration/integration_create_update.ts"; -import { ApplicationCommandCreateUpdateDelete } from "../interactions/application_command_create_update_delete.ts"; +import { IntegrationCreateUpdate } from "../integrations/integration_create_update.ts"; +import { ApplicationCommandCreateUpdateDelete } from "../interactions/commands/application_command_create_update_delete.ts"; import { DiscordGatewayPayload, Emoji, diff --git a/src/types/gateway/status_update.ts b/src/types/gateway/status_update.ts index 27f65b9ca..12092cbdd 100644 --- a/src/types/gateway/status_update.ts +++ b/src/types/gateway/status_update.ts @@ -1,4 +1,4 @@ -import { Activity } from "../misc/activity.ts"; +import { Activity } from "../activity/activity.ts"; import { DiscordStatusTypes } from "./status_types.ts"; /** https://discord.com/developers/docs/topics/gateway#update-status */ diff --git a/src/types/guilds/guild.ts b/src/types/guilds/guild.ts index a6b050529..14e9676fe 100644 --- a/src/types/guilds/guild.ts +++ b/src/types/guilds/guild.ts @@ -1,12 +1,12 @@ +import { PresenceUpdate } from "../activity/presence_update.ts"; import { Channel } from "../channels/channel.ts"; import { Emoji } from "../emojis/emoji.ts"; -import { PresenceUpdate } from "../misc/presence_update.ts"; +import { GuildMember } from "../members/guild_member.ts"; import { Role } from "../permissions/role.ts"; import { VoiceState } from "../voice/voice_state.ts"; import { DiscordDefaultMessageNotificationLevels } from "./default_message_notification_levels.ts"; import { DiscordExplicitContentFilterLevels } from "./explicit_content_filter_levels.ts"; import { DiscordGuildFeatures } from "./guild_features.ts"; -import { GuildMember } from "./guild_member.ts"; import { DiscordMfaLevels } from "./mfa_levels.ts"; import { DiscordPremiumTiers } from "./premium_tiers.ts"; import { DiscordSystemChannelFlags } from "./system_channel_flags.ts"; diff --git a/src/types/integration/guild_integrations_update.ts b/src/types/integrations/guild_integrations_update.ts similarity index 100% rename from src/types/integration/guild_integrations_update.ts rename to src/types/integrations/guild_integrations_update.ts diff --git a/src/types/integration/integration.ts b/src/types/integrations/integration.ts similarity index 100% rename from src/types/integration/integration.ts rename to src/types/integrations/integration.ts diff --git a/src/types/integration/integration_account.ts b/src/types/integrations/integration_account.ts similarity index 100% rename from src/types/integration/integration_account.ts rename to src/types/integrations/integration_account.ts diff --git a/src/types/integration/integration_application.ts b/src/types/integrations/integration_application.ts similarity index 100% rename from src/types/integration/integration_application.ts rename to src/types/integrations/integration_application.ts diff --git a/src/types/integration/integration_create_update.ts b/src/types/integrations/integration_create_update.ts similarity index 100% rename from src/types/integration/integration_create_update.ts rename to src/types/integrations/integration_create_update.ts diff --git a/src/types/integration/integration_delete.ts b/src/types/integrations/integration_delete.ts similarity index 100% rename from src/types/integration/integration_delete.ts rename to src/types/integrations/integration_delete.ts diff --git a/src/types/integration/integration_expire_behaviors.ts b/src/types/integrations/integration_expire_behaviors.ts similarity index 100% rename from src/types/integration/integration_expire_behaviors.ts rename to src/types/integrations/integration_expire_behaviors.ts diff --git a/src/types/interactions/application_command.ts b/src/types/interactions/commands/application_command.ts similarity index 100% rename from src/types/interactions/application_command.ts rename to src/types/interactions/commands/application_command.ts diff --git a/src/types/interactions/application_command_callback_data.ts b/src/types/interactions/commands/application_command_callback_data.ts similarity index 80% rename from src/types/interactions/application_command_callback_data.ts rename to src/types/interactions/commands/application_command_callback_data.ts index 5844862d2..6857815af 100644 --- a/src/types/interactions/application_command_callback_data.ts +++ b/src/types/interactions/commands/application_command_callback_data.ts @@ -1,5 +1,5 @@ -import { Embed } from "../embeds/embed.ts"; -import { AllowedMentions } from "../messages/allowed_mentions.ts"; +import { Embed } from "../../embeds/embed.ts"; +import { AllowedMentions } from "../../messages/allowed_mentions.ts"; /** https://discord.com/developers/docs/interactions/slash-commands#interaction-response-interactionapplicationcommandcallbackdata */ export interface InteractionApplicationCommandCallbackData { diff --git a/src/types/interactions/application_command_create_update_delete.ts b/src/types/interactions/commands/application_command_create_update_delete.ts similarity index 100% rename from src/types/interactions/application_command_create_update_delete.ts rename to src/types/interactions/commands/application_command_create_update_delete.ts diff --git a/src/types/interactions/application_command_interaction_data.ts b/src/types/interactions/commands/application_command_interaction_data.ts similarity index 100% rename from src/types/interactions/application_command_interaction_data.ts rename to src/types/interactions/commands/application_command_interaction_data.ts diff --git a/src/types/interactions/application_command_interaction_data_option.ts b/src/types/interactions/commands/application_command_interaction_data_option.ts similarity index 100% rename from src/types/interactions/application_command_interaction_data_option.ts rename to src/types/interactions/commands/application_command_interaction_data_option.ts diff --git a/src/types/interactions/application_command_interaction_data_resolved.ts b/src/types/interactions/commands/application_command_interaction_data_resolved.ts similarity index 68% rename from src/types/interactions/application_command_interaction_data_resolved.ts rename to src/types/interactions/commands/application_command_interaction_data_resolved.ts index db967bb97..976129ece 100644 --- a/src/types/interactions/application_command_interaction_data_resolved.ts +++ b/src/types/interactions/commands/application_command_interaction_data_resolved.ts @@ -1,7 +1,7 @@ -import { Channel } from "../channels/channel.ts"; -import { GuildMember } from "../guilds/guild_member.ts"; -import { Role } from "../permissions/role.ts"; -import { User } from "../users/user.ts"; +import { Channel } from "../../channels/channel.ts"; +import { GuildMember } from "../../members/guild_member.ts"; +import { Role } from "../../permissions/role.ts"; +import { User } from "../../users/user.ts"; export interface ApplicationCommandInteractionDataResolved { /** The Ids and User objects */ diff --git a/src/types/interactions/application_command_option.ts b/src/types/interactions/commands/application_command_option.ts similarity index 100% rename from src/types/interactions/application_command_option.ts rename to src/types/interactions/commands/application_command_option.ts diff --git a/src/types/interactions/application_command_option_choice.ts b/src/types/interactions/commands/application_command_option_choice.ts similarity index 100% rename from src/types/interactions/application_command_option_choice.ts rename to src/types/interactions/commands/application_command_option_choice.ts diff --git a/src/types/interactions/application_command_option_types.ts b/src/types/interactions/commands/application_command_option_types.ts similarity index 100% rename from src/types/interactions/application_command_option_types.ts rename to src/types/interactions/commands/application_command_option_types.ts diff --git a/src/types/interactions/application_command_permission_types.ts b/src/types/interactions/commands/application_command_permission_types.ts similarity index 100% rename from src/types/interactions/application_command_permission_types.ts rename to src/types/interactions/commands/application_command_permission_types.ts diff --git a/src/types/interactions/application_command_permissions.ts b/src/types/interactions/commands/application_command_permissions.ts similarity index 100% rename from src/types/interactions/application_command_permissions.ts rename to src/types/interactions/commands/application_command_permissions.ts diff --git a/src/types/interactions/create_global_application_command.ts b/src/types/interactions/commands/create_global_application_command.ts similarity index 100% rename from src/types/interactions/create_global_application_command.ts rename to src/types/interactions/commands/create_global_application_command.ts diff --git a/src/types/interactions/create_guild_application_command.ts b/src/types/interactions/commands/create_guild_application_command.ts similarity index 100% rename from src/types/interactions/create_guild_application_command.ts rename to src/types/interactions/commands/create_guild_application_command.ts diff --git a/src/types/interactions/edit_global_application_command.ts b/src/types/interactions/commands/edit_global_application_command.ts similarity index 100% rename from src/types/interactions/edit_global_application_command.ts rename to src/types/interactions/commands/edit_global_application_command.ts diff --git a/src/types/interactions/edit_guild_application_command.ts b/src/types/interactions/commands/edit_guild_application_command.ts similarity index 100% rename from src/types/interactions/edit_guild_application_command.ts rename to src/types/interactions/commands/edit_guild_application_command.ts diff --git a/src/types/interactions/guild_application_command_permissions.ts b/src/types/interactions/commands/guild_application_command_permissions.ts similarity index 100% rename from src/types/interactions/guild_application_command_permissions.ts rename to src/types/interactions/commands/guild_application_command_permissions.ts diff --git a/src/types/interactions/interaction.ts b/src/types/interactions/interaction.ts index 975238ac8..adf4ab521 100644 --- a/src/types/interactions/interaction.ts +++ b/src/types/interactions/interaction.ts @@ -1,7 +1,7 @@ -import { GuildMemberWithUser } from "../guilds/guild_member.ts"; +import { GuildMemberWithUser } from "../members/guild_member.ts"; import { Message } from "../messages/message.ts"; import { User } from "../users/user.ts"; -import { ApplicationCommandInteractionData } from "./application_command_interaction_data.ts"; +import { ApplicationCommandInteractionData } from "./commands/application_command_interaction_data.ts"; import { DiscordInteractionTypes } from "./interaction_types.ts"; /** https://discord.com/developers/docs/interactions/slash-commands#interaction */ diff --git a/src/types/interactions/interaction_guild_member.ts b/src/types/interactions/interaction_guild_member.ts index fb9cebc78..d7ab18d57 100644 --- a/src/types/interactions/interaction_guild_member.ts +++ b/src/types/interactions/interaction_guild_member.ts @@ -1,4 +1,4 @@ -import { GuildMember } from "../guilds/guild_member.ts"; +import { GuildMember } from "../members/guild_member.ts"; /** https://discord.com/developers/docs/resources/guild#guild-member-object */ export interface InteractionGuildMember extends GuildMember { diff --git a/src/types/interactions/interaction_response.ts b/src/types/interactions/interaction_response.ts index 5460cbb4e..4b0ac1b8c 100644 --- a/src/types/interactions/interaction_response.ts +++ b/src/types/interactions/interaction_response.ts @@ -1,4 +1,4 @@ -import { InteractionApplicationCommandCallbackData } from "./application_command_callback_data.ts"; +import { InteractionApplicationCommandCallbackData } from "./commands/application_command_callback_data.ts"; import { DiscordInteractionResponseTypes } from "./interaction_response_types.ts"; /** https://discord.com/developers/docs/interactions/slash-commands#interaction-response */ diff --git a/src/types/guilds/guild_member.ts b/src/types/members/guild_member.ts similarity index 100% rename from src/types/guilds/guild_member.ts rename to src/types/members/guild_member.ts diff --git a/src/types/members/guild_member_add.ts b/src/types/members/guild_member_add.ts index a39685228..f5b8bd9ee 100644 --- a/src/types/members/guild_member_add.ts +++ b/src/types/members/guild_member_add.ts @@ -1,4 +1,4 @@ -import { GuildMemberWithUser } from "../guilds/guild_member.ts"; +import { GuildMemberWithUser } from "../members/guild_member.ts"; /** https://discord.com/developers/docs/topics/gateway#guild-member-add */ export interface GuildMemberAdd extends GuildMemberWithUser { diff --git a/src/types/members/guild_members_chunk.ts b/src/types/members/guild_members_chunk.ts index a4b801f33..0e0cd7a32 100644 --- a/src/types/members/guild_members_chunk.ts +++ b/src/types/members/guild_members_chunk.ts @@ -1,5 +1,5 @@ -import { GuildMemberWithUser } from "../guilds/guild_member.ts"; -import { PresenceUpdate } from "../misc/presence_update.ts"; +import { PresenceUpdate } from "../activity/presence_update.ts"; +import { GuildMemberWithUser } from "../members/guild_member.ts"; /** https://discord.com/developers/docs/topics/gateway#guild-members-chunk */ export interface GuildMembersChunk { diff --git a/src/types/guilds/list_guild_members.ts b/src/types/members/list_guild_members.ts similarity index 100% rename from src/types/guilds/list_guild_members.ts rename to src/types/members/list_guild_members.ts diff --git a/src/types/guilds/modify_current_user_nick.ts b/src/types/members/modify_current_user_nick.ts similarity index 100% rename from src/types/guilds/modify_current_user_nick.ts rename to src/types/members/modify_current_user_nick.ts diff --git a/src/types/guilds/request_guild_members.ts b/src/types/members/request_guild_members.ts similarity index 100% rename from src/types/guilds/request_guild_members.ts rename to src/types/members/request_guild_members.ts diff --git a/src/types/messages/message.ts b/src/types/messages/message.ts index 9ae7b8879..72934232f 100644 --- a/src/types/messages/message.ts +++ b/src/types/messages/message.ts @@ -2,8 +2,8 @@ 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"; +import { GuildMember } from "../members/guild_member.ts"; import { Application } from "../oauth2/application.ts"; import { User } from "../users/user.ts"; import { Attachment } from "./attachment.ts"; diff --git a/src/types/messages/message_reaction_add.ts b/src/types/messages/message_reaction_add.ts index ef3709af3..c0846e858 100644 --- a/src/types/messages/message_reaction_add.ts +++ b/src/types/messages/message_reaction_add.ts @@ -1,5 +1,5 @@ import { Emoji } from "../emojis/emoji.ts"; -import { GuildMemberWithUser } from "../guilds/guild_member.ts"; +import { GuildMemberWithUser } from "../members/guild_member.ts"; /** https://discord.com/developers/docs/topics/gateway#message-reaction-add */ export interface MessageReactionAdd { diff --git a/src/types/misc/typing_start.ts b/src/types/misc/typing_start.ts index 4c23b7d2b..748de7b3f 100644 --- a/src/types/misc/typing_start.ts +++ b/src/types/misc/typing_start.ts @@ -1,4 +1,4 @@ -import { GuildMember } from "../guilds/guild_member.ts"; +import { GuildMember } from "../members/guild_member.ts"; /** https://discord.com/developers/docs/topics/gateway#typing-start */ export interface TypingStart { diff --git a/src/types/mod.ts b/src/types/mod.ts index 61ed15cc6..2bd4c0e92 100644 --- a/src/types/mod.ts +++ b/src/types/mod.ts @@ -1,3 +1,14 @@ +export * from "./activity/activity.ts"; +export * from "./activity/activity_assets.ts"; +export * from "./activity/activity_button.ts"; +export * from "./activity/activity_emoji.ts"; +export * from "./activity/activity_flags.ts"; +export * from "./activity/activity_party.ts"; +export * from "./activity/activity_secrets.ts"; +export * from "./activity/activity_timestamps.ts"; +export * from "./activity/activity_types.ts"; +export * from "./activity/client_status.ts"; +export * from "./activity/presence_update.ts"; export * from "./audit_log/audit_log.ts"; export * from "./audit_log/audit_log_change.ts"; export * from "./audit_log/audit_log_change_value.ts"; @@ -13,6 +24,14 @@ export * from "./channels/followed_channel.ts"; export * from "./channels/modify_channel.ts"; export * from "./channels/overwrite.ts"; export * from "./channels/overwrite_types.ts"; +export * from "./channels/threads/list_active_threads.ts"; +export * from "./channels/threads/list_public_archived_threads.ts"; +export * from "./channels/threads/modify_thread.ts"; +export * from "./channels/threads/start_thread.ts"; +export * from "./channels/threads/thread_list_sync.ts"; +export * from "./channels/threads/thread_member.ts"; +export * from "./channels/threads/thread_members_update.ts"; +export * from "./channels/threads/thread_metadata.ts"; export * from "./channels/video_quality_modes.ts"; export * from "./codes/gateway_close_event_codes.ts"; export * from "./codes/gateway_opcodes.ts"; @@ -25,10 +44,19 @@ export * from "./codes/voice_opcodes.ts"; export * from "./discordeno/create_slash_command.ts"; export * from "./discordeno/debug_arg.ts"; export * from "./discordeno/edit_webhook_message.ts"; +export * from "./discordeno/errors.ts"; export * from "./discordeno/eventHandlers.ts"; +export * from "./discordeno/file_content.ts"; export * from "./discordeno/guild_member.ts"; export * from "./discordeno/guild_update_change.ts"; export * from "./discordeno/interaction_response.ts"; +export * from "./discovery/add_guild_discovery_subcategory.ts"; +export * from "./discovery/discovery_category.ts"; +export * from "./discovery/discovery_metadata.ts"; +export * from "./discovery/discovery_name.ts"; +export * from "./discovery/modify_guild_discovery_metadata.ts"; +export * from "./discovery/validate_discovery_search_term.ts"; +export * from "./discovery/validate_discovery_search_term_params.ts"; export * from "./embeds/embed.ts"; export * from "./embeds/embed_author.ts"; export * from "./embeds/embed_field.ts"; @@ -70,15 +98,13 @@ export * from "./guilds/guild.ts"; export * from "./guilds/guild_ban_add_remove.ts"; export * from "./guilds/guild_ban_remove.ts"; export * from "./guilds/guild_features.ts"; -export * from "./guilds/guild_member.ts"; export * from "./guilds/guild_preview.ts"; export * from "./guilds/guild_role_create.ts"; export * from "./guilds/guild_role_delete.ts"; export * from "./guilds/guild_role_update.ts"; export * from "./guilds/guild_widget.ts"; -export * from "./guilds/list_guild_members.ts"; +export * from "./guilds/guild_widget_details.ts"; export * from "./guilds/mfa_levels.ts"; -export * from "./guilds/modify_current_user_nick.ts"; export * from "./guilds/modify_guild.ts"; export * from "./guilds/modify_guild_channel_position.ts"; export * from "./guilds/modify_guild_member.ts"; @@ -86,32 +112,36 @@ export * from "./guilds/modify_guild_role.ts"; export * from "./guilds/modify_guild_role_positions.ts"; export * from "./guilds/modify_guild_welcome_screen.ts"; export * from "./guilds/premium_tiers.ts"; -export * from "./guilds/request_guild_members.ts"; export * from "./guilds/system_channel_flags.ts"; export * from "./guilds/unavailable_guild.ts"; +export * from "./guilds/update_others_voice_state.ts"; +export * from "./guilds/update_self_voice_state.ts"; export * from "./guilds/verification_levels.ts"; export * from "./guilds/welcome_screen.ts"; export * from "./guilds/welcome_screen_channel.ts"; -export * from "./integration/guild_integrations_update.ts"; -export * from "./integration/integration.ts"; -export * from "./integration/integration_account.ts"; -export * from "./integration/integration_application.ts"; -export * from "./integration/integration_create_update.ts"; -export * from "./integration/integration_delete.ts"; -export * from "./integration/integration_expire_behaviors.ts"; -export * from "./interactions/application_command.ts"; -export * from "./interactions/application_command_callback_data.ts"; -export * from "./interactions/application_command_create_update_delete.ts"; -export * from "./interactions/application_command_interaction_data.ts"; -export * from "./interactions/application_command_interaction_data_option.ts"; -export * from "./interactions/application_command_interaction_data_resolved.ts"; -export * from "./interactions/application_command_option.ts"; -export * from "./interactions/application_command_option_choice.ts"; -export * from "./interactions/application_command_option_types.ts"; -export * from "./interactions/create_global_application_command.ts"; -export * from "./interactions/create_guild_application_command.ts"; -export * from "./interactions/edit_global_application_command.ts"; -export * from "./interactions/edit_guild_application_command.ts"; +export * from "./integrations/guild_integrations_update.ts"; +export * from "./integrations/integration.ts"; +export * from "./integrations/integration_account.ts"; +export * from "./integrations/integration_application.ts"; +export * from "./integrations/integration_create_update.ts"; +export * from "./integrations/integration_delete.ts"; +export * from "./integrations/integration_expire_behaviors.ts"; +export * from "./interactions/commands/application_command.ts"; +export * from "./interactions/commands/application_command_callback_data.ts"; +export * from "./interactions/commands/application_command_create_update_delete.ts"; +export * from "./interactions/commands/application_command_interaction_data.ts"; +export * from "./interactions/commands/application_command_interaction_data_option.ts"; +export * from "./interactions/commands/application_command_interaction_data_resolved.ts"; +export * from "./interactions/commands/application_command_option.ts"; +export * from "./interactions/commands/application_command_option_choice.ts"; +export * from "./interactions/commands/application_command_option_types.ts"; +export * from "./interactions/commands/application_command_permissions.ts"; +export * from "./interactions/commands/application_command_permission_types.ts"; +export * from "./interactions/commands/create_global_application_command.ts"; +export * from "./interactions/commands/create_guild_application_command.ts"; +export * from "./interactions/commands/edit_global_application_command.ts"; +export * from "./interactions/commands/edit_guild_application_command.ts"; +export * from "./interactions/commands/guild_application_command_permissions.ts"; export * from "./interactions/interaction.ts"; export * from "./interactions/interaction_guild_member.ts"; export * from "./interactions/interaction_response.ts"; @@ -126,19 +156,23 @@ export * from "./invites/invite_delete.ts"; export * from "./invites/invite_metadata.ts"; export * from "./invites/invite_target_types.ts"; export * from "./invites/target_types.ts"; +export * from "./members/guild_member.ts"; export * from "./members/guild_members_chunk.ts"; export * from "./members/guild_member_add.ts"; export * from "./members/guild_member_remove.ts"; export * from "./members/guild_member_update.ts"; +export * from "./members/list_guild_members.ts"; +export * from "./members/modify_current_user_nick.ts"; +export * from "./members/request_guild_members.ts"; export * from "./members/search_guild_members.ts"; -export * from "./messages/components/action_row.ts"; -export * from "./messages/components/button_component.ts"; -export * from "./messages/components/button_styles.ts"; -export * from "./messages/components/message_component_types.ts"; -export * from "./messages/components/message_components.ts"; export * from "./messages/allowed_mentions.ts"; export * from "./messages/allowed_mentions_types.ts"; export * from "./messages/attachment.ts"; +export * from "./messages/components/action_row.ts"; +export * from "./messages/components/button_component.ts"; +export * from "./messages/components/button_styles.ts"; +export * from "./messages/components/message_components.ts"; +export * from "./messages/components/message_component_types.ts"; export * from "./messages/create_message.ts"; export * from "./messages/edit_message.ts"; export * from "./messages/get_messages.ts"; @@ -158,21 +192,8 @@ export * from "./messages/message_sticker.ts"; export * from "./messages/message_sticker_format_types.ts"; export * from "./messages/message_types.ts"; export * from "./messages/reaction.ts"; -export * from "./misc/activity.ts"; -export * from "./misc/activity_assets.ts"; -export * from "./misc/activity_button.ts"; -export * from "./misc/activity_emoji.ts"; -export * from "./misc/activity_flags.ts"; -export * from "./misc/activity_party.ts"; -export * from "./misc/activity_secrets.ts"; -export * from "./misc/activity_timestamps.ts"; -export * from "./misc/activity_types.ts"; -export * from "./misc/client_status.ts"; -export * from "./discordeno/errors.ts"; -export * from "./discordeno/file_content.ts"; export * from "./misc/image_format.ts"; export * from "./misc/image_size.ts"; -export * from "./misc/presence_update.ts"; export * from "./misc/typing_start.ts"; export * from "./mod.ts"; export * from "./oauth2/application.ts"; diff --git a/src/types/users/connection.ts b/src/types/users/connection.ts index 4d3f64f26..69e8de021 100644 --- a/src/types/users/connection.ts +++ b/src/types/users/connection.ts @@ -1,4 +1,4 @@ -import { Integration } from "../integration/integration.ts"; +import { Integration } from "../integrations/integration.ts"; import { DiscordVisibilityTypes } from "./visibility_types.ts"; /** https://discord.com/developers/docs/resources/user#connection-objecthttps://discord.com/developers/docs/resources/user#user-object-premium-types */ diff --git a/src/types/voice/voice_state.ts b/src/types/voice/voice_state.ts index 8aa38f68b..156e15ad4 100644 --- a/src/types/voice/voice_state.ts +++ b/src/types/voice/voice_state.ts @@ -1,4 +1,4 @@ -import { GuildMemberWithUser } from "../guilds/guild_member.ts"; +import { GuildMemberWithUser } from "../members/guild_member.ts"; /** https://discord.com/developers/docs/resources/voice#voice-state-object-voice-state-structure */ export interface VoiceState { diff --git a/src/util/cache_members.ts b/src/util/cache_members.ts index c2b9b81d6..86e27d15a 100644 --- a/src/util/cache_members.ts +++ b/src/util/cache_members.ts @@ -1,7 +1,7 @@ import { eventHandlers } from "../bot.ts"; import { cacheHandlers } from "../cache.ts"; import { structures } from "../structures/mod.ts"; -import { GuildMemberWithUser } from "../types/guilds/guild_member.ts"; +import { GuildMemberWithUser } from "../types/members/guild_member.ts"; const guildMemberQueue = new Map< bigint, diff --git a/src/util/utils.ts b/src/util/utils.ts index 8ae7511f9..d936d291b 100644 --- a/src/util/utils.ts +++ b/src/util/utils.ts @@ -1,11 +1,11 @@ import { encode } from "../../deps.ts"; import { eventHandlers } from "../bot.ts"; -import type { ApplicationCommandOption } from "../types/interactions/application_command_option.ts"; -import type { ApplicationCommandOptionChoice } from "../types/interactions/application_command_option_choice.ts"; -import { DiscordApplicationCommandOptionTypes } from "../types/interactions/application_command_option_types.ts"; -import type { CreateGlobalApplicationCommand } from "../types/interactions/create_global_application_command.ts"; -import type { EditGlobalApplicationCommand } from "../types/interactions/edit_global_application_command.ts"; import { Errors } from "../types/discordeno/errors.ts"; +import type { ApplicationCommandOption } from "../types/interactions/commands/application_command_option.ts"; +import type { ApplicationCommandOptionChoice } from "../types/interactions/commands/application_command_option_choice.ts"; +import { DiscordApplicationCommandOptionTypes } from "../types/interactions/commands/application_command_option_types.ts"; +import type { CreateGlobalApplicationCommand } from "../types/interactions/commands/create_global_application_command.ts"; +import type { EditGlobalApplicationCommand } from "../types/interactions/commands/edit_global_application_command.ts"; import type { DiscordImageFormat } from "../types/misc/image_format.ts"; import type { DiscordImageSize } from "../types/misc/image_size.ts"; import { SLASH_COMMANDS_NAME_REGEX } from "./constants.ts"; @@ -61,7 +61,7 @@ function isConvertableObject(obj: unknown) { ); } -export function camelKeysToSnakeCase( +export function snakelize( // deno-lint-ignore no-explicit-any obj: Record | Record[], ): T { @@ -72,9 +72,9 @@ export function camelKeysToSnakeCase( Object.keys(obj).forEach((key) => { eventHandlers.debug?.( "loop", - `Running forEach loop in camelKeysToSnakeCase function.`, + `Running forEach loop in snakelize function.`, ); - convertedObject[camelToSnakeCase(key)] = camelKeysToSnakeCase( + convertedObject[camelToSnakeCase(key)] = snakelize( // deno-lint-ignore no-explicit-any (obj as Record)[key], ); @@ -82,13 +82,13 @@ export function camelKeysToSnakeCase( return convertedObject as T; } else if (Array.isArray(obj)) { - obj = obj.map((element) => camelKeysToSnakeCase(element)); + obj = obj.map((element) => snakelize(element)); } return obj as T; } -export function snakeKeysToCamelCase( +export function camelize( // deno-lint-ignore no-explicit-any obj: Record | Record[], ): T { @@ -99,9 +99,9 @@ export function snakeKeysToCamelCase( Object.keys(obj).forEach((key) => { eventHandlers.debug?.( "loop", - `Running forEach loop in snakeKeysToCamelCase function.`, + `Running forEach loop in camelize function.`, ); - convertedObject[snakeToCamelCase(key)] = snakeKeysToCamelCase( + convertedObject[snakeToCamelCase(key)] = camelize( // deno-lint-ignore no-explicit-any (obj as Record)[key], ); @@ -109,7 +109,7 @@ export function snakeKeysToCamelCase( return convertedObject as T; } else if (Array.isArray(obj)) { - obj = obj.map((element) => snakeKeysToCamelCase(element)); + obj = obj.map((element) => camelize(element)); } return obj as T; diff --git a/src/ws/handle_on_message.ts b/src/ws/handle_on_message.ts index 2dee79979..33335c8da 100644 --- a/src/ws/handle_on_message.ts +++ b/src/ws/handle_on_message.ts @@ -4,7 +4,7 @@ import { DiscordGatewayOpcodes } from "../types/codes/gateway_opcodes.ts"; import type { DiscordGatewayPayload } from "../types/gateway/gateway_payload.ts"; import type { DiscordHello } from "../types/gateway/hello.ts"; import type { DiscordReady } from "../types/gateway/ready.ts"; -import { delay, snakeKeysToCamelCase } from "../util/utils.ts"; +import { camelize, delay } from "../util/utils.ts"; import { decompressWith } from "./deps.ts"; import { identify } from "./identify.ts"; import { resume } from "./resume.ts"; @@ -128,7 +128,7 @@ export async function handleOnMessage(message: any, shardId: number) { if (!messageData.t) return; return handlers[messageData.t]?.( - snakeKeysToCamelCase(messageData), + camelize(messageData), shardId, ); } diff --git a/src/ws/start_gateway.ts b/src/ws/start_gateway.ts index 11062276f..281611bcd 100644 --- a/src/ws/start_gateway.ts +++ b/src/ws/start_gateway.ts @@ -1,6 +1,6 @@ import { DiscordGatewayIntents } from "../types/gateway/gateway_intents.ts"; import type { GetGatewayBot } from "../types/gateway/get_gateway_bot.ts"; -import { snakeKeysToCamelCase } from "../util/utils.ts"; +import { camelize } from "../util/utils.ts"; import { StartGatewayOptions } from "./start_gateway_options.ts"; import { ws } from "./ws.ts"; @@ -33,7 +33,7 @@ export async function startGateway(options: StartGatewayOptions) { 0, ); - ws.botGatewayData = snakeKeysToCamelCase( + ws.botGatewayData = camelize( await fetch(`https://discord.com/api/gateway/bot`, { headers: { Authorization: ws.identifyPayload.token }, }).then((res) => res.json()), diff --git a/tests/util/utils.ts b/tests/util/utils.ts index 4cf2ef05e..233bf229e 100644 --- a/tests/util/utils.ts +++ b/tests/util/utils.ts @@ -1,8 +1,8 @@ -import { ApplicationCommandOption } from "../../src/types/interactions/application_command_option.ts"; -import { DiscordApplicationCommandOptionTypes } from "../../src/types/interactions/application_command_option_types.ts"; +import { ApplicationCommandOption } from "../../src/types/interactions/commands/application_command_option.ts"; +import { DiscordApplicationCommandOptionTypes } from "../../src/types/interactions/commands/application_command_option_types.ts"; import { - camelKeysToSnakeCase, - snakeKeysToCamelCase, + camelize, + snakelize, validateSlashCommands, } from "../../src/util/utils.ts"; import { assertEquals, assertThrows } from "../deps.ts"; @@ -61,9 +61,9 @@ const someElseOther = { Deno.test({ name: "[utils] convert snake case keys to camel case", fn() { - const result = snakeKeysToCamelCase(testSnakeObject); + const result = camelize(testSnakeObject); assertEquals(result, testCamelObject); - const resultTwo = snakeKeysToCamelCase(someOther); + const resultTwo = camelize(someOther); assertEquals(resultTwo, someOther); }, }); @@ -71,9 +71,9 @@ Deno.test({ Deno.test({ name: "[utils] convert camel case keys to snake case", fn() { - const result = camelKeysToSnakeCase(testCamelObject); + const result = snakelize(testCamelObject); assertEquals(result, testSnakeObject); - const resultTwo = camelKeysToSnakeCase(someElseOther); + const resultTwo = snakelize(someElseOther); assertEquals(resultTwo, someElseOther); }, }); From 781537bd170bf35687ddd615a16a68adb9a3fb96 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 5 May 2021 20:19:19 +0200 Subject: [PATCH 143/148] change this --- src/helpers/channels/update_voice_state.ts | 32 ++++++++++++++++++++++ src/helpers/mod.ts | 3 ++ 2 files changed, 35 insertions(+) create mode 100644 src/helpers/channels/update_voice_state.ts diff --git a/src/helpers/channels/update_voice_state.ts b/src/helpers/channels/update_voice_state.ts new file mode 100644 index 000000000..17ead3140 --- /dev/null +++ b/src/helpers/channels/update_voice_state.ts @@ -0,0 +1,32 @@ +import { rest } from "../../rest/rest.ts"; +import { UpdateOthersVoiceState } from "../../types/guilds/update_others_voice_state.ts"; +import type { + UpdateSelfVoiceState, +} from "../../types/guilds/update_self_voice_state.ts"; +import { endpoints } from "../../util/constants.ts"; +import { hasOwnProperty, snakelize } from "../../util/utils.ts"; + +/** + * Updates the a user's voice state, defaults to the current user + * Caveats: + * - `channel_id` must currently point to a stage channel. + * - User must already have joined `channel_id`. + * - You must have the `MUTE_MEMBERS` permission. But can always suppress yourself. + * - When unsuppressed, non-bot users will have their `request_to_speak_timestamp` set to the current time. Bot users will not. + * - You must have the `REQUEST_TO_SPEAK` permission to request to speak. You can always clear your own request to speak. + * - You are able to set `request_to_speak_timestamp` to any present or future time. + * - When suppressed, the user will have their `request_to_speak_timestamp` removed. + */ +export async function updateBotVoiceState( + guildId: bigint, + options: UpdateSelfVoiceState | { userId: bigint } & UpdateOthersVoiceState, +) { + return await rest.runMethod( + "patch", + endpoints.UPDATE_VOICE_STATE( + guildId, + hasOwnProperty(options, "userId") ? options.userId : undefined, + ), + snakelize(options), + ); +} diff --git a/src/helpers/mod.ts b/src/helpers/mod.ts index 903614119..fa610049d 100644 --- a/src/helpers/mod.ts +++ b/src/helpers/mod.ts @@ -13,6 +13,7 @@ import { getPins } from "./channels/get_pins.ts"; import { isChannelSynced } from "./channels/is_channel_synced.ts"; import { startTyping } from "./channels/start_typing.ts"; import { swapChannels } from "./channels/swap_channels.ts"; +import { updateBotVoiceState } from "./channels/update_voice_state.ts"; import { batchEditSlashCommandPermissions } from "./commands/batch_edit_slash_command_permissions.ts"; import { createSlashCommand } from "./commands/create_slash_command.ts"; import { deleteSlashCommand } from "./commands/delete_slash_command.ts"; @@ -258,6 +259,7 @@ export { unbanMember, unpin, unpinMessage, + updateBotVoiceState, upsertSlashCommand, upsertSlashCommands, validDiscoveryTerm, @@ -279,6 +281,7 @@ export let helpers = { isChannelSynced, startTyping, swapChannels, + updateBotVoiceState, // commands createSlashCommand, deleteSlashCommand, From be3889b5b00edeb949100d7d31127d1dab5d4e14 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 5 May 2021 20:20:50 +0200 Subject: [PATCH 144/148] rem --- src/helpers/guilds/update_bot_voice_state.ts | 26 ------------------ src/helpers/guilds/update_user_voice_state.ts | 27 ------------------- 2 files changed, 53 deletions(-) delete mode 100644 src/helpers/guilds/update_bot_voice_state.ts delete mode 100644 src/helpers/guilds/update_user_voice_state.ts diff --git a/src/helpers/guilds/update_bot_voice_state.ts b/src/helpers/guilds/update_bot_voice_state.ts deleted file mode 100644 index 8043de974..000000000 --- a/src/helpers/guilds/update_bot_voice_state.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { rest } from "../../rest/rest.ts"; -import type { - UpdateSelfVoiceState, -} from "../../types/guilds/update_self_voice_state.ts"; -import { endpoints } from "../../util/constants.ts"; -import { snakelize } from "../../util/utils.ts"; - -/** - * Updates the current user's voice state. - * Caveats: - * - `channel_id` must currently point to a stage channel. - * - current user must already have joined `channel_id`. - * - You must have the `MUTE_MEMBERS` permission to unsuppress yourself. You can always suppress yourself. - * - You must have the `REQUEST_TO_SPEAK` permission to request to speak. You can always clear your own request to speak. - * - You are able to set `request_to_speak_timestamp` to any present or future time. - */ -export async function updateBotVoiceState( - guildId: bigint, - data: UpdateSelfVoiceState, -) { - return await rest.runMethod( - "patch", - endpoints.UPDATE_VOICE_STATE(guildId), - snakelize(data), - ); -} diff --git a/src/helpers/guilds/update_user_voice_state.ts b/src/helpers/guilds/update_user_voice_state.ts deleted file mode 100644 index 38191274b..000000000 --- a/src/helpers/guilds/update_user_voice_state.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { rest } from "../../rest/rest.ts"; -import type { - UpdateOthersVoiceState, -} from "../../types/guilds/update_others_voice_state.ts"; -import { endpoints } from "../../util/constants.ts"; -import { snakelize } from "../../util/utils.ts"; - -/** - * Updates another user's voice state. - * Caveats: - * - `channel_id` must currently point to a stage channel. - * - User must already have joined `channel_id`. - * - You must have the `MUTE_MEMBERS` permission. (Since suppression is the only thing that is available currently.) - * - When unsuppressed, non-bot users will have their `request_to_speak_timestamp` set to the current time. Bot users will not. - * - When suppressed, the user will have their `request_to_speak_timestamp` removed. - */ -export function updateVoiceState( - guildId: bigint, - userId: bigint, - data: UpdateOthersVoiceState, -) { - return rest.runMethod( - "patch", - endpoints.UPDATE_VOICE_STATE(guildId, userId), - snakelize(data), - ); -} From 95e3c796ec5057bb407dcb1f6edbf0e8a972b659 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 5 May 2021 21:51:02 +0200 Subject: [PATCH 145/148] remove author for better auto completion --- src/structures/message.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/structures/message.ts b/src/structures/message.ts index 0525d254f..97bf7ff40 100644 --- a/src/structures/message.ts +++ b/src/structures/message.ts @@ -253,7 +253,6 @@ export interface DiscordenoMessage extends | "author" > { id: bigint; - author: undefined; /** Whether or not this message was sent by a bot */ isBot: boolean; /** The username#discrimnator for the user who sent this message */ From 11e9a800e590f1191b1d55a290b98d848f4c0324 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Thu, 6 May 2021 12:38:05 +0200 Subject: [PATCH 146/148] message.guildid has to be bigint --- src/structures/message.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/structures/message.ts b/src/structures/message.ts index 97bf7ff40..bec9d8e2d 100644 --- a/src/structures/message.ts +++ b/src/structures/message.ts @@ -191,10 +191,10 @@ export async function createDiscordenoMessage(data: Message) { props.tag = createNewProp(`${author.username}#${author.discriminator}`); // Discord doesnt give guild id for getMessage() so this will fill it in - const guildIdFinal = guildId || + const guildIdFinal = snowflakeToBigint(guildId) || (await cacheHandlers.get("channels", snowflakeToBigint(data.channelId))) ?.guildId || - ""; + 0n; const message: DiscordenoMessage = Object.create(baseMessage, { ...props, From b30dd053a8a7396e34ead2384c0ecf9205f0a08c Mon Sep 17 00:00:00 2001 From: ITOH Date: Thu, 6 May 2021 13:42:38 +0100 Subject: [PATCH 147/148] Update rest.ts --- src/rest/rest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rest/rest.ts b/src/rest/rest.ts index 2f7997780..91aa47f6c 100644 --- a/src/rest/rest.ts +++ b/src/rest/rest.ts @@ -14,7 +14,7 @@ export const rest = { token: "", /** The maximum amount of retries allowed */ maxRetryCount: 10, - apiVersion: "8", + apiVersion: "9", /** The secret authorization key to confirm that this was a request made by you and not a DDOS attack. */ authorization: "discordeno_best_lib_ever", pathQueues: new Map< From d56279d75cfd521f0d221b49b1b35ab69703ae87 Mon Sep 17 00:00:00 2001 From: ITOH Date: Thu, 6 May 2021 13:43:14 +0100 Subject: [PATCH 148/148] Update ws.ts --- src/ws/ws.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ws/ws.ts b/src/ws/ws.ts index a66e3f816..2ff84d92b 100644 --- a/src/ws/ws.ts +++ b/src/ws/ws.ts @@ -49,7 +49,7 @@ export const ws = { }, botGatewayData: { /** The WSS URL that can be used for connecting to the gateway. */ - url: "wss://gateway.discord.gg/?v=8&encoding=json", + url: "wss://gateway.discord.gg/?v=9&encoding=json", /** The recommended number of shards to use when connecting. */ shards: 1, /** Info on the current start limit. */