diff --git a/src/bot.ts b/src/bot.ts index c1505c1fb..b077dbfc0 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -5,7 +5,6 @@ import { DiscordGatewayIntents } from "./types/gateway/gateway_intents.ts"; import { baseEndpoints, GATEWAY_VERSION } from "./util/constants.ts"; import { ws } from "./ws/ws.ts"; -export let authorization = ""; export let secretKey = ""; export let botId = ""; export let applicationId = ""; @@ -14,21 +13,8 @@ export let eventHandlers: EventHandlers = {}; export let proxyWSURL = `wss://gateway.discord.gg`; -export const identifyPayload = { - token: "", - compress: true, - properties: { - $os: "linux", - $browser: "Discordeno", - $device: "Discordeno", - }, - intents: 0, - shard: [0, 0], -}; - export async function startBot(config: BotConfig) { if (config.eventHandlers) eventHandlers = config.eventHandlers; - authorization = `Bot ${config.token}`; ws.identifyPayload.token = `Bot ${config.token}`; rest.token = `Bot ${config.token}`; ws.identifyPayload.intents = config.intents.reduce( @@ -49,17 +35,6 @@ export async function startBot(config: BotConfig) { ws.botGatewayData.url += `?v=${GATEWAY_VERSION}&encoding=json`; proxyWSURL = ws.botGatewayData.url; - identifyPayload.token = config.token; - identifyPayload.intents = config.intents.reduce( - ( - bits, - next, - ) => (bits |= typeof next === "string" - ? DiscordGatewayIntents[next] - : next), - 0, - ); - identifyPayload.shard = [0, ws.botGatewayData.shards]; ws.spawnShards(); } @@ -91,18 +66,15 @@ export function setApplicationId(id: string) { * Advanced Devs: This function will allow you to have an insane amount of customization potential as when you get to large bots you need to be able to optimize every tiny detail to make you bot work the way you need. */ export async function startBigBrainBot(data: BigBrainBotConfig) { - authorization = `Bot ${data.token}`; - identifyPayload.token = `Bot ${data.token}`; - if (data.secretKey) secretKey = data.secretKey; if (data.restURL) baseEndpoints.BASE_URL = data.restURL; if (data.cdnURL) baseEndpoints.CDN_URL = data.cdnURL; if (data.eventHandlers) eventHandlers = data.eventHandlers; if (data.compress) { - identifyPayload.compress = data.compress; + ws.identifyPayload.compress = data.compress; } - identifyPayload.intents = data.intents.reduce( + ws.identifyPayload.intents = data.intents.reduce( ( bits, next, diff --git a/src/handlers/guilds/GUILD_UPDATE.ts b/src/handlers/guilds/GUILD_UPDATE.ts index 186b40c25..607c16e76 100644 --- a/src/handlers/guilds/GUILD_UPDATE.ts +++ b/src/handlers/guilds/GUILD_UPDATE.ts @@ -30,8 +30,6 @@ export async function handleGuildUpdate(data: DiscordGatewayPayload) { if (Array.isArray(cachedValue) && Array.isArray(value)) { const different = (cachedValue.length !== value.length) || cachedValue.find((val) => !value.includes(val)) || - // TODO: check if this really works hehe - // @ts-ignore typescript thinks that this is not an array value.find((val) => !cachedValue.includes(val)); if (!different) return; } diff --git a/src/helpers/guilds/edit_guild.ts b/src/helpers/guilds/edit_guild.ts index 20df19c47..e17206c00 100644 --- a/src/helpers/guilds/edit_guild.ts +++ b/src/helpers/guilds/edit_guild.ts @@ -1,3 +1,4 @@ +import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { Guild } from "../../types/guilds/guild.ts"; @@ -5,6 +6,7 @@ import { 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"; +import { ws } from "../../ws/ws.ts"; /** Modify a guilds settings. Requires the MANAGE_GUILD permission. */ export async function editGuild(guildId: string, options: ModifyGuild) { @@ -28,6 +30,13 @@ export async function editGuild(guildId: string, options: ModifyGuild) { options, ); - // TODO: use ws.botGatewayData to calculate the shard ID - return structures.createDiscordenoGuild(result, -1); + const cached = await cacheHandlers.get("guilds", guildId); + return structures.createDiscordenoGuild( + result, + cached?.shardId || + Number( + (BigInt(result.id) >> 22n % BigInt(ws.botGatewayData.shards)) + .toString(), + ), + ); } diff --git a/src/helpers/guilds/get_widget.ts b/src/helpers/guilds/get_widget.ts index c685b8088..2e5b4d84a 100644 --- a/src/helpers/guilds/get_widget.ts +++ b/src/helpers/guilds/get_widget.ts @@ -1,5 +1,6 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; +import { GuildWidgetDetails } from "../../types/guilds/guild_widget_details.ts"; import { Errors } from "../../types/misc/errors.ts"; import { endpoints } from "../../util/constants.ts"; @@ -11,6 +12,5 @@ export async function getWidget(guildId: string, options?: { force: boolean }) { if (!guild?.widgetEnabled) throw new Error(Errors.GUILD_WIDGET_NOT_ENABLED); } - // TODO: add return type - return await rest.runMethod("get", `${endpoints.GUILD_WIDGET(guildId)}.json`); + return await rest.runMethod("get", `${endpoints.GUILD_WIDGET(guildId)}.json`) as GuildWidgetDetails; } diff --git a/src/helpers/invites/create_invite.ts b/src/helpers/invites/create_invite.ts index 0c7af679f..0edab07ba 100644 --- a/src/helpers/invites/create_invite.ts +++ b/src/helpers/invites/create_invite.ts @@ -1,6 +1,7 @@ import { rest } from "../../rest/rest.ts"; import { CreateChannelInvite } from "../../types/invites/create_channel_invite.ts"; -import { Invite } from "../../types/mod.ts"; +import { 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"; @@ -11,7 +12,12 @@ export async function createInvite( ) { await requireBotChannelPermissions(channelId, ["CREATE_INSTANT_INVITE"]); - // TODO: add proper options validation + if (options.maxAge && (options.maxAge < 0 || options.maxAge > 604800)) { + throw new Error(Errors.INVITE_MAX_AGE_INVALID); + } + if (options.maxUses && (options.maxUses < 0 || options.maxUses > 100)) { + throw new Error(Errors.INVITE_MAX_USES_INVALID); + } return await rest.runMethod( "post", diff --git a/src/helpers/members/fetch_members.ts b/src/helpers/members/fetch_members.ts index e336d42cf..9a0428aad 100644 --- a/src/helpers/members/fetch_members.ts +++ b/src/helpers/members/fetch_members.ts @@ -1,9 +1,9 @@ -import { identifyPayload } from "../../bot.ts"; import { DiscordenoMember } from "../../structures/member.ts"; import { DiscordGatewayIntents } from "../../types/gateway/gateway_intents.ts"; import { RequestGuildMembers } from "../../types/guilds/request_guild_members.ts"; import { Errors } from "../../types/misc/errors.ts"; import { Collection } from "../../util/collection.ts"; +import { ws } from "../../ws/ws.ts"; /** * ⚠️ BEGINNER DEVS!! YOU SHOULD ALMOST NEVER NEED THIS AND YOU CAN GET FROM cache.members.get() @@ -21,7 +21,7 @@ export function fetchMembers( // You can request 1 member without the intent if ( (!options?.limit || options.limit > 1) && - !(identifyPayload.intents && DiscordGatewayIntents.GUILD_MEMBERS) + !(ws.identifyPayload.intents && DiscordGatewayIntents.GUILD_MEMBERS) ) { 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 e54173b7c..b51fff45a 100644 --- a/src/helpers/members/get_members.ts +++ b/src/helpers/members/get_members.ts @@ -1,4 +1,4 @@ -import { eventHandlers, identifyPayload } from "../../bot.ts"; +import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { DiscordenoMember } from "../../structures/member.ts"; @@ -9,6 +9,7 @@ import { ListGuildMembers } from "../../types/guilds/list_guild_members.ts"; import { Errors } from "../../types/misc/errors.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; +import { ws } from "../../ws/ws.ts"; /** * ⚠️ BEGINNER DEVS!! YOU SHOULD ALMOST NEVER NEED THIS AND YOU CAN GET FROM cache.members.get() @@ -19,7 +20,7 @@ import { endpoints } from "../../util/constants.ts"; * GW(fetchMembers): 120/m(PER shard) rate limit. Meaning if you have 8 shards your limit is 960/m. */ export async function getMembers(guildId: string, options?: ListGuildMembers) { - if (!(identifyPayload.intents && DiscordGatewayIntents.GUILD_MEMBERS)) { + if (!(ws.identifyPayload.intents && DiscordGatewayIntents.GUILD_MEMBERS)) { 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 73d00246f..a15e97881 100644 --- a/src/helpers/messages/send_message.ts +++ b/src/helpers/messages/send_message.ts @@ -3,6 +3,7 @@ import { rest } from "../../rest/rest.ts"; 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 { DiscordMessage, Message } from "../../types/messages/message.ts"; import { Errors } from "../../types/misc/errors.ts"; @@ -11,6 +12,8 @@ import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; import { camelKeysToSnakeCase } 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"; /** Send a message to the channel. Requires SEND_MESSAGES permission. */ export async function sendMessage( @@ -93,6 +96,60 @@ export async function sendMessage( } } + if (content.components?.length) { + let actionRowCounter = 0; + + for (const component of content.components) { + // 5 Link buttons can not have a custom_id + if (isButton(component)) { + if ( + component.type === ButtonStyles.Link && + component.customId + ) { + throw new Error(Errors.LINK_BUTTON_CANNOT_HAVE_CUSTOM_ID); + } + if ( + !component.customId + ) { + if (component.type !== ButtonStyles.Link) { + throw new Error(Errors.BUTTON_REQUIRES_CUSTOM_ID); + } + } + + if (!validateLength(component.label, { max: 80 })) { + throw new Error(Errors.COMPONENT_LABEL_TOO_BIG); + } + + if ( + component.customId && + !validateLength(component.customId, { max: 100 }) + ) { + throw new Error(Errors.COMPONENT_CUSTOM_ID_TOO_BIG); + } + } + + if (!isActionRow(component)) { + continue; + } + + actionRowCounter++; + // Max of 5 ActionRows per message + if (actionRowCounter > 5) throw new Error(Errors.TOO_MANY_ACTION_ROWS); + + // Max of 5 Buttons (or any component type) within an ActionRow + if (component.components?.length > 5) { + throw new Error(Errors.TOO_MANY_COMPONENTS); + } + } + } + + 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), diff --git a/src/helpers/type_guards/is_action_row.ts b/src/helpers/type_guards/is_action_row.ts new file mode 100644 index 000000000..ec9779d1e --- /dev/null +++ b/src/helpers/type_guards/is_action_row.ts @@ -0,0 +1,8 @@ +import { ActionRow } from "../../types/messages/components/action_row.ts"; +import { 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 */ +export function isActionRow(component: MessageComponent): component is ActionRow { + return component.type === MessageComponentTypes.ActionRow +} \ No newline at end of file diff --git a/src/helpers/type_guards/is_button.ts b/src/helpers/type_guards/is_button.ts new file mode 100644 index 000000000..dfe2b92cd --- /dev/null +++ b/src/helpers/type_guards/is_button.ts @@ -0,0 +1,10 @@ +import { ButtonComponent } from "../../types/messages/components/button_component.ts"; +import { 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 */ +export function isButton( + component: MessageComponent, +): component is ButtonComponent { + return component.type === MessageComponentTypes.Button; +} diff --git a/src/types/guilds/guild_widget_details.ts b/src/types/guilds/guild_widget_details.ts new file mode 100644 index 000000000..a0347ee47 --- /dev/null +++ b/src/types/guilds/guild_widget_details.ts @@ -0,0 +1,24 @@ +import { SnakeCasedPropertiesDeep } from "../util.ts"; + +export interface GuildWidgetDetails { + id: string; + name: string; + instantInvite: string; + channels: { + id: string; + name: string; + position: number; + }[]; + members: { + id: string; + username: string; + discriminator: string; + avatar?: string | null; + status: string; + avatar_url: string; + }[]; + presenceCount: number; +} + +/** https://discord.com/developers/docs/resources/guild#get-guild-widget-example-get-guild-widget */ +export type DiscordGuildWidget = SnakeCasedPropertiesDeep; \ No newline at end of file diff --git a/src/types/interactions/application_command_interaction_data.ts b/src/types/interactions/application_command_interaction_data.ts index 5074f1c29..5d7502664 100644 --- a/src/types/interactions/application_command_interaction_data.ts +++ b/src/types/interactions/application_command_interaction_data.ts @@ -4,13 +4,17 @@ import { ApplicationCommandInteractionDataResolved } from "./application_command export interface ApplicationCommandInteractionData { /** The Id of the invoked command */ - id: string; + id?: string; /** The name of the invoked command */ - name: string; + name?: string; /** Converted users + roles + channels */ resolved?: ApplicationCommandInteractionDataResolved; /** The params + values from the user */ options?: ApplicationCommandInteractionDataOption[]; + /** with the value you defined for this component */ + customId?: string; + /** The type of this component */ + componentType?: 2; } /** https://discord.com/developers/docs/interactions/slash-commands#interaction-applicationcommandinteractiondata */ diff --git a/src/types/interactions/interaction.ts b/src/types/interactions/interaction.ts index a2b8b66f7..8578c7f62 100644 --- a/src/types/interactions/interaction.ts +++ b/src/types/interactions/interaction.ts @@ -1,4 +1,5 @@ import { GuildMemberWithUser } from "../guilds/guild_member.ts"; +import { Message } from "../messages/message.ts"; import { User } from "../users/user.ts"; import { SnakeCasedPropertiesDeep } from "../util.ts"; import { ApplicationCommandInteractionData } from "./application_command_interaction_data.ts"; @@ -25,6 +26,8 @@ export interface Interaction { token: string; /** Read-only property, always `1` */ version: 1; + /** for the message the button was attached to */ + message?: Message; } /** https://discord.com/developers/docs/interactions/slash-commands#interaction */ diff --git a/src/types/interactions/interaction_response_types.ts b/src/types/interactions/interaction_response_types.ts index 8a152ad39..122f22995 100644 --- a/src/types/interactions/interaction_response_types.ts +++ b/src/types/interactions/interaction_response_types.ts @@ -6,4 +6,6 @@ export enum DiscordInteractionResponseTypes { ChannelMessageWithSource = 4, /** ACK an interaction and edit a response later, the user sees a loading state */ DeferredChannelMessageWithSource = 5, + /** It has no data fields. You can send this type **only in response to a button interaction .** It will acknowledge the interaction and update the button to a loading state. */ + DeferredMessageUpdate, } diff --git a/src/types/interactions/interaction_types.ts b/src/types/interactions/interaction_types.ts index fe9408744..099c63999 100644 --- a/src/types/interactions/interaction_types.ts +++ b/src/types/interactions/interaction_types.ts @@ -2,4 +2,5 @@ export enum DiscordInteractionTypes { Ping = 1, ApplicationCommand, + Button } diff --git a/src/types/invites/create_channel_invite.ts b/src/types/invites/create_channel_invite.ts index 50ac50762..4271e6984 100644 --- a/src/types/invites/create_channel_invite.ts +++ b/src/types/invites/create_channel_invite.ts @@ -1,7 +1,7 @@ import { DiscordInviteTargetTypes } from "./invite_target_types.ts"; export interface CreateChannelInvite { - /** Durationi of invite in seconds before expiry, or 0 for never. Between 0 and 604800 (7 days). Default: 86400 (24 hours) */ + /** Duration of invite in seconds before expiry, or 0 for never. Between 0 and 604800 (7 days). Default: 86400 (24 hours) */ maxAge?: number; /** Max number of users or 0 for unlimited. Between 0 and 100. Default: 0 */ maxUses?: number; diff --git a/src/types/messages/components/action_row.ts b/src/types/messages/components/action_row.ts new file mode 100644 index 000000000..f00f3fff6 --- /dev/null +++ b/src/types/messages/components/action_row.ts @@ -0,0 +1,11 @@ +import { SnakeCasedPropertiesDeep } from "../../util.ts"; +import { ButtonComponent } from "./button_component.ts"; + +export interface ActionRow { + /** Action rows are a group of buttons. */ + type: 1; + /** The button components */ + components: ButtonComponent[]; +} + +export type DiscordActionRow = SnakeCasedPropertiesDeep; \ No newline at end of file diff --git a/src/types/messages/components/button_component.ts b/src/types/messages/components/button_component.ts new file mode 100644 index 000000000..7bdcc6be7 --- /dev/null +++ b/src/types/messages/components/button_component.ts @@ -0,0 +1,28 @@ +import { SnakeCasedPropertiesDeep } from "../../util.ts"; +import { ButtonStyles } from "./button_styles.ts"; + +export interface ButtonComponent { + /** All button components have type 2 */ + type: 2; + /** for what the button says (max 80 characters) */ + label: string; + /** a dev-defined unique string sent on click (max 100 characters). type 5 Link buttons can not have a custom_id */ + customId?: string; + /** For different styles/colors of the buttons */ + style: ButtonStyles; + /** Emoji object that includes fields of name, id, and animated supporting unicode and custom emojis. */ + emoji?: { + /** Emoji id */ + id: string | null; + /** Emoji name (can only be null in reaction emoji objects) */ + name: string | null; + /** Whether this emoji is animated */ + animated?: boolean; + }; + /** optional url for link-style buttons that can navigate a user to the web. Only type 5 Link buttons can have a url */ + url?: string; + /** Whether or not this button is disabled */ + disabled?: boolean; +} + +export type DiscordButtonComponent = SnakeCasedPropertiesDeep; diff --git a/src/types/messages/components/button_styles.ts b/src/types/messages/components/button_styles.ts new file mode 100644 index 000000000..dae735204 --- /dev/null +++ b/src/types/messages/components/button_styles.ts @@ -0,0 +1,12 @@ +export enum ButtonStyles { + /** A blurple button */ + Primary = 1, + /** A grey button */ + Secondary, + /** A green button */ + Success, + /** A red button */ + Danger, + /** A button that navigates to a URL */ + Link, +} diff --git a/src/types/messages/components/message_component_types.ts b/src/types/messages/components/message_component_types.ts new file mode 100644 index 000000000..aaa89ecb9 --- /dev/null +++ b/src/types/messages/components/message_component_types.ts @@ -0,0 +1,6 @@ +export enum MessageComponentTypes { + /** A row of components at the bottom of a message */ + ActionRow = 1, + /** A button! */ + Button, +} diff --git a/src/types/messages/components/message_components.ts b/src/types/messages/components/message_components.ts new file mode 100644 index 000000000..045b0f75a --- /dev/null +++ b/src/types/messages/components/message_components.ts @@ -0,0 +1,6 @@ +import { ActionRow } from "./action_row.ts"; +import { ButtonComponent } from "./button_component.ts"; + +export type MessageComponent = ActionRow | ButtonComponent; + +export type MessageComponents = MessageComponent[]; diff --git a/src/types/messages/create_message.ts b/src/types/messages/create_message.ts index 1ec41fc32..fa1704f90 100644 --- a/src/types/messages/create_message.ts +++ b/src/types/messages/create_message.ts @@ -3,6 +3,7 @@ import { AllowedMentions } from "../messages/allowed_mentions.ts"; import { MessageReference } from "../messages/message_reference.ts"; import { FileContent } from "../misc/file_content.ts"; import { SnakeCasedPropertiesDeep } from "../util.ts"; +import { MessageComponents } from "./components/message_components.ts"; export interface CreateMessage { /** The message contents (up to 2000 characters) */ @@ -19,6 +20,8 @@ export interface CreateMessage { messageReference?: MessageReference; /** The contents of the file being sent */ file?: FileContent | FileContent[]; + /** The components you would like to have sent in this message */ + components?: MessageComponents; } /** https://discord.com/developers/docs/resources/channel#create-message */ diff --git a/src/types/messages/message.ts b/src/types/messages/message.ts index c00b23d62..bfc456465 100644 --- a/src/types/messages/message.ts +++ b/src/types/messages/message.ts @@ -6,6 +6,7 @@ import { Application } from "../oauth2/application.ts"; import { User } from "../users/user.ts"; import { SnakeCasedPropertiesDeep } from "../util.ts"; import { Attachment } from "./attachment.ts"; +import { MessageComponents } from "./components/message_components.ts"; import { MessageActivity } from "./message_activity.ts"; import { MessageReference } from "./message_reference.ts"; import { MessageSticker } from "./message_sticker.ts"; @@ -82,6 +83,8 @@ export interface Message { referencedMessage?: Message; /** Sent if the message is a response to an Interaction */ interaction?: MessageInteraction; + /** The components related to this message */ + components: MessageComponents; } /** https://discord.com/developers/docs/resources/channel#message-object */ diff --git a/src/types/misc/errors.ts b/src/types/misc/errors.ts index f8e441b72..ee55755c0 100644 --- a/src/types/misc/errors.ts +++ b/src/types/misc/errors.ts @@ -68,9 +68,19 @@ export enum Errors { USERNAME_INVALID_USERNAME = "USERNAME_INVALID_USERNAME", USERNAME_MAX_LENGTH = "USERNAME_MAX_LENGTH", USERNAME_MIN_LENGTH = "USERNAME_MIN_LENGTH", + NONCE_TOO_LONG = "NONCE_TOO_LONG", + INVITE_MAX_AGE_INVALID = "INVITE_MAX_AGE_INVALID", + INVITE_MAX_USES_INVALID = "INVITE_MAX_USES_INVALID", // API Errors RATE_LIMIT_RETRY_MAXED = "RATE_LIMIT_RETRY_MAXED", REQUEST_CLIENT_ERROR = "REQUEST_CLIENT_ERROR", REQUEST_SERVER_ERROR = "REQUEST_SERVER_ERROR", REQUEST_UNKNOWN_ERROR = "REQUEST_UNKNOWN_ERROR", + // Component Errors + TOO_MANY_COMPONENTS = "TOO_MANY_COMPONENTS", + TOO_MANY_ACTION_ROWS = "TOO_MANY_ACTION_ROWS", + LINK_BUTTON_CANNOT_HAVE_CUSTOM_ID = "LINK_BUTTON_CANNOT_HAVE_CUSTOM_ID", + COMPONENT_LABEL_TOO_BIG = "COMPONENT_LABEL_TOO_BIG", + COMPONENT_CUSTOM_ID_TOO_BIG = "COMPONENT_CUSTOM_ID_TOO_BIG", + BUTTON_REQUIRES_CUSTOM_ID = "BUTTON_REQUIRES_CUSTOM_ID", } diff --git a/src/types/mod.ts b/src/types/mod.ts index dd18a8ec4..bc4d06750 100644 --- a/src/types/mod.ts +++ b/src/types/mod.ts @@ -131,6 +131,11 @@ export * from "./members/guild_member_add.ts"; export * from "./members/guild_member_remove.ts"; export * from "./members/guild_member_update.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"; diff --git a/src/ws/create_shard.ts b/src/ws/create_shard.ts index cecbc20a0..da974d65b 100644 --- a/src/ws/create_shard.ts +++ b/src/ws/create_shard.ts @@ -17,24 +17,17 @@ export async function createShard(shardId: number) { socket.onclose = (event) => { ws.log("CLOSED", { shardId, payload: event }); - if ( - event.code === 3064 || - event.reason === "Discordeno Testing Finished! Do Not RESUME!" - ) { - return; - } - - if ( - event.code === 3065 || - ["Resharded!", "Resuming the shard, closing old shard."].includes( - event.reason, - ) - ) { - return ws.log("CLOSED_RECONNECT", { shardId, payload: event }); - } - // TODO: ENUM FOR THESE CODES? switch (event.code) { + // Discordeno tests finished + case 3061: + return; + case 3063: // Resharded + case 3064: // Resuming + case 3065: // Reidentifying + case 3066: // Missing ACK + // Will restart shard manually + return ws.log("CLOSED_RECONNECT", { shardId, payload: event }); case 4001: case 4002: case 4004: diff --git a/src/ws/events.ts b/src/ws/events.ts index 02b70000d..a64d7e474 100644 --- a/src/ws/events.ts +++ b/src/ws/events.ts @@ -61,5 +61,6 @@ export function log( | "DEBUG", data: unknown, ) { - console.log(type, data); + // This is just a placeholder for the dev to override + if (!type && !data) console.log(type, data); } diff --git a/src/ws/spawn_shards.ts b/src/ws/spawn_shards.ts index b7b449ba0..7dd24eff2 100644 --- a/src/ws/spawn_shards.ts +++ b/src/ws/spawn_shards.ts @@ -50,7 +50,6 @@ export function spawnShards(firstShardId = 0) { } } - console.log("BUCKETS", ws.buckets); // SPREAD THIS OUT TO DIFFERENT CLUSTERS TO BEGIN STARTING UP ws.buckets.forEach(async (bucket, bucketId) => { ws.log(