diff --git a/src/rest/process_queue.ts b/src/rest/process_queue.ts index b9539da1c..9404583cd 100644 --- a/src/rest/process_queue.ts +++ b/src/rest/process_queue.ts @@ -36,18 +36,19 @@ export async function processQueue(id: string) { // EXECUTE THE REQUEST // IF THIS IS A GET REQUEST, CHANGE THE BODY TO QUERY PARAMETERS - const query = - queuedRequest.request.method.toUpperCase() === "GET" && - queuedRequest.payload.body - ? Object.entries(queuedRequest.payload.body) - .map( - ([key, value]) => - `${encodeURIComponent(key)}=${encodeURIComponent( - value as string - )}` - ) - .join("&") - : ""; + const query = queuedRequest.request.method.toUpperCase() === "GET" && + queuedRequest.payload.body + ? Object.entries(queuedRequest.payload.body) + .map( + ([key, value]) => + `${encodeURIComponent(key)}=${ + encodeURIComponent( + value as string, + ) + }`, + ) + .join("&") + : ""; const urlToUse = queuedRequest.request.method.toUpperCase() === "GET" && query ? `${queuedRequest.request.url}?${query}` @@ -59,13 +60,13 @@ export async function processQueue(id: string) { try { const response = await fetch( urlToUse, - rest.createRequestBody(queuedRequest) + rest.createRequestBody(queuedRequest), ); rest.eventHandlers.fetched(queuedRequest.payload); const bucketIdFromHeaders = rest.processRequestHeaders( queuedRequest.request.url, - response.headers + response.headers, ); if (response.status < 200 || response.status >= 400) { @@ -123,7 +124,7 @@ export async function processQueue(id: string) { // IF IT HAS MAXED RETRIES SOMETHING SERIOUSLY WRONG. CANCEL OUT. if ( queuedRequest.payload.retryCount >= - queuedRequest.options.maxRetryCount + queuedRequest.options.maxRetryCount ) { rest.eventHandlers.retriesMaxed(queuedRequest.payload); queuedRequest.request.respond({ diff --git a/src/types/audit_log/audit_log_change_value.ts b/src/types/audit_log/audit_log_change_value.ts index 1028e35ff..c1372004c 100644 --- a/src/types/audit_log/audit_log_change_value.ts +++ b/src/types/audit_log/audit_log_change_value.ts @@ -4,85 +4,87 @@ import { SnakeCasedPropertiesDeep } from "../util.ts"; export type AuditLogChangeValue = | { - newValue: string; - oldValue: string; - key: - | "name" - | "description" - | "discovery_splash_hash" - | "banner_hash" - | "preferred_locale" - | "rules_channel_id" - | "public_updates_channel_id" - | "icon_hash" - | "splash_hash" - | "owner_id" - | "region" - | "afk_channel_id" - | "vanity_url_code" - | "widget_channel_id" - | "system_channel_id" - | "topic" - | "application_id" - | "permissions" - | "allow" - | "deny" - | "code" - | "channel_id" - | "inviter_id" - | "nick" - | "avatar_hash" - | "id"; - } + newValue: string; + oldValue: string; + key: + | "name" + | "description" + | "discovery_splash_hash" + | "banner_hash" + | "preferred_locale" + | "rules_channel_id" + | "public_updates_channel_id" + | "icon_hash" + | "splash_hash" + | "owner_id" + | "region" + | "afk_channel_id" + | "vanity_url_code" + | "widget_channel_id" + | "system_channel_id" + | "topic" + | "application_id" + | "permissions" + | "allow" + | "deny" + | "code" + | "channel_id" + | "inviter_id" + | "nick" + | "avatar_hash" + | "id"; + } | { - newValue: number; - oldValue: number; - key: - | "afk_timeout" - | "mfa_level" - | "verification_level" - | "explicit_content_filter" - | "default_messagae_notifications" - | "prune_delete_days" - | "position" - | "bitrate" - | "rate_limit_per_user" - | "color" - | "max_uses" - | "uses" - | "max_age" - | "expire_behavior" - | "expire_grace_period" - | "user_limit"; - } + newValue: number; + oldValue: number; + key: + | "afk_timeout" + | "mfa_level" + | "verification_level" + | "explicit_content_filter" + | "default_messagae_notifications" + | "prune_delete_days" + | "position" + | "bitrate" + | "rate_limit_per_user" + | "color" + | "max_uses" + | "uses" + | "max_age" + | "expire_behavior" + | "expire_grace_period" + | "user_limit"; + } | { - newValue: Partial; - oldValue: Partial; - key: "$add" | "$remove"; - } + newValue: Partial; + oldValue: Partial; + key: "$add" | "$remove"; + } | { - newValue: boolean; - oldValue: boolean; - key: - | "widget_enabled" - | "nsfw" - | "hoist" - | "mentionable" - | "temporary" - | "deaf" - | "mute" - | "enable_emoticons"; - } + newValue: boolean; + oldValue: boolean; + key: + | "widget_enabled" + | "nsfw" + | "hoist" + | "mentionable" + | "temporary" + | "deaf" + | "mute" + | "enable_emoticons"; + } | { - newValue: Overwrite[]; - oldValue: Overwrite[]; - key: "permission_overwrites"; - } + newValue: Overwrite[]; + oldValue: Overwrite[]; + key: "permission_overwrites"; + } | { - newValue: string | number; - oldValue: string | number; - key: "type"; - }; + newValue: string | number; + oldValue: string | number; + key: "type"; + }; /** https://discord.com/developers/docs/resources/audit-log#audit-log-change-object-audit-log-change-structure */ -export type DiscordAuditLogChangeValue = SnakeCasedPropertiesDeep; +export type DiscordAuditLogChangeValue = SnakeCasedPropertiesDeep< + AuditLogChangeValue +>; diff --git a/src/types/audit_log/get_guild_audit_log.ts b/src/types/audit_log/get_guild_audit_log.ts index 45b1537e5..ef2fab575 100644 --- a/src/types/audit_log/get_guild_audit_log.ts +++ b/src/types/audit_log/get_guild_audit_log.ts @@ -13,4 +13,6 @@ export interface GetGuildAuditLog { } /** https://discord.com/developers/docs/resources/audit-log#get-guild-audit-log-query-string-parameters */ -export type DiscordGetGuildAuditLog = SnakeCasedPropertiesDeep; +export type DiscordGetGuildAuditLog = SnakeCasedPropertiesDeep< + GetGuildAuditLog +>; diff --git a/src/types/audit_log/optional_audit_entry_info.ts b/src/types/audit_log/optional_audit_entry_info.ts index fa367803e..ec89b1a6d 100644 --- a/src/types/audit_log/optional_audit_entry_info.ts +++ b/src/types/audit_log/optional_audit_entry_info.ts @@ -20,4 +20,6 @@ export interface OptionalAuditEntryInfo { } /** https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-optional-audit-entry-info */ -export type DiscordOptionalAuditEntryInfo = SnakeCasedPropertiesDeep; +export type DiscordOptionalAuditEntryInfo = SnakeCasedPropertiesDeep< + OptionalAuditEntryInfo +>; diff --git a/src/types/channels/channel_pins_update.ts b/src/types/channels/channel_pins_update.ts index 6d7bc4929..65de83815 100644 --- a/src/types/channels/channel_pins_update.ts +++ b/src/types/channels/channel_pins_update.ts @@ -10,4 +10,6 @@ export interface ChannelPinsUpdate { } /** https://discord.com/developers/docs/topics/gateway#channel-pins-update */ -export type DiscordChannelPinsUpdate = SnakeCasedPropertiesDeep; +export type DiscordChannelPinsUpdate = SnakeCasedPropertiesDeep< + ChannelPinsUpdate +>; diff --git a/src/types/channels/modify_channel.ts b/src/types/channels/modify_channel.ts index 41c56776b..4a12af469 100644 --- a/src/types/channels/modify_channel.ts +++ b/src/types/channels/modify_channel.ts @@ -26,8 +26,8 @@ export interface ModifyChannel { } /** https://discord.com/developers/docs/resources/channel#modify-channel */ -export interface DiscordModifyChannel - extends SnakeCasedPropertiesDeep< +export interface DiscordModifyChannel extends + SnakeCasedPropertiesDeep< Omit > { permission_overwrites?: DiscordOverwrite[]; diff --git a/src/types/emojis/guild_emojis_update.ts b/src/types/emojis/guild_emojis_update.ts index d680d1739..d7990f61b 100644 --- a/src/types/emojis/guild_emojis_update.ts +++ b/src/types/emojis/guild_emojis_update.ts @@ -9,4 +9,6 @@ export interface GuildEmojisUpdate { } /** https://discord.com/developers/docs/topics/gateway#guild-emojis-update */ -export type DiscordGuildEmojisUpdate = SnakeCasedPropertiesDeep; +export type DiscordGuildEmojisUpdate = SnakeCasedPropertiesDeep< + GuildEmojisUpdate +>; diff --git a/src/types/gateway/session_start_limit.ts b/src/types/gateway/session_start_limit.ts index 4bfd204d3..01bbac11b 100644 --- a/src/types/gateway/session_start_limit.ts +++ b/src/types/gateway/session_start_limit.ts @@ -12,4 +12,6 @@ export interface SessionStartLimit { } /** https://discord.com/developers/docs/topics/gateway#session-start-limit-object */ -export type DiscordSessionStartLimit = SnakeCasedPropertiesDeep; +export type DiscordSessionStartLimit = SnakeCasedPropertiesDeep< + SessionStartLimit +>; diff --git a/src/types/guilds/create_guild_channel.ts b/src/types/guilds/create_guild_channel.ts index 8bbde8f24..82ff9d9f8 100644 --- a/src/types/guilds/create_guild_channel.ts +++ b/src/types/guilds/create_guild_channel.ts @@ -26,8 +26,8 @@ export interface CreateGuildChannel { } /** https://discord.com/developers/docs/resources/guild#create-guild-channel */ -export interface DiscordCreateGuildChannel - extends SnakeCasedPropertiesDeep< +export interface DiscordCreateGuildChannel extends + SnakeCasedPropertiesDeep< Omit > { permission_overwrites: DiscordOverwrite[]; diff --git a/src/types/guilds/get_guild_prune_count.ts b/src/types/guilds/get_guild_prune_count.ts index 79476bde6..f0eb6636a 100644 --- a/src/types/guilds/get_guild_prune_count.ts +++ b/src/types/guilds/get_guild_prune_count.ts @@ -8,4 +8,6 @@ export interface GetGuildPruneCountQuery { } /** https://discord.com/developers/docs/resources/guild#get-guild-prune-count */ -export type DiscordGetGuildPruneCountQuery = SnakeCasedPropertiesDeep; +export type DiscordGetGuildPruneCountQuery = SnakeCasedPropertiesDeep< + GetGuildPruneCountQuery +>; diff --git a/src/types/guilds/guild_ban_add_remove.ts b/src/types/guilds/guild_ban_add_remove.ts index 4cd453246..988368946 100644 --- a/src/types/guilds/guild_ban_add_remove.ts +++ b/src/types/guilds/guild_ban_add_remove.ts @@ -9,4 +9,6 @@ export interface GuildBanAddRemove { } /** https://discord.com/developers/docs/topics/gateway#guild-ban-add */ -export type DiscordGuildBanAddRemove = SnakeCasedPropertiesDeep; +export type DiscordGuildBanAddRemove = SnakeCasedPropertiesDeep< + GuildBanAddRemove +>; diff --git a/src/types/guilds/modify_guild_member.ts b/src/types/guilds/modify_guild_member.ts index 096573e6d..e7756ea07 100644 --- a/src/types/guilds/modify_guild_member.ts +++ b/src/types/guilds/modify_guild_member.ts @@ -14,4 +14,6 @@ export interface ModifyGuildMember { } /** https://discord.com/developers/docs/resources/guild#modify-guild-member */ -export type DiscordModifyGuildMember = SnakeCasedPropertiesDeep; +export type DiscordModifyGuildMember = SnakeCasedPropertiesDeep< + ModifyGuildMember +>; diff --git a/src/types/guilds/request_guild_members.ts b/src/types/guilds/request_guild_members.ts index 85d7fbd69..89d29feea 100644 --- a/src/types/guilds/request_guild_members.ts +++ b/src/types/guilds/request_guild_members.ts @@ -16,4 +16,6 @@ export interface RequestGuildMembers { } /** https://discord.com/developers/docs/topics/gateway#request-guild-members */ -export type DiscordRequestGuildMembers = SnakeCasedPropertiesDeep; +export type DiscordRequestGuildMembers = SnakeCasedPropertiesDeep< + RequestGuildMembers +>; diff --git a/src/types/guilds/unavailable_guild.ts b/src/types/guilds/unavailable_guild.ts index 4a939c120..d52f8c5fe 100644 --- a/src/types/guilds/unavailable_guild.ts +++ b/src/types/guilds/unavailable_guild.ts @@ -4,4 +4,6 @@ import { Guild } from "./guild.ts"; export type UnavailableGuild = Pick; /** https://discord.com/developers/docs/resources/guild#unavailable-guild-object */ -export type DiscordUnavailableGuild = SnakeCasedPropertiesDeep; +export type DiscordUnavailableGuild = SnakeCasedPropertiesDeep< + UnavailableGuild +>; diff --git a/src/types/guilds/welcome_screen_channel.ts b/src/types/guilds/welcome_screen_channel.ts index 1d63a32f2..0b44d9c94 100644 --- a/src/types/guilds/welcome_screen_channel.ts +++ b/src/types/guilds/welcome_screen_channel.ts @@ -12,4 +12,6 @@ export interface WelcomeScreenChannel { } /** https://discord.com/developers/docs/resources/guild#welcome-screen-object-welcome-screen-channel-structure */ -export type DiscordWelcomeScreenChannel = SnakeCasedPropertiesDeep; +export type DiscordWelcomeScreenChannel = SnakeCasedPropertiesDeep< + WelcomeScreenChannel +>; diff --git a/src/types/integration/guild_integrations_update.ts b/src/types/integration/guild_integrations_update.ts index d460e1207..e29351c75 100644 --- a/src/types/integration/guild_integrations_update.ts +++ b/src/types/integration/guild_integrations_update.ts @@ -6,4 +6,6 @@ export interface GuildIntegrationsUpdate { } /** https://discord.com/developers/docs/topics/gateway#guild-integrations-update */ -export type DiscordGuildIntegrationsUpdate = SnakeCasedPropertiesDeep; +export type DiscordGuildIntegrationsUpdate = SnakeCasedPropertiesDeep< + GuildIntegrationsUpdate +>; diff --git a/src/types/integration/integration_application.ts b/src/types/integration/integration_application.ts index d4da00b90..0b20531b3 100644 --- a/src/types/integration/integration_application.ts +++ b/src/types/integration/integration_application.ts @@ -17,4 +17,6 @@ export interface IntegrationApplication { } /** https://discord.com/developers/docs/resources/guild#integration-application-object-integration-application-structure */ -export type DiscordIntegrationApplication = SnakeCasedPropertiesDeep; +export type DiscordIntegrationApplication = SnakeCasedPropertiesDeep< + IntegrationApplication +>; diff --git a/src/types/integration/integration_create_update.ts b/src/types/integration/integration_create_update.ts index f15cd60da..dda32b493 100644 --- a/src/types/integration/integration_create_update.ts +++ b/src/types/integration/integration_create_update.ts @@ -7,4 +7,6 @@ export interface IntegrationCreateUpdate extends Integration { } /** https://github.com/discord/discord-api-docs/blob/master/docs/topics/Gateway.md#integration-create-event-additional-fields */ -export type DiscordIntegrationCreateUpdate = SnakeCasedPropertiesDeep; +export type DiscordIntegrationCreateUpdate = SnakeCasedPropertiesDeep< + IntegrationCreateUpdate +>; diff --git a/src/types/integration/integration_delete.ts b/src/types/integration/integration_delete.ts index 2217fb855..83d090299 100644 --- a/src/types/integration/integration_delete.ts +++ b/src/types/integration/integration_delete.ts @@ -10,4 +10,6 @@ export interface IntegrationDelete { } /** https://github.com/discord/discord-api-docs/blob/master/docs/topics/Gateway.md#integration-delete-event-fields */ -export type DiscordIntegrationDelete = SnakeCasedPropertiesDeep; +export type DiscordIntegrationDelete = SnakeCasedPropertiesDeep< + IntegrationDelete +>; diff --git a/src/types/integration/modify_guild_integration.ts b/src/types/integration/modify_guild_integration.ts index 62c7a4256..dfd942bca 100644 --- a/src/types/integration/modify_guild_integration.ts +++ b/src/types/integration/modify_guild_integration.ts @@ -10,4 +10,6 @@ export interface ModifyGuildIntegration { } /** https://discord.com/developers/docs/resources/guild#modify-guild-integration-json-params */ -export type DiscordModifyGuildIntegration = SnakeCasedPropertiesDeep; +export type DiscordModifyGuildIntegration = SnakeCasedPropertiesDeep< + ModifyGuildIntegration +>; diff --git a/src/types/interactions/application_command.ts b/src/types/interactions/application_command.ts index 270dd7e04..9a3df0bc3 100644 --- a/src/types/interactions/application_command.ts +++ b/src/types/interactions/application_command.ts @@ -15,4 +15,6 @@ export interface ApplicationCommand { } /** https://discord.com/developers/docs/interactions/slash-commands#applicationcommand */ -export type DiscordApplicationCommand = SnakeCasedPropertiesDeep; +export type DiscordApplicationCommand = SnakeCasedPropertiesDeep< + ApplicationCommand +>; diff --git a/src/types/interactions/application_command_callback_data.ts b/src/types/interactions/application_command_callback_data.ts index f3c073f33..e5443854e 100644 --- a/src/types/interactions/application_command_callback_data.ts +++ b/src/types/interactions/application_command_callback_data.ts @@ -16,4 +16,5 @@ export interface InteractionApplicationCommandCallbackData { } /** https://discord.com/developers/docs/interactions/slash-commands#interaction-response-interactionapplicationcommandcallbackdata */ -export type DiscordInteractionApplicationCommandCallbackData = SnakeCasedPropertiesDeep; +export type DiscordInteractionApplicationCommandCallbackData = + SnakeCasedPropertiesDeep; diff --git a/src/types/interactions/application_command_create_update_delete.ts b/src/types/interactions/application_command_create_update_delete.ts index 74a7d7b03..83aaaba9a 100644 --- a/src/types/interactions/application_command_create_update_delete.ts +++ b/src/types/interactions/application_command_create_update_delete.ts @@ -8,4 +8,5 @@ export interface ApplicationCommandCreateUpdateDelete } /** https://discord.com/developers/docs/topics/gateway#application-command-delete-application-command-extra-fields */ -export type DiscordApplicationCommandCreateUpdateDelete = SnakeCasedPropertiesDeep; +export type DiscordApplicationCommandCreateUpdateDelete = + SnakeCasedPropertiesDeep; diff --git a/src/types/interactions/application_command_interaction_data.ts b/src/types/interactions/application_command_interaction_data.ts index 5550c1664..566b3518a 100644 --- a/src/types/interactions/application_command_interaction_data.ts +++ b/src/types/interactions/application_command_interaction_data.ts @@ -11,4 +11,6 @@ export interface ApplicationCommandInteractionData { } /** https://discord.com/developers/docs/interactions/slash-commands#interaction-applicationcommandinteractiondata */ -export type DiscordApplicationCommandInteractionData = SnakeCasedPropertiesDeep; +export type DiscordApplicationCommandInteractionData = SnakeCasedPropertiesDeep< + ApplicationCommandInteractionData +>; diff --git a/src/types/interactions/application_command_interaction_data_option.ts b/src/types/interactions/application_command_interaction_data_option.ts index a1f62647e..80e9e3cad 100644 --- a/src/types/interactions/application_command_interaction_data_option.ts +++ b/src/types/interactions/application_command_interaction_data_option.ts @@ -11,4 +11,5 @@ export interface ApplicationCommandInteractionDataOption { } /** https://discord.com/developers/docs/interactions/slash-commands#interaction-applicationcommandinteractiondataoption */ -export type DiscordApplicationCommandInteractionDataOption = SnakeCasedPropertiesDeep; +export type DiscordApplicationCommandInteractionDataOption = + SnakeCasedPropertiesDeep; diff --git a/src/types/interactions/application_command_option.ts b/src/types/interactions/application_command_option.ts index 337724617..1491c8898 100644 --- a/src/types/interactions/application_command_option.ts +++ b/src/types/interactions/application_command_option.ts @@ -18,4 +18,6 @@ export interface ApplicationCommandOption { } /** https://discord.com/developers/docs/interactions/slash-commands#applicationcommandoption */ -export type DiscordApplicationCommandOption = SnakeCasedPropertiesDeep; +export type DiscordApplicationCommandOption = SnakeCasedPropertiesDeep< + ApplicationCommandOption +>; diff --git a/src/types/interactions/create_global_application_command.ts b/src/types/interactions/create_global_application_command.ts index 307354cc6..760141db4 100644 --- a/src/types/interactions/create_global_application_command.ts +++ b/src/types/interactions/create_global_application_command.ts @@ -11,4 +11,6 @@ export interface CreateGlobalApplicationCommand { } /** https://discord.com/developers/docs/interactions/slash-commands#create-global-application-command-json-params */ -export type DiscordCreateGlobalApplicationCommand = SnakeCasedPropertiesDeep; +export type DiscordCreateGlobalApplicationCommand = SnakeCasedPropertiesDeep< + CreateGlobalApplicationCommand +>; diff --git a/src/types/interactions/create_guild_application_command.ts b/src/types/interactions/create_guild_application_command.ts index a298d5c7e..8c6520826 100644 --- a/src/types/interactions/create_guild_application_command.ts +++ b/src/types/interactions/create_guild_application_command.ts @@ -11,4 +11,6 @@ export interface CreateGuildApplicationCommand { } /** https://discord.com/developers/docs/interactions/slash-commands#create-guild-application-command-json-params */ -export type DiscordCreateGuildApplicationCommand = SnakeCasedPropertiesDeep; +export type DiscordCreateGuildApplicationCommand = SnakeCasedPropertiesDeep< + CreateGuildApplicationCommand +>; diff --git a/src/types/interactions/edit_global_application_command.ts b/src/types/interactions/edit_global_application_command.ts index 7880a651f..a9cc2e088 100644 --- a/src/types/interactions/edit_global_application_command.ts +++ b/src/types/interactions/edit_global_application_command.ts @@ -11,4 +11,6 @@ export interface EditGlobalApplicationCommand { } /** https://discord.com/developers/docs/interactions/slash-commands#edit-global-application-command-json-params */ -export type DiscordEditGlobalApplicationCommand = SnakeCasedPropertiesDeep; +export type DiscordEditGlobalApplicationCommand = SnakeCasedPropertiesDeep< + EditGlobalApplicationCommand +>; diff --git a/src/types/interactions/edit_guild_application_command.ts b/src/types/interactions/edit_guild_application_command.ts index ca956121e..d5139f065 100644 --- a/src/types/interactions/edit_guild_application_command.ts +++ b/src/types/interactions/edit_guild_application_command.ts @@ -11,4 +11,6 @@ export interface EditGuildApplicationCommand { } /** https://discord.com/developers/docs/interactions/slash-commands#edit-guild-application-command-json-params */ -export type DiscordEditGuildApplicationCommand = SnakeCasedPropertiesDeep; +export type DiscordEditGuildApplicationCommand = SnakeCasedPropertiesDeep< + EditGuildApplicationCommand +>; diff --git a/src/types/interactions/interaction_guild_member.ts b/src/types/interactions/interaction_guild_member.ts index 584b2f74f..a37e50b9b 100644 --- a/src/types/interactions/interaction_guild_member.ts +++ b/src/types/interactions/interaction_guild_member.ts @@ -7,4 +7,6 @@ export interface InteractionGuildMember extends GuildMember { } /** https://discord.com/developers/docs/resources/guild#guild-member-object */ -export type DiscordInteractionGuildMember = SnakeCasedPropertiesDeep; +export type DiscordInteractionGuildMember = SnakeCasedPropertiesDeep< + InteractionGuildMember +>; diff --git a/src/types/interactions/interaction_response.ts b/src/types/interactions/interaction_response.ts index 596e3520e..4a47cdef2 100644 --- a/src/types/interactions/interaction_response.ts +++ b/src/types/interactions/interaction_response.ts @@ -10,4 +10,6 @@ export interface InteractionResponse { } /** https://discord.com/developers/docs/interactions/slash-commands#interaction-response */ -export type DiscordInteractionResponse = SnakeCasedPropertiesDeep; +export type DiscordInteractionResponse = SnakeCasedPropertiesDeep< + InteractionResponse +>; diff --git a/src/types/interactions/message_interaction.ts b/src/types/interactions/message_interaction.ts index 19f857eee..2ceb98aca 100644 --- a/src/types/interactions/message_interaction.ts +++ b/src/types/interactions/message_interaction.ts @@ -14,4 +14,6 @@ export interface MessageInteraction { } /** https://discord.com/developers/docs/interactions/slash-commands#messageinteraction */ -export type DiscordMessageInteraction = SnakeCasedPropertiesDeep; +export type DiscordMessageInteraction = SnakeCasedPropertiesDeep< + MessageInteraction +>; diff --git a/src/types/members/guild_member_remove.ts b/src/types/members/guild_member_remove.ts index 2d44b5c66..21010be0c 100644 --- a/src/types/members/guild_member_remove.ts +++ b/src/types/members/guild_member_remove.ts @@ -9,4 +9,6 @@ export interface GuildMemberRemove { } /** https://discord.com/developers/docs/topics/gateway#guild-member-remove */ -export type DiscordGuildMemberRemove = SnakeCasedPropertiesDeep; +export type DiscordGuildMemberRemove = SnakeCasedPropertiesDeep< + GuildMemberRemove +>; diff --git a/src/types/members/guild_member_update.ts b/src/types/members/guild_member_update.ts index 36241a94d..a171bee40 100644 --- a/src/types/members/guild_member_update.ts +++ b/src/types/members/guild_member_update.ts @@ -19,4 +19,6 @@ export interface GuildMemberUpdate { } /** https://discord.com/developers/docs/topics/gateway#guild-member-update */ -export type DiscordGuildMemberUpdate = SnakeCasedPropertiesDeep; +export type DiscordGuildMemberUpdate = SnakeCasedPropertiesDeep< + GuildMemberUpdate +>; diff --git a/src/types/members/guild_members_chunk.ts b/src/types/members/guild_members_chunk.ts index 3c78feed0..b4b4e0a82 100644 --- a/src/types/members/guild_members_chunk.ts +++ b/src/types/members/guild_members_chunk.ts @@ -20,4 +20,6 @@ export interface GuildMembersChunk { } /** https://discord.com/developers/docs/topics/gateway#guild-members-chunk */ -export type DiscordGuildMembersChunk = SnakeCasedPropertiesDeep; +export type DiscordGuildMembersChunk = SnakeCasedPropertiesDeep< + GuildMembersChunk +>; diff --git a/src/types/messages/message_application.ts b/src/types/messages/message_application.ts index 19d301cd4..a0cd69eef 100644 --- a/src/types/messages/message_application.ts +++ b/src/types/messages/message_application.ts @@ -13,4 +13,6 @@ export interface MessageApplication { name: string; } -export type DiscordMessageApplication = SnakeCasedPropertiesDeep; +export type DiscordMessageApplication = SnakeCasedPropertiesDeep< + MessageApplication +>; diff --git a/src/types/messages/message_delete_bulk.ts b/src/types/messages/message_delete_bulk.ts index 8474f65b6..9d1a0f163 100644 --- a/src/types/messages/message_delete_bulk.ts +++ b/src/types/messages/message_delete_bulk.ts @@ -10,4 +10,6 @@ export interface MessageDeleteBulk { } /** https://discord.com/developers/docs/topics/gateway#message-delete-bulk */ -export type DiscordMessageDeleteBulk = SnakeCasedPropertiesDeep; +export type DiscordMessageDeleteBulk = SnakeCasedPropertiesDeep< + MessageDeleteBulk +>; diff --git a/src/types/messages/message_reaction_add.ts b/src/types/messages/message_reaction_add.ts index 8d50ebd70..4839e9e26 100644 --- a/src/types/messages/message_reaction_add.ts +++ b/src/types/messages/message_reaction_add.ts @@ -18,4 +18,6 @@ export interface MessageReactionAdd { } /** https://discord.com/developers/docs/topics/gateway#message-reaction-add */ -export type DiscordMessageReactionAdd = SnakeCasedPropertiesDeep; +export type DiscordMessageReactionAdd = SnakeCasedPropertiesDeep< + MessageReactionAdd +>; diff --git a/src/types/messages/message_reaction_remove.ts b/src/types/messages/message_reaction_remove.ts index 439022a88..8ffd7c996 100644 --- a/src/types/messages/message_reaction_remove.ts +++ b/src/types/messages/message_reaction_remove.ts @@ -4,4 +4,6 @@ import { MessageReactionAdd } from "./message_reaction_add.ts"; export type MessageReactionRemove = Omit; /** https://discord.com/developers/docs/topics/gateway#message-reaction-remove */ -export type DiscordMessageReactionRemove = SnakeCasedPropertiesDeep; +export type DiscordMessageReactionRemove = SnakeCasedPropertiesDeep< + MessageReactionRemove +>; diff --git a/src/types/messages/message_reaction_remove_all.ts b/src/types/messages/message_reaction_remove_all.ts index d046bce40..6e7264889 100644 --- a/src/types/messages/message_reaction_remove_all.ts +++ b/src/types/messages/message_reaction_remove_all.ts @@ -7,4 +7,6 @@ export type MessageReactionRemoveAll = Pick< >; /** https://discord.com/developers/docs/topics/gateway#message-reaction-remove-all */ -export type DiscordMessageReactionRemoveAll = SnakeCasedPropertiesDeep; +export type DiscordMessageReactionRemoveAll = SnakeCasedPropertiesDeep< + MessageReactionRemoveAll +>; diff --git a/src/types/messages/message_reaction_remove_emoji.ts b/src/types/messages/message_reaction_remove_emoji.ts index 09e5edcd0..6460ef99a 100644 --- a/src/types/messages/message_reaction_remove_emoji.ts +++ b/src/types/messages/message_reaction_remove_emoji.ts @@ -7,4 +7,6 @@ export type MessageReactionRemoveEmoji = Pick< >; /** https://discord.com/developers/docs/topics/gateway#message-reaction-remove-emoji */ -export type DiscordMessageReactionRemoveEmoji = SnakeCasedPropertiesDeep; +export type DiscordMessageReactionRemoveEmoji = SnakeCasedPropertiesDeep< + MessageReactionRemoveEmoji +>; diff --git a/src/types/messages/message_reference.ts b/src/types/messages/message_reference.ts index d6b6acd48..ba2b143e8 100644 --- a/src/types/messages/message_reference.ts +++ b/src/types/messages/message_reference.ts @@ -15,4 +15,6 @@ export interface MessageReference { } /** https://discord.com/developers/docs/resources/channel#message-object-message-reference-structure */ -export type DiscordMessageReference = SnakeCasedPropertiesDeep; +export type DiscordMessageReference = SnakeCasedPropertiesDeep< + MessageReference +>; diff --git a/src/types/oauth2/bot_auth_query.ts b/src/types/oauth2/bot_auth_query.ts index bd458284c..90137da04 100644 --- a/src/types/oauth2/bot_auth_query.ts +++ b/src/types/oauth2/bot_auth_query.ts @@ -15,4 +15,6 @@ export interface BotAuthenticationFlowQuery { } /** https://discord.com/developers/docs/topics/oauth2#bot-authorization-flow-bot-auth-parameters */ -export type DiscordBotAuthenticationFlowQuery = SnakeCasedPropertiesDeep; +export type DiscordBotAuthenticationFlowQuery = SnakeCasedPropertiesDeep< + BotAuthenticationFlowQuery +>; diff --git a/src/types/oauth2/get_current_authorization_information.ts b/src/types/oauth2/get_current_authorization_information.ts index 60d1ffea8..0a8009c16 100644 --- a/src/types/oauth2/get_current_authorization_information.ts +++ b/src/types/oauth2/get_current_authorization_information.ts @@ -15,4 +15,6 @@ export interface GetCurrentAuthorizationInformation { } /** https://discord.com/developers/docs/topics/oauth2#get-current-authorization-information-response-structure */ -export type DiscordGetCurrentAuthoriationInformation = SnakeCasedPropertiesDeep; +export type DiscordGetCurrentAuthoriationInformation = SnakeCasedPropertiesDeep< + GetCurrentAuthorizationInformation +>; diff --git a/src/types/teams/team_member.ts b/src/types/teams/team_member.ts index 7f1fb8f8f..f3249bdbd 100644 --- a/src/types/teams/team_member.ts +++ b/src/types/teams/team_member.ts @@ -10,8 +10,9 @@ export interface TeamMember { /** The id of the parent team of which they are a member */ teamId: string; /** The avatar, discriminator, id, and username of the user */ - user: Partial & - Pick; + user: + & Partial + & Pick; } /** https://discord.com/developers/docs/topics/teams#data-models-team-members-object */ diff --git a/src/types/util.ts b/src/types/util.ts index fb3512b89..16cea5311 100644 --- a/src/types/util.ts +++ b/src/types/util.ts @@ -1,103 +1,166 @@ -export type UpperCaseCharacters = 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z'; +export type UpperCaseCharacters = + | "A" + | "B" + | "C" + | "D" + | "E" + | "F" + | "G" + | "H" + | "I" + | "J" + | "K" + | "L" + | "M" + | "N" + | "O" + | "P" + | "Q" + | "R" + | "S" + | "T" + | "U" + | "V" + | "W" + | "X" + | "Y" + | "Z"; -export type WordSeparators = '-' | '_' | ' '; +export type WordSeparators = "-" | "_" | " "; -export type StringDigit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'; - -export type SplitIncludingDelimiters = - Source extends '' ? [] : - Source extends `${infer FirstPart}${Delimiter}${infer SecondPart}` ? - ( - Source extends `${FirstPart}${infer UsedDelimiter}${SecondPart}` - ? UsedDelimiter extends Delimiter - ? Source extends `${infer FirstPart}${UsedDelimiter}${infer SecondPart}` - ? [...SplitIncludingDelimiters, UsedDelimiter, ...SplitIncludingDelimiters] - : never - : never - : never - ) : - [Source]; +export type StringDigit = + | "0" + | "1" + | "2" + | "3" + | "4" + | "5" + | "6" + | "7" + | "8" + | "9"; +export type SplitIncludingDelimiters< + Source extends string, + Delimiter extends string, +> = Source extends "" ? [] + : Source extends `${infer FirstPart}${Delimiter}${infer SecondPart}` ? ( + Source extends `${FirstPart}${infer UsedDelimiter}${SecondPart}` + ? UsedDelimiter extends Delimiter + ? Source extends `${infer FirstPart}${UsedDelimiter}${infer SecondPart}` + ? [ + ...SplitIncludingDelimiters, + UsedDelimiter, + ...SplitIncludingDelimiters, + ] + : never + : never + : never + ) + : [Source]; type InnerCamelCaseStringArray = - Parts extends [`${infer FirstPart}`, ...infer RemainingParts] - ? FirstPart extends undefined - ? '' - : FirstPart extends '' - ? InnerCamelCaseStringArray - : `${PreviousPart extends '' ? FirstPart : Capitalize}${InnerCamelCaseStringArray}` - : ''; + Parts extends [`${infer FirstPart}`, ...infer RemainingParts] + ? FirstPart extends undefined ? "" + : FirstPart extends "" + ? InnerCamelCaseStringArray + : `${PreviousPart extends "" ? FirstPart + : Capitalize}${InnerCamelCaseStringArray< + RemainingParts, + FirstPart + >}` + : ""; +type CamelCaseStringArray = Parts extends + [`${infer FirstPart}`, ...infer RemainingParts] + ? Uncapitalize< + `${FirstPart}${InnerCamelCaseStringArray}` + > + : never; -type CamelCaseStringArray = - Parts extends [`${infer FirstPart}`, ...infer RemainingParts] - ? Uncapitalize<`${FirstPart}${InnerCamelCaseStringArray}`> - : never; +type StringPartToDelimiterCase< + StringPart extends string, + UsedWordSeparators extends string, + UsedUpperCaseCharacters extends string, + Delimiter extends string, +> = StringPart extends UsedWordSeparators ? Delimiter + : StringPart extends UsedUpperCaseCharacters + ? `${Delimiter}${Lowercase}` + : StringPart; -type StringPartToDelimiterCase = - StringPart extends UsedWordSeparators ? Delimiter : - StringPart extends UsedUpperCaseCharacters ? `${Delimiter}${Lowercase}` : - StringPart; +type StringArrayToDelimiterCase< + Parts extends any[], + UsedWordSeparators extends string, + UsedUpperCaseCharacters extends string, + Delimiter extends string, +> = Parts extends [`${infer FirstPart}`, ...infer RemainingParts] + ? `${StringPartToDelimiterCase< + FirstPart, + UsedWordSeparators, + UsedUpperCaseCharacters, + Delimiter + >}${StringArrayToDelimiterCase< + RemainingParts, + UsedWordSeparators, + UsedUpperCaseCharacters, + Delimiter + >}` + : ""; -type StringArrayToDelimiterCase = - Parts extends [`${infer FirstPart}`, ...infer RemainingParts] - ? `${StringPartToDelimiterCase}${StringArrayToDelimiterCase}` - : ''; - -export type DelimiterCase = Value extends string - ? StringArrayToDelimiterCase< - SplitIncludingDelimiters, - WordSeparators, - UpperCaseCharacters, - Delimiter - > - : Value; +export type DelimiterCase = Value extends + string ? StringArrayToDelimiterCase< + SplitIncludingDelimiters, + WordSeparators, + UpperCaseCharacters, + Delimiter +> + : Value; export type DelimiterCasedProperties< - Value, - Delimiter extends string -> = Value extends Function - ? Value - : Value extends Array - ? Value - : { [K in keyof Value as DelimiterCase]: Value[K] }; + Value, + Delimiter extends string, +> = Value extends Function ? Value + : Value extends Array ? Value + : { [K in keyof Value as DelimiterCase]: Value[K] }; export type DelimiterCasedPropertiesDeep< - Value, - Delimiter extends string -> = Value extends Function - ? Value - : Value extends Array - ? Array> - : Value extends Set - ? Set> : { - [K in keyof Value as DelimiterCase< - K, - Delimiter - >]: DelimiterCasedPropertiesDeep; - }; + Value, + Delimiter extends string, +> = Value extends Function ? Value + : Value extends Array + ? Array> + : Value extends Set ? Set> + : { + [ + K in keyof Value as DelimiterCase< + K, + Delimiter + > + ]: DelimiterCasedPropertiesDeep; + }; -export type SnakeCase = DelimiterCase; +export type SnakeCase = DelimiterCase; -export type CamelCase = K extends string ? CamelCaseStringArray> : K; +export type CamelCase = K extends string + ? CamelCaseStringArray> + : K; -export type SnakeCasedProperties = DelimiterCasedProperties; +export type SnakeCasedProperties = DelimiterCasedProperties; -export type CamelCasedProperties = Value extends Function - ? Value - : Value extends Array - ? Value - : { - [K in keyof Value as CamelCase]: Value[K]; - }; +export type CamelCasedProperties = Value extends Function ? Value + : Value extends Array ? Value + : { + [K in keyof Value as CamelCase]: Value[K]; + }; -export type SnakeCasedPropertiesDeep = DelimiterCasedPropertiesDeep; +export type SnakeCasedPropertiesDeep = DelimiterCasedPropertiesDeep< + Value, + "_" +>; -export type CamelCasedPropertiesDeep = Value extends Function - ? Value - : Value extends Array - ? Array> - : Value extends Set - ? Set> : { - [K in keyof Value as CamelCase]: CamelCasedPropertiesDeep; - }; +export type CamelCasedPropertiesDeep = Value extends Function ? Value + : Value extends Array ? Array> + : Value extends Set ? Set> + : { + [K in keyof Value as CamelCase]: CamelCasedPropertiesDeep; + }; diff --git a/src/types/voice/update_voice_state.ts b/src/types/voice/update_voice_state.ts index 1865e00df..9a4c5c927 100644 --- a/src/types/voice/update_voice_state.ts +++ b/src/types/voice/update_voice_state.ts @@ -12,4 +12,6 @@ export interface UpdateVoiceState { } /** https://discord.com/developers/docs/topics/gateway#update-voice-state */ -export type DiscordUpdateVoiceState = SnakeCasedPropertiesDeep; +export type DiscordUpdateVoiceState = SnakeCasedPropertiesDeep< + UpdateVoiceState +>; diff --git a/src/types/voice/voice_server_update.ts b/src/types/voice/voice_server_update.ts index 8eab8240e..ec3485e92 100644 --- a/src/types/voice/voice_server_update.ts +++ b/src/types/voice/voice_server_update.ts @@ -10,4 +10,6 @@ export interface VoiceServerUpdate { } /** https://discord.com/developers/docs/topics/gateway#voice-server-update */ -export type DiscordVoiceServerUpdate = SnakeCasedPropertiesDeep; +export type DiscordVoiceServerUpdate = SnakeCasedPropertiesDeep< + VoiceServerUpdate +>; diff --git a/src/types/webhooks/edit_webhook_message.ts b/src/types/webhooks/edit_webhook_message.ts index b8c247832..78c9ac5eb 100644 --- a/src/types/webhooks/edit_webhook_message.ts +++ b/src/types/webhooks/edit_webhook_message.ts @@ -12,4 +12,6 @@ export interface EditWebhookMessage { } /** https://discord.com/developers/docs/resources/webhook#edit-webhook-message-jsonform-params */ -export type DiscordEditWebhookMessage = SnakeCasedPropertiesDeep; +export type DiscordEditWebhookMessage = SnakeCasedPropertiesDeep< + EditWebhookMessage +>; diff --git a/src/util/utils.ts b/src/util/utils.ts index 9dfab8dc0..4d97a83bf 100644 --- a/src/util/utils.ts +++ b/src/util/utils.ts @@ -11,7 +11,7 @@ export const sleep = (timeout: number) => { }; export function editBotStatus( - data: Pick + data: Pick, ) { ws.shards.forEach((shard) => { shard.ws.send( @@ -22,7 +22,7 @@ export function editBotStatus( afk: false, ...data, }, - }) + }), ); }); } @@ -51,11 +51,10 @@ export function delay(ms: number): Promise { export const formatImageURL = ( url: string, size: DiscordImageSize = 128, - format?: DiscordImageFormat + format?: DiscordImageFormat, ) => { - return `${url}.${ - format || (url.includes("/a_") ? "gif" : "jpg") - }?size=${size}`; + return `${url}.${format || + (url.includes("/a_") ? "gif" : "jpg")}?size=${size}`; }; function camelToSnakeCase(text: string) { @@ -63,8 +62,9 @@ function camelToSnakeCase(text: string) { } function snakeToCamelCase(text: string) { - return text.replace(/([-_][a-z])/gi, ($1) => - $1.toUpperCase().replace("_", "") + return text.replace( + /([-_][a-z])/gi, + ($1) => $1.toUpperCase().replace("_", ""), ); } @@ -76,7 +76,7 @@ function isObject(obj: unknown) { // deno-lint-ignore no-explicit-any export function camelKeysToSnakeCase( - obj: Record | Record[] + obj: Record | Record[], ): T { if (isObject(obj)) { // deno-lint-ignore no-explicit-any @@ -84,7 +84,7 @@ export function camelKeysToSnakeCase( Object.keys(obj).forEach((key) => { convertedObject[camelToSnakeCase(key)] = camelKeysToSnakeCase( - (obj as Record)[key] + (obj as Record)[key], ); }); @@ -98,7 +98,7 @@ export function camelKeysToSnakeCase( // deno-lint-ignore no-explicit-any export function snakeKeysToCamelCase( - obj: Record | Record[] + obj: Record | Record[], ): T { if (isObject(obj)) { // deno-lint-ignore no-explicit-any @@ -106,7 +106,7 @@ export function snakeKeysToCamelCase( Object.keys(obj).forEach((key) => { convertedObject[snakeToCamelCase(key)] = snakeKeysToCamelCase( - (obj as Record)[key] + (obj as Record)[key], ); }); @@ -121,7 +121,7 @@ export function snakeKeysToCamelCase( /** @private */ function validateSlashOptionChoices( choices: SlashCommandOptionChoice[], - optionType: SlashCommandOptionType + optionType: SlashCommandOptionType, ) { for (const choice of choices) { if ([...choice.name].length < 1 || [...choice.name].length > 100) { @@ -171,7 +171,7 @@ function validateSlashOptions(options: SlashCommandOption[]) { /** @private */ export function validateSlashCommands( commands: UpsertSlashCommandOptions[], - create = false + create = false, ) { for (const command of commands) { if ( diff --git a/src/ws/cleanup_loading_shards.ts b/src/ws/cleanup_loading_shards.ts index af2acf387..d5e0e9c4e 100644 --- a/src/ws/cleanup_loading_shards.ts +++ b/src/ws/cleanup_loading_shards.ts @@ -10,7 +10,7 @@ export async function cleanupLoadingShards() { if (now < loadingShard.startedAt + 60000) return; loadingShard.reject( - `[Identify Failure] Shard ${loadingShard.shardId} has not received READY event in over a minute.` + `[Identify Failure] Shard ${loadingShard.shardId} has not received READY event in over a minute.`, ); }); diff --git a/src/ws/create_shard.ts b/src/ws/create_shard.ts index 8982be351..a5c503356 100644 --- a/src/ws/create_shard.ts +++ b/src/ws/create_shard.ts @@ -19,7 +19,7 @@ export async function createShard(shardId: number) { if ( event.code === 4009 && ["Resharded!", "Resuming the shard, closing old shard."].includes( - event.reason + event.reason, ) ) { return ws.log("CLOSED_RECONNECT", { shardId, payload: event }); @@ -43,7 +43,7 @@ export async function createShard(shardId: number) { case 4013: case 4014: throw new Error( - event.reason || "Discord gave no reason! GG! You broke Discord!" + event.reason || "Discord gave no reason! GG! You broke Discord!", ); // THESE ERRORS CAN NO BE RESUMED! THEY MUST RE-IDENTIFY! case 4003: diff --git a/src/ws/handle_on_message.ts b/src/ws/handle_on_message.ts index 1a202fd75..1263bbc31 100644 --- a/src/ws/handle_on_message.ts +++ b/src/ws/handle_on_message.ts @@ -15,8 +15,10 @@ export async function handleOnMessage(message: any, shardId: number) { } if (message instanceof Uint8Array) { - message = decompressWith(message, 0, (slice: Uint8Array) => - ws.utf8decoder.decode(slice) + message = decompressWith( + message, + 0, + (slice: Uint8Array) => ws.utf8decoder.decode(slice), ); } @@ -29,7 +31,7 @@ export async function handleOnMessage(message: any, shardId: number) { case DiscordGatewayOpcodes.Hello: ws.heartbeat( shardId, - (messageData.d as DiscordHeartbeat).heartbeat_interval + (messageData.d as DiscordHeartbeat).heartbeat_interval, ); break; case DiscordGatewayOpcodes.HeartbeatACK: diff --git a/src/ws/identify.ts b/src/ws/identify.ts index 90ae0da23..368c60c44 100644 --- a/src/ws/identify.ts +++ b/src/ws/identify.ts @@ -32,7 +32,7 @@ export async function identify(shardId: number, maxShards: number) { JSON.stringify({ op: DiscordGatewayOpcodes.Identify, d: { ...ws.identifyPayload, shard: [shardId, maxShards] }, - }) + }), ); }; diff --git a/src/ws/start_gateway.ts b/src/ws/start_gateway.ts index afb51f02f..90ab27670 100644 --- a/src/ws/start_gateway.ts +++ b/src/ws/start_gateway.ts @@ -22,9 +22,13 @@ export async function startGateway(options: StartGatewayOptions) { // setInterval(ws.resharder, 1000 * 60 * 60); ws.identifyPayload.intents = options.intents.reduce( - (bits, next) => - (bits |= typeof next === "string" ? DiscordGatewayIntents[next] : next), - 0 + ( + bits, + next, + ) => (bits |= typeof next === "string" + ? DiscordGatewayIntents[next] + : next), + 0, ); const data = (await fetch(`https://discord.com/api/gateway/bot`, { diff --git a/src/ws/tell_cluster_to_identify.ts b/src/ws/tell_cluster_to_identify.ts index a801270a3..d1c4e25e7 100644 --- a/src/ws/tell_cluster_to_identify.ts +++ b/src/ws/tell_cluster_to_identify.ts @@ -4,7 +4,7 @@ import { ws } from "./ws.ts"; export async function tellClusterToIdentify( workerId: number, shardId: number, - bucketId: number + bucketId: number, ) { // When resharding this may exist already const oldShard = ws.shards.get(shardId);