mirror of
https://github.com/discordeno/discordeno.git
synced 2026-05-31 07:50:07 +00:00
deno fmt
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -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<Role>;
|
||||
oldValue: Partial<Role>;
|
||||
key: "$add" | "$remove";
|
||||
}
|
||||
newValue: Partial<Role>;
|
||||
oldValue: Partial<Role>;
|
||||
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<AuditLogChangeValue>;
|
||||
export type DiscordAuditLogChangeValue = SnakeCasedPropertiesDeep<
|
||||
AuditLogChangeValue
|
||||
>;
|
||||
|
||||
@@ -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<GetGuildAuditLog>;
|
||||
export type DiscordGetGuildAuditLog = SnakeCasedPropertiesDeep<
|
||||
GetGuildAuditLog
|
||||
>;
|
||||
|
||||
@@ -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<OptionalAuditEntryInfo>;
|
||||
export type DiscordOptionalAuditEntryInfo = SnakeCasedPropertiesDeep<
|
||||
OptionalAuditEntryInfo
|
||||
>;
|
||||
|
||||
@@ -10,4 +10,6 @@ export interface ChannelPinsUpdate {
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/topics/gateway#channel-pins-update */
|
||||
export type DiscordChannelPinsUpdate = SnakeCasedPropertiesDeep<ChannelPinsUpdate>;
|
||||
export type DiscordChannelPinsUpdate = SnakeCasedPropertiesDeep<
|
||||
ChannelPinsUpdate
|
||||
>;
|
||||
|
||||
@@ -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<ModifyChannel, "permissionOverwrites">
|
||||
> {
|
||||
permission_overwrites?: DiscordOverwrite[];
|
||||
|
||||
@@ -9,4 +9,6 @@ export interface GuildEmojisUpdate {
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/topics/gateway#guild-emojis-update */
|
||||
export type DiscordGuildEmojisUpdate = SnakeCasedPropertiesDeep<GuildEmojisUpdate>;
|
||||
export type DiscordGuildEmojisUpdate = SnakeCasedPropertiesDeep<
|
||||
GuildEmojisUpdate
|
||||
>;
|
||||
|
||||
@@ -12,4 +12,6 @@ export interface SessionStartLimit {
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/topics/gateway#session-start-limit-object */
|
||||
export type DiscordSessionStartLimit = SnakeCasedPropertiesDeep<SessionStartLimit>;
|
||||
export type DiscordSessionStartLimit = SnakeCasedPropertiesDeep<
|
||||
SessionStartLimit
|
||||
>;
|
||||
|
||||
@@ -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<CreateGuildChannel, "permissionOverwrites">
|
||||
> {
|
||||
permission_overwrites: DiscordOverwrite[];
|
||||
|
||||
@@ -8,4 +8,6 @@ export interface GetGuildPruneCountQuery {
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/resources/guild#get-guild-prune-count */
|
||||
export type DiscordGetGuildPruneCountQuery = SnakeCasedPropertiesDeep<GetGuildPruneCountQuery>;
|
||||
export type DiscordGetGuildPruneCountQuery = SnakeCasedPropertiesDeep<
|
||||
GetGuildPruneCountQuery
|
||||
>;
|
||||
|
||||
@@ -9,4 +9,6 @@ export interface GuildBanAddRemove {
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/topics/gateway#guild-ban-add */
|
||||
export type DiscordGuildBanAddRemove = SnakeCasedPropertiesDeep<GuildBanAddRemove>;
|
||||
export type DiscordGuildBanAddRemove = SnakeCasedPropertiesDeep<
|
||||
GuildBanAddRemove
|
||||
>;
|
||||
|
||||
@@ -14,4 +14,6 @@ export interface ModifyGuildMember {
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/resources/guild#modify-guild-member */
|
||||
export type DiscordModifyGuildMember = SnakeCasedPropertiesDeep<ModifyGuildMember>;
|
||||
export type DiscordModifyGuildMember = SnakeCasedPropertiesDeep<
|
||||
ModifyGuildMember
|
||||
>;
|
||||
|
||||
@@ -16,4 +16,6 @@ export interface RequestGuildMembers {
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/topics/gateway#request-guild-members */
|
||||
export type DiscordRequestGuildMembers = SnakeCasedPropertiesDeep<RequestGuildMembers>;
|
||||
export type DiscordRequestGuildMembers = SnakeCasedPropertiesDeep<
|
||||
RequestGuildMembers
|
||||
>;
|
||||
|
||||
@@ -4,4 +4,6 @@ import { Guild } from "./guild.ts";
|
||||
export type UnavailableGuild = Pick<Guild, "id" | "unavailable">;
|
||||
|
||||
/** https://discord.com/developers/docs/resources/guild#unavailable-guild-object */
|
||||
export type DiscordUnavailableGuild = SnakeCasedPropertiesDeep<UnavailableGuild>;
|
||||
export type DiscordUnavailableGuild = SnakeCasedPropertiesDeep<
|
||||
UnavailableGuild
|
||||
>;
|
||||
|
||||
@@ -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<WelcomeScreenChannel>;
|
||||
export type DiscordWelcomeScreenChannel = SnakeCasedPropertiesDeep<
|
||||
WelcomeScreenChannel
|
||||
>;
|
||||
|
||||
@@ -6,4 +6,6 @@ export interface GuildIntegrationsUpdate {
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/topics/gateway#guild-integrations-update */
|
||||
export type DiscordGuildIntegrationsUpdate = SnakeCasedPropertiesDeep<GuildIntegrationsUpdate>;
|
||||
export type DiscordGuildIntegrationsUpdate = SnakeCasedPropertiesDeep<
|
||||
GuildIntegrationsUpdate
|
||||
>;
|
||||
|
||||
@@ -17,4 +17,6 @@ export interface IntegrationApplication {
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/resources/guild#integration-application-object-integration-application-structure */
|
||||
export type DiscordIntegrationApplication = SnakeCasedPropertiesDeep<IntegrationApplication>;
|
||||
export type DiscordIntegrationApplication = SnakeCasedPropertiesDeep<
|
||||
IntegrationApplication
|
||||
>;
|
||||
|
||||
@@ -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<IntegrationCreateUpdate>;
|
||||
export type DiscordIntegrationCreateUpdate = SnakeCasedPropertiesDeep<
|
||||
IntegrationCreateUpdate
|
||||
>;
|
||||
|
||||
@@ -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<IntegrationDelete>;
|
||||
export type DiscordIntegrationDelete = SnakeCasedPropertiesDeep<
|
||||
IntegrationDelete
|
||||
>;
|
||||
|
||||
@@ -10,4 +10,6 @@ export interface ModifyGuildIntegration {
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/resources/guild#modify-guild-integration-json-params */
|
||||
export type DiscordModifyGuildIntegration = SnakeCasedPropertiesDeep<ModifyGuildIntegration>;
|
||||
export type DiscordModifyGuildIntegration = SnakeCasedPropertiesDeep<
|
||||
ModifyGuildIntegration
|
||||
>;
|
||||
|
||||
@@ -15,4 +15,6 @@ export interface ApplicationCommand {
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/interactions/slash-commands#applicationcommand */
|
||||
export type DiscordApplicationCommand = SnakeCasedPropertiesDeep<ApplicationCommand>;
|
||||
export type DiscordApplicationCommand = SnakeCasedPropertiesDeep<
|
||||
ApplicationCommand
|
||||
>;
|
||||
|
||||
@@ -16,4 +16,5 @@ export interface InteractionApplicationCommandCallbackData {
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/interactions/slash-commands#interaction-response-interactionapplicationcommandcallbackdata */
|
||||
export type DiscordInteractionApplicationCommandCallbackData = SnakeCasedPropertiesDeep<InteractionApplicationCommandCallbackData>;
|
||||
export type DiscordInteractionApplicationCommandCallbackData =
|
||||
SnakeCasedPropertiesDeep<InteractionApplicationCommandCallbackData>;
|
||||
|
||||
@@ -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<ApplicationCommandCreateUpdateDelete>;
|
||||
export type DiscordApplicationCommandCreateUpdateDelete =
|
||||
SnakeCasedPropertiesDeep<ApplicationCommandCreateUpdateDelete>;
|
||||
|
||||
@@ -11,4 +11,6 @@ export interface ApplicationCommandInteractionData {
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/interactions/slash-commands#interaction-applicationcommandinteractiondata */
|
||||
export type DiscordApplicationCommandInteractionData = SnakeCasedPropertiesDeep<ApplicationCommandInteractionData>;
|
||||
export type DiscordApplicationCommandInteractionData = SnakeCasedPropertiesDeep<
|
||||
ApplicationCommandInteractionData
|
||||
>;
|
||||
|
||||
@@ -11,4 +11,5 @@ export interface ApplicationCommandInteractionDataOption {
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/interactions/slash-commands#interaction-applicationcommandinteractiondataoption */
|
||||
export type DiscordApplicationCommandInteractionDataOption = SnakeCasedPropertiesDeep<ApplicationCommandInteractionDataOption>;
|
||||
export type DiscordApplicationCommandInteractionDataOption =
|
||||
SnakeCasedPropertiesDeep<ApplicationCommandInteractionDataOption>;
|
||||
|
||||
@@ -18,4 +18,6 @@ export interface ApplicationCommandOption {
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/interactions/slash-commands#applicationcommandoption */
|
||||
export type DiscordApplicationCommandOption = SnakeCasedPropertiesDeep<ApplicationCommandOption>;
|
||||
export type DiscordApplicationCommandOption = SnakeCasedPropertiesDeep<
|
||||
ApplicationCommandOption
|
||||
>;
|
||||
|
||||
@@ -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<CreateGlobalApplicationCommand>;
|
||||
export type DiscordCreateGlobalApplicationCommand = SnakeCasedPropertiesDeep<
|
||||
CreateGlobalApplicationCommand
|
||||
>;
|
||||
|
||||
@@ -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<CreateGuildApplicationCommand>;
|
||||
export type DiscordCreateGuildApplicationCommand = SnakeCasedPropertiesDeep<
|
||||
CreateGuildApplicationCommand
|
||||
>;
|
||||
|
||||
@@ -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<EditGlobalApplicationCommand>;
|
||||
export type DiscordEditGlobalApplicationCommand = SnakeCasedPropertiesDeep<
|
||||
EditGlobalApplicationCommand
|
||||
>;
|
||||
|
||||
@@ -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<EditGuildApplicationCommand>;
|
||||
export type DiscordEditGuildApplicationCommand = SnakeCasedPropertiesDeep<
|
||||
EditGuildApplicationCommand
|
||||
>;
|
||||
|
||||
@@ -7,4 +7,6 @@ export interface InteractionGuildMember extends GuildMember {
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/resources/guild#guild-member-object */
|
||||
export type DiscordInteractionGuildMember = SnakeCasedPropertiesDeep<InteractionGuildMember>;
|
||||
export type DiscordInteractionGuildMember = SnakeCasedPropertiesDeep<
|
||||
InteractionGuildMember
|
||||
>;
|
||||
|
||||
@@ -10,4 +10,6 @@ export interface InteractionResponse {
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/interactions/slash-commands#interaction-response */
|
||||
export type DiscordInteractionResponse = SnakeCasedPropertiesDeep<InteractionResponse>;
|
||||
export type DiscordInteractionResponse = SnakeCasedPropertiesDeep<
|
||||
InteractionResponse
|
||||
>;
|
||||
|
||||
@@ -14,4 +14,6 @@ export interface MessageInteraction {
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/interactions/slash-commands#messageinteraction */
|
||||
export type DiscordMessageInteraction = SnakeCasedPropertiesDeep<MessageInteraction>;
|
||||
export type DiscordMessageInteraction = SnakeCasedPropertiesDeep<
|
||||
MessageInteraction
|
||||
>;
|
||||
|
||||
@@ -9,4 +9,6 @@ export interface GuildMemberRemove {
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/topics/gateway#guild-member-remove */
|
||||
export type DiscordGuildMemberRemove = SnakeCasedPropertiesDeep<GuildMemberRemove>;
|
||||
export type DiscordGuildMemberRemove = SnakeCasedPropertiesDeep<
|
||||
GuildMemberRemove
|
||||
>;
|
||||
|
||||
@@ -19,4 +19,6 @@ export interface GuildMemberUpdate {
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/topics/gateway#guild-member-update */
|
||||
export type DiscordGuildMemberUpdate = SnakeCasedPropertiesDeep<GuildMemberUpdate>;
|
||||
export type DiscordGuildMemberUpdate = SnakeCasedPropertiesDeep<
|
||||
GuildMemberUpdate
|
||||
>;
|
||||
|
||||
@@ -20,4 +20,6 @@ export interface GuildMembersChunk {
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/topics/gateway#guild-members-chunk */
|
||||
export type DiscordGuildMembersChunk = SnakeCasedPropertiesDeep<GuildMembersChunk>;
|
||||
export type DiscordGuildMembersChunk = SnakeCasedPropertiesDeep<
|
||||
GuildMembersChunk
|
||||
>;
|
||||
|
||||
@@ -13,4 +13,6 @@ export interface MessageApplication {
|
||||
name: string;
|
||||
}
|
||||
|
||||
export type DiscordMessageApplication = SnakeCasedPropertiesDeep<MessageApplication>;
|
||||
export type DiscordMessageApplication = SnakeCasedPropertiesDeep<
|
||||
MessageApplication
|
||||
>;
|
||||
|
||||
@@ -10,4 +10,6 @@ export interface MessageDeleteBulk {
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/topics/gateway#message-delete-bulk */
|
||||
export type DiscordMessageDeleteBulk = SnakeCasedPropertiesDeep<MessageDeleteBulk>;
|
||||
export type DiscordMessageDeleteBulk = SnakeCasedPropertiesDeep<
|
||||
MessageDeleteBulk
|
||||
>;
|
||||
|
||||
@@ -18,4 +18,6 @@ export interface MessageReactionAdd {
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/topics/gateway#message-reaction-add */
|
||||
export type DiscordMessageReactionAdd = SnakeCasedPropertiesDeep<MessageReactionAdd>;
|
||||
export type DiscordMessageReactionAdd = SnakeCasedPropertiesDeep<
|
||||
MessageReactionAdd
|
||||
>;
|
||||
|
||||
@@ -4,4 +4,6 @@ import { MessageReactionAdd } from "./message_reaction_add.ts";
|
||||
export type MessageReactionRemove = Omit<MessageReactionAdd, "member">;
|
||||
|
||||
/** https://discord.com/developers/docs/topics/gateway#message-reaction-remove */
|
||||
export type DiscordMessageReactionRemove = SnakeCasedPropertiesDeep<MessageReactionRemove>;
|
||||
export type DiscordMessageReactionRemove = SnakeCasedPropertiesDeep<
|
||||
MessageReactionRemove
|
||||
>;
|
||||
|
||||
@@ -7,4 +7,6 @@ export type MessageReactionRemoveAll = Pick<
|
||||
>;
|
||||
|
||||
/** https://discord.com/developers/docs/topics/gateway#message-reaction-remove-all */
|
||||
export type DiscordMessageReactionRemoveAll = SnakeCasedPropertiesDeep<MessageReactionRemoveAll>;
|
||||
export type DiscordMessageReactionRemoveAll = SnakeCasedPropertiesDeep<
|
||||
MessageReactionRemoveAll
|
||||
>;
|
||||
|
||||
@@ -7,4 +7,6 @@ export type MessageReactionRemoveEmoji = Pick<
|
||||
>;
|
||||
|
||||
/** https://discord.com/developers/docs/topics/gateway#message-reaction-remove-emoji */
|
||||
export type DiscordMessageReactionRemoveEmoji = SnakeCasedPropertiesDeep<MessageReactionRemoveEmoji>;
|
||||
export type DiscordMessageReactionRemoveEmoji = SnakeCasedPropertiesDeep<
|
||||
MessageReactionRemoveEmoji
|
||||
>;
|
||||
|
||||
@@ -15,4 +15,6 @@ export interface MessageReference {
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/resources/channel#message-object-message-reference-structure */
|
||||
export type DiscordMessageReference = SnakeCasedPropertiesDeep<MessageReference>;
|
||||
export type DiscordMessageReference = SnakeCasedPropertiesDeep<
|
||||
MessageReference
|
||||
>;
|
||||
|
||||
@@ -15,4 +15,6 @@ export interface BotAuthenticationFlowQuery {
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/topics/oauth2#bot-authorization-flow-bot-auth-parameters */
|
||||
export type DiscordBotAuthenticationFlowQuery = SnakeCasedPropertiesDeep<BotAuthenticationFlowQuery>;
|
||||
export type DiscordBotAuthenticationFlowQuery = SnakeCasedPropertiesDeep<
|
||||
BotAuthenticationFlowQuery
|
||||
>;
|
||||
|
||||
@@ -15,4 +15,6 @@ export interface GetCurrentAuthorizationInformation {
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/topics/oauth2#get-current-authorization-information-response-structure */
|
||||
export type DiscordGetCurrentAuthoriationInformation = SnakeCasedPropertiesDeep<GetCurrentAuthorizationInformation>;
|
||||
export type DiscordGetCurrentAuthoriationInformation = SnakeCasedPropertiesDeep<
|
||||
GetCurrentAuthorizationInformation
|
||||
>;
|
||||
|
||||
@@ -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<User> &
|
||||
Pick<User, "avatar" | "discriminator" | "id" | "username">;
|
||||
user:
|
||||
& Partial<User>
|
||||
& Pick<User, "avatar" | "discriminator" | "id" | "username">;
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/topics/teams#data-models-team-members-object */
|
||||
|
||||
@@ -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 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<FirstPart, Delimiter>, UsedDelimiter, ...SplitIncludingDelimiters<SecondPart, Delimiter>]
|
||||
: 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<FirstPart, Delimiter>,
|
||||
UsedDelimiter,
|
||||
...SplitIncludingDelimiters<SecondPart, Delimiter>,
|
||||
]
|
||||
: never
|
||||
: never
|
||||
: never
|
||||
)
|
||||
: [Source];
|
||||
|
||||
type InnerCamelCaseStringArray<Parts extends any[], PreviousPart> =
|
||||
Parts extends [`${infer FirstPart}`, ...infer RemainingParts]
|
||||
? FirstPart extends undefined
|
||||
? ''
|
||||
: FirstPart extends ''
|
||||
? InnerCamelCaseStringArray<RemainingParts, PreviousPart>
|
||||
: `${PreviousPart extends '' ? FirstPart : Capitalize<FirstPart>}${InnerCamelCaseStringArray<RemainingParts, FirstPart>}`
|
||||
: '';
|
||||
Parts extends [`${infer FirstPart}`, ...infer RemainingParts]
|
||||
? FirstPart extends undefined ? ""
|
||||
: FirstPart extends ""
|
||||
? InnerCamelCaseStringArray<RemainingParts, PreviousPart>
|
||||
: `${PreviousPart extends "" ? FirstPart
|
||||
: Capitalize<FirstPart>}${InnerCamelCaseStringArray<
|
||||
RemainingParts,
|
||||
FirstPart
|
||||
>}`
|
||||
: "";
|
||||
|
||||
type CamelCaseStringArray<Parts extends string[]> = Parts extends
|
||||
[`${infer FirstPart}`, ...infer RemainingParts]
|
||||
? Uncapitalize<
|
||||
`${FirstPart}${InnerCamelCaseStringArray<RemainingParts, FirstPart>}`
|
||||
>
|
||||
: never;
|
||||
|
||||
type CamelCaseStringArray<Parts extends string[]> =
|
||||
Parts extends [`${infer FirstPart}`, ...infer RemainingParts]
|
||||
? Uncapitalize<`${FirstPart}${InnerCamelCaseStringArray<RemainingParts, FirstPart>}`>
|
||||
: 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>}`
|
||||
: StringPart;
|
||||
|
||||
type StringPartToDelimiterCase<StringPart extends string, UsedWordSeparators extends string, UsedUpperCaseCharacters extends string, Delimiter extends string> =
|
||||
StringPart extends UsedWordSeparators ? Delimiter :
|
||||
StringPart extends UsedUpperCaseCharacters ? `${Delimiter}${Lowercase<StringPart>}` :
|
||||
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 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>}`
|
||||
: '';
|
||||
|
||||
export type DelimiterCase<Value, Delimiter extends string> = Value extends string
|
||||
? StringArrayToDelimiterCase<
|
||||
SplitIncludingDelimiters<Value, WordSeparators | UpperCaseCharacters>,
|
||||
WordSeparators,
|
||||
UpperCaseCharacters,
|
||||
Delimiter
|
||||
>
|
||||
: Value;
|
||||
export type DelimiterCase<Value, Delimiter extends string> = Value extends
|
||||
string ? StringArrayToDelimiterCase<
|
||||
SplitIncludingDelimiters<Value, WordSeparators | UpperCaseCharacters>,
|
||||
WordSeparators,
|
||||
UpperCaseCharacters,
|
||||
Delimiter
|
||||
>
|
||||
: Value;
|
||||
|
||||
export type DelimiterCasedProperties<
|
||||
Value,
|
||||
Delimiter extends string
|
||||
> = Value extends Function
|
||||
? Value
|
||||
: Value extends Array<infer U>
|
||||
? Value
|
||||
: { [K in keyof Value as DelimiterCase<K, Delimiter>]: Value[K] };
|
||||
Value,
|
||||
Delimiter extends string,
|
||||
> = Value extends Function ? Value
|
||||
: Value extends Array<infer U> ? Value
|
||||
: { [K in keyof Value as DelimiterCase<K, Delimiter>]: Value[K] };
|
||||
|
||||
export type DelimiterCasedPropertiesDeep<
|
||||
Value,
|
||||
Delimiter extends string
|
||||
> = Value extends Function
|
||||
? Value
|
||||
: Value extends Array<infer U>
|
||||
? Array<DelimiterCasedPropertiesDeep<U, Delimiter>>
|
||||
: Value extends Set<infer U>
|
||||
? Set<DelimiterCasedPropertiesDeep<U, Delimiter>> : {
|
||||
[K in keyof Value as DelimiterCase<
|
||||
K,
|
||||
Delimiter
|
||||
>]: DelimiterCasedPropertiesDeep<Value[K], Delimiter>;
|
||||
};
|
||||
Value,
|
||||
Delimiter extends string,
|
||||
> = Value extends Function ? Value
|
||||
: Value extends Array<infer U>
|
||||
? Array<DelimiterCasedPropertiesDeep<U, Delimiter>>
|
||||
: Value extends Set<infer U> ? Set<DelimiterCasedPropertiesDeep<U, Delimiter>>
|
||||
: {
|
||||
[
|
||||
K in keyof Value as DelimiterCase<
|
||||
K,
|
||||
Delimiter
|
||||
>
|
||||
]: DelimiterCasedPropertiesDeep<Value[K], Delimiter>;
|
||||
};
|
||||
|
||||
export type SnakeCase<Value> = DelimiterCase<Value, '_'>;
|
||||
export type SnakeCase<Value> = DelimiterCase<Value, "_">;
|
||||
|
||||
export type CamelCase<K> = K extends string ? CamelCaseStringArray<Split<K, WordSeparators>> : K;
|
||||
export type CamelCase<K> = K extends string
|
||||
? CamelCaseStringArray<Split<K, WordSeparators>>
|
||||
: K;
|
||||
|
||||
export type SnakeCasedProperties<Value> = DelimiterCasedProperties<Value, '_'>;
|
||||
export type SnakeCasedProperties<Value> = DelimiterCasedProperties<Value, "_">;
|
||||
|
||||
export type CamelCasedProperties<Value> = Value extends Function
|
||||
? Value
|
||||
: Value extends Array<infer U>
|
||||
? Value
|
||||
: {
|
||||
[K in keyof Value as CamelCase<K>]: Value[K];
|
||||
};
|
||||
export type CamelCasedProperties<Value> = Value extends Function ? Value
|
||||
: Value extends Array<infer U> ? Value
|
||||
: {
|
||||
[K in keyof Value as CamelCase<K>]: Value[K];
|
||||
};
|
||||
|
||||
export type SnakeCasedPropertiesDeep<Value> = DelimiterCasedPropertiesDeep<Value, '_'>;
|
||||
export type SnakeCasedPropertiesDeep<Value> = DelimiterCasedPropertiesDeep<
|
||||
Value,
|
||||
"_"
|
||||
>;
|
||||
|
||||
export type CamelCasedPropertiesDeep<Value> = Value extends Function
|
||||
? Value
|
||||
: Value extends Array<infer U>
|
||||
? Array<CamelCasedPropertiesDeep<U>>
|
||||
: Value extends Set<infer U>
|
||||
? Set<CamelCasedPropertiesDeep<U>> : {
|
||||
[K in keyof Value as CamelCase<K>]: CamelCasedPropertiesDeep<Value[K]>;
|
||||
};
|
||||
export type CamelCasedPropertiesDeep<Value> = Value extends Function ? Value
|
||||
: Value extends Array<infer U> ? Array<CamelCasedPropertiesDeep<U>>
|
||||
: Value extends Set<infer U> ? Set<CamelCasedPropertiesDeep<U>>
|
||||
: {
|
||||
[K in keyof Value as CamelCase<K>]: CamelCasedPropertiesDeep<Value[K]>;
|
||||
};
|
||||
|
||||
@@ -12,4 +12,6 @@ export interface UpdateVoiceState {
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/topics/gateway#update-voice-state */
|
||||
export type DiscordUpdateVoiceState = SnakeCasedPropertiesDeep<UpdateVoiceState>;
|
||||
export type DiscordUpdateVoiceState = SnakeCasedPropertiesDeep<
|
||||
UpdateVoiceState
|
||||
>;
|
||||
|
||||
@@ -10,4 +10,6 @@ export interface VoiceServerUpdate {
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/topics/gateway#voice-server-update */
|
||||
export type DiscordVoiceServerUpdate = SnakeCasedPropertiesDeep<VoiceServerUpdate>;
|
||||
export type DiscordVoiceServerUpdate = SnakeCasedPropertiesDeep<
|
||||
VoiceServerUpdate
|
||||
>;
|
||||
|
||||
@@ -12,4 +12,6 @@ export interface EditWebhookMessage {
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/resources/webhook#edit-webhook-message-jsonform-params */
|
||||
export type DiscordEditWebhookMessage = SnakeCasedPropertiesDeep<EditWebhookMessage>;
|
||||
export type DiscordEditWebhookMessage = SnakeCasedPropertiesDeep<
|
||||
EditWebhookMessage
|
||||
>;
|
||||
|
||||
@@ -11,7 +11,7 @@ export const sleep = (timeout: number) => {
|
||||
};
|
||||
|
||||
export function editBotStatus(
|
||||
data: Pick<GatewayStatusUpdatePayload, "activities" | "status">
|
||||
data: Pick<GatewayStatusUpdatePayload, "activities" | "status">,
|
||||
) {
|
||||
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<void> {
|
||||
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<T>(
|
||||
obj: Record<string, any> | Record<string, any>[]
|
||||
obj: Record<string, any> | Record<string, any>[],
|
||||
): T {
|
||||
if (isObject(obj)) {
|
||||
// deno-lint-ignore no-explicit-any
|
||||
@@ -84,7 +84,7 @@ export function camelKeysToSnakeCase<T>(
|
||||
|
||||
Object.keys(obj).forEach((key) => {
|
||||
convertedObject[camelToSnakeCase(key)] = camelKeysToSnakeCase(
|
||||
(obj as Record<string, any>)[key]
|
||||
(obj as Record<string, any>)[key],
|
||||
);
|
||||
});
|
||||
|
||||
@@ -98,7 +98,7 @@ export function camelKeysToSnakeCase<T>(
|
||||
|
||||
// deno-lint-ignore no-explicit-any
|
||||
export function snakeKeysToCamelCase<T>(
|
||||
obj: Record<string, any> | Record<string, any>[]
|
||||
obj: Record<string, any> | Record<string, any>[],
|
||||
): T {
|
||||
if (isObject(obj)) {
|
||||
// deno-lint-ignore no-explicit-any
|
||||
@@ -106,7 +106,7 @@ export function snakeKeysToCamelCase<T>(
|
||||
|
||||
Object.keys(obj).forEach((key) => {
|
||||
convertedObject[snakeToCamelCase(key)] = snakeKeysToCamelCase(
|
||||
(obj as Record<string, any>)[key]
|
||||
(obj as Record<string, any>)[key],
|
||||
);
|
||||
});
|
||||
|
||||
@@ -121,7 +121,7 @@ export function snakeKeysToCamelCase<T>(
|
||||
/** @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 (
|
||||
|
||||
@@ -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.`,
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -32,7 +32,7 @@ export async function identify(shardId: number, maxShards: number) {
|
||||
JSON.stringify({
|
||||
op: DiscordGatewayOpcodes.Identify,
|
||||
d: { ...ws.identifyPayload, shard: [shardId, maxShards] },
|
||||
})
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -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`, {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user