mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 03:18:17 +00:00
buttons buttons and more buttons
This commit is contained in:
+2
-30
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<Invite>(
|
||||
"post",
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Message>(
|
||||
"post",
|
||||
endpoints.CHANNEL_MESSAGES(channelId),
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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<GuildWidgetDetails>;
|
||||
@@ -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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -2,4 +2,5 @@
|
||||
export enum DiscordInteractionTypes {
|
||||
Ping = 1,
|
||||
ApplicationCommand,
|
||||
Button
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<ActionRow>;
|
||||
@@ -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<ButtonComponent>;
|
||||
@@ -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,
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
export enum MessageComponentTypes {
|
||||
/** A row of components at the bottom of a message */
|
||||
ActionRow = 1,
|
||||
/** A button! */
|
||||
Button,
|
||||
}
|
||||
@@ -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[];
|
||||
@@ -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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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",
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
|
||||
+9
-16
@@ -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:
|
||||
|
||||
+2
-1
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user