mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
refactor: cleanup and fmt
This commit is contained in:
@@ -2,7 +2,6 @@ import { getGatewayBot } from "./helpers/misc/get_gateway_bot.ts";
|
|||||||
import { DiscordGatewayIntents } from "./types/gateway/gateway_intents.ts";
|
import { DiscordGatewayIntents } from "./types/gateway/gateway_intents.ts";
|
||||||
import { DiscordGetGatewayBot } from "./types/gateway/get_gateway_bot.ts";
|
import { DiscordGetGatewayBot } from "./types/gateway/get_gateway_bot.ts";
|
||||||
import { baseEndpoints, GATEWAY_VERSION } from "./util/constants.ts";
|
import { baseEndpoints, GATEWAY_VERSION } from "./util/constants.ts";
|
||||||
import { spawnShards } from "./ws/shard_manager.ts";
|
|
||||||
|
|
||||||
export let authorization = "";
|
export let authorization = "";
|
||||||
export let secretKey = "";
|
export let secretKey = "";
|
||||||
|
|||||||
+23
-23
@@ -23,7 +23,7 @@ export const cache = {
|
|||||||
(
|
(
|
||||||
value:
|
value:
|
||||||
| Collection<string, Member>
|
| Collection<string, Member>
|
||||||
| PromiseLike<Collection<string, Member>>
|
| PromiseLike<Collection<string, Member>>,
|
||||||
) => void
|
) => void
|
||||||
>(),
|
>(),
|
||||||
executedSlashCommands: new Collection<string, string>(),
|
executedSlashCommands: new Collection<string, string>(),
|
||||||
@@ -31,8 +31,8 @@ export const cache = {
|
|||||||
return new Collection<string, Emoji>(
|
return new Collection<string, Emoji>(
|
||||||
this.guilds.reduce(
|
this.guilds.reduce(
|
||||||
(a, b) => [...a, ...b.emojis.map((e) => [e.id, e])],
|
(a, b) => [...a, ...b.emojis.map((e) => [e.id, e])],
|
||||||
[] as any[]
|
[] as any[],
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -78,32 +78,32 @@ export type TableName =
|
|||||||
function set(
|
function set(
|
||||||
table: "guilds",
|
table: "guilds",
|
||||||
key: string,
|
key: string,
|
||||||
value: Guild
|
value: Guild,
|
||||||
): Promise<Collection<string, Guild>>;
|
): Promise<Collection<string, Guild>>;
|
||||||
function set(
|
function set(
|
||||||
table: "channels",
|
table: "channels",
|
||||||
key: string,
|
key: string,
|
||||||
value: Channel
|
value: Channel,
|
||||||
): Promise<Collection<string, Channel>>;
|
): Promise<Collection<string, Channel>>;
|
||||||
function set(
|
function set(
|
||||||
table: "messages",
|
table: "messages",
|
||||||
key: string,
|
key: string,
|
||||||
value: Message
|
value: Message,
|
||||||
): Promise<Collection<string, Message>>;
|
): Promise<Collection<string, Message>>;
|
||||||
function set(
|
function set(
|
||||||
table: "members",
|
table: "members",
|
||||||
key: string,
|
key: string,
|
||||||
value: Member
|
value: Member,
|
||||||
): Promise<Collection<string, Member>>;
|
): Promise<Collection<string, Member>>;
|
||||||
function set(
|
function set(
|
||||||
table: "presences",
|
table: "presences",
|
||||||
key: string,
|
key: string,
|
||||||
value: PresenceUpdatePayload
|
value: PresenceUpdatePayload,
|
||||||
): Promise<Collection<string, PresenceUpdatePayload>>;
|
): Promise<Collection<string, PresenceUpdatePayload>>;
|
||||||
function set(
|
function set(
|
||||||
table: "unavailableGuilds",
|
table: "unavailableGuilds",
|
||||||
key: string,
|
key: string,
|
||||||
value: number
|
value: number,
|
||||||
): Promise<Collection<string, number>>;
|
): Promise<Collection<string, number>>;
|
||||||
async function set(table: TableName, key: string, value: any) {
|
async function set(table: TableName, key: string, value: any) {
|
||||||
return cache[table].set(key, value);
|
return cache[table].set(key, value);
|
||||||
@@ -115,11 +115,11 @@ function get(table: "messages", key: string): Promise<Message | undefined>;
|
|||||||
function get(table: "members", key: string): Promise<Member | undefined>;
|
function get(table: "members", key: string): Promise<Member | undefined>;
|
||||||
function get(
|
function get(
|
||||||
table: "presences",
|
table: "presences",
|
||||||
key: string
|
key: string,
|
||||||
): Promise<PresenceUpdatePayload | undefined>;
|
): Promise<PresenceUpdatePayload | undefined>;
|
||||||
function get(
|
function get(
|
||||||
table: "unavailableGuilds",
|
table: "unavailableGuilds",
|
||||||
key: string
|
key: string,
|
||||||
): Promise<Guild | undefined>;
|
): Promise<Guild | undefined>;
|
||||||
async function get(table: TableName, key: string) {
|
async function get(table: TableName, key: string) {
|
||||||
return cache[table].get(key);
|
return cache[table].get(key);
|
||||||
@@ -127,54 +127,54 @@ async function get(table: TableName, key: string) {
|
|||||||
|
|
||||||
function forEach(
|
function forEach(
|
||||||
table: "guilds",
|
table: "guilds",
|
||||||
callback: (value: Guild, key: string, map: Map<string, Guild>) => unknown
|
callback: (value: Guild, key: string, map: Map<string, Guild>) => unknown,
|
||||||
): void;
|
): void;
|
||||||
function forEach(
|
function forEach(
|
||||||
table: "unavailableGuilds",
|
table: "unavailableGuilds",
|
||||||
callback: (value: Guild, key: string, map: Map<string, Guild>) => unknown
|
callback: (value: Guild, key: string, map: Map<string, Guild>) => unknown,
|
||||||
): void;
|
): void;
|
||||||
function forEach(
|
function forEach(
|
||||||
table: "channels",
|
table: "channels",
|
||||||
callback: (value: Channel, key: string, map: Map<string, Channel>) => unknown
|
callback: (value: Channel, key: string, map: Map<string, Channel>) => unknown,
|
||||||
): void;
|
): void;
|
||||||
function forEach(
|
function forEach(
|
||||||
table: "messages",
|
table: "messages",
|
||||||
callback: (value: Message, key: string, map: Map<string, Message>) => unknown
|
callback: (value: Message, key: string, map: Map<string, Message>) => unknown,
|
||||||
): void;
|
): void;
|
||||||
function forEach(
|
function forEach(
|
||||||
table: "members",
|
table: "members",
|
||||||
callback: (value: Member, key: string, map: Map<string, Member>) => unknown
|
callback: (value: Member, key: string, map: Map<string, Member>) => unknown,
|
||||||
): void;
|
): void;
|
||||||
function forEach(
|
function forEach(
|
||||||
table: TableName,
|
table: TableName,
|
||||||
callback: (value: any, key: string, map: Map<string, any>) => unknown
|
callback: (value: any, key: string, map: Map<string, any>) => unknown,
|
||||||
) {
|
) {
|
||||||
return cache[table].forEach(callback);
|
return cache[table].forEach(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function filter(
|
function filter(
|
||||||
table: "guilds",
|
table: "guilds",
|
||||||
callback: (value: Guild, key: string) => boolean
|
callback: (value: Guild, key: string) => boolean,
|
||||||
): Promise<Collection<string, Guild>>;
|
): Promise<Collection<string, Guild>>;
|
||||||
function filter(
|
function filter(
|
||||||
table: "unavailableGuilds",
|
table: "unavailableGuilds",
|
||||||
callback: (value: Guild, key: string) => boolean
|
callback: (value: Guild, key: string) => boolean,
|
||||||
): Promise<Collection<string, Guild>>;
|
): Promise<Collection<string, Guild>>;
|
||||||
function filter(
|
function filter(
|
||||||
table: "channels",
|
table: "channels",
|
||||||
callback: (value: Channel, key: string) => boolean
|
callback: (value: Channel, key: string) => boolean,
|
||||||
): Promise<Collection<string, Channel>>;
|
): Promise<Collection<string, Channel>>;
|
||||||
function filter(
|
function filter(
|
||||||
table: "messages",
|
table: "messages",
|
||||||
callback: (value: Message, key: string) => boolean
|
callback: (value: Message, key: string) => boolean,
|
||||||
): Promise<Collection<string, Message>>;
|
): Promise<Collection<string, Message>>;
|
||||||
function filter(
|
function filter(
|
||||||
table: "members",
|
table: "members",
|
||||||
callback: (value: Member, key: string) => boolean
|
callback: (value: Member, key: string) => boolean,
|
||||||
): Promise<Collection<string, Member>>;
|
): Promise<Collection<string, Member>>;
|
||||||
async function filter(
|
async function filter(
|
||||||
table: TableName,
|
table: TableName,
|
||||||
callback: (value: any, key: string) => boolean
|
callback: (value: any, key: string) => boolean,
|
||||||
) {
|
) {
|
||||||
return cache[table].filter(callback);
|
return cache[table].filter(callback);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { eventHandlers } from "../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { cache, cacheHandlers } from "../../cache.ts";
|
import { cache, cacheHandlers } from "../../cache.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
import { basicShards } from "../../ws/shard.ts";
|
|
||||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||||
import { DiscordGuild } from "../../types/guilds/guild.ts";
|
import { DiscordGuild } from "../../types/guilds/guild.ts";
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { eventHandlers } from "../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { basicShards } from "../../ws/shard.ts";
|
|
||||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||||
import { DiscordUnavailableGuild } from "../../types/guilds/unavailable_guild.ts";
|
import { DiscordUnavailableGuild } from "../../types/guilds/unavailable_guild.ts";
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import {
|
|||||||
export async function createChannel(
|
export async function createChannel(
|
||||||
guildId: string,
|
guildId: string,
|
||||||
name: string,
|
name: string,
|
||||||
options?: CreateGuildChannel
|
options?: CreateGuildChannel,
|
||||||
) {
|
) {
|
||||||
const requiredPerms: Set<PermissionStrings> = new Set(["MANAGE_CHANNELS"]);
|
const requiredPerms: Set<PermissionStrings> = new Set(["MANAGE_CHANNELS"]);
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ export async function createChannel(
|
|||||||
deny: calculateBits(perm.deny),
|
deny: calculateBits(perm.deny),
|
||||||
})),
|
})),
|
||||||
type: options?.type || DiscordChannelTypes.GUILD_TEXT,
|
type: options?.type || DiscordChannelTypes.GUILD_TEXT,
|
||||||
}
|
},
|
||||||
)) as DiscordChannel;
|
)) as DiscordChannel;
|
||||||
|
|
||||||
const channelStruct = await structures.createChannelStruct(result);
|
const channelStruct = await structures.createChannelStruct(result);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export function guildBannerURL(
|
|||||||
id: string,
|
id: string,
|
||||||
banner: string,
|
banner: string,
|
||||||
size: DiscordImageSize = 128,
|
size: DiscordImageSize = 128,
|
||||||
format?: DiscordImageFormat
|
format?: DiscordImageFormat,
|
||||||
) {
|
) {
|
||||||
return banner
|
return banner
|
||||||
? formatImageURL(endpoints.GUILD_BANNER(id, banner), size, format)
|
? formatImageURL(endpoints.GUILD_BANNER(id, banner), size, format)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { Member } from "../../structures/mod.ts";
|
|||||||
import { DiscordGatewayIntents } from "../../types/gateway/gateway_intents.ts";
|
import { DiscordGatewayIntents } from "../../types/gateway/gateway_intents.ts";
|
||||||
import { Errors } from "../../types/misc/errors.ts";
|
import { Errors } from "../../types/misc/errors.ts";
|
||||||
import { Collection } from "../../util/collection.ts";
|
import { Collection } from "../../util/collection.ts";
|
||||||
import { requestAllMembers } from "../../ws/shard_manager.ts";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ⚠️ BEGINNER DEVS!! YOU SHOULD ALMOST NEVER NEED THIS AND YOU CAN GET FROM cache.members.get()
|
* ⚠️ BEGINNER DEVS!! YOU SHOULD ALMOST NEVER NEED THIS AND YOU CAN GET FROM cache.members.get()
|
||||||
|
|||||||
@@ -15,11 +15,10 @@ export async function getMember(
|
|||||||
const guild = await cacheHandlers.get("guilds", guildId);
|
const guild = await cacheHandlers.get("guilds", guildId);
|
||||||
if (!guild && !options?.force) return;
|
if (!guild && !options?.force) return;
|
||||||
|
|
||||||
const data =
|
const data = (await rest.runMethod(
|
||||||
(await rest.runMethod(
|
"get",
|
||||||
"get",
|
endpoints.GUILD_MEMBER(guildId, id),
|
||||||
endpoints.GUILD_MEMBER(guildId, id),
|
)) as MemberCreatePayload;
|
||||||
)) as MemberCreatePayload;
|
|
||||||
|
|
||||||
const memberStruct = await structures.createMemberStruct(data, guildId);
|
const memberStruct = await structures.createMemberStruct(data, guildId);
|
||||||
await cacheHandlers.set("members", memberStruct.id, memberStruct);
|
await cacheHandlers.set("members", memberStruct.id, memberStruct);
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { Member } from "../../structures/mod.ts";
|
import { Member } from "../../structures/mod.ts";
|
||||||
import { Collection } from "../../util/collection.ts";
|
import { Collection } from "../../util/collection.ts";
|
||||||
import { requestAllMembers } from "../../ws/shard_manager.ts";
|
|
||||||
|
|
||||||
/** Returns guild member objects for the specified user by their nickname/username.
|
/** Returns guild member objects for the specified user by their nickname/username.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ export async function createGuildStruct(
|
|||||||
} = snakeKeysToCamelCase(data) as Guild;
|
} = snakeKeysToCamelCase(data) as Guild;
|
||||||
|
|
||||||
const roles = await Promise.all(
|
const roles = await Promise.all(
|
||||||
data.roles.map((role) => structures.createRoleStruct(role))
|
data.roles.map((role) => structures.createRoleStruct(role)),
|
||||||
);
|
);
|
||||||
|
|
||||||
await Promise.all(channels.map(async (channel) => {
|
await Promise.all(channels.map(async (channel) => {
|
||||||
@@ -148,7 +148,7 @@ export async function createGuildStruct(
|
|||||||
),
|
),
|
||||||
memberCount: createNewProp(memberCount),
|
memberCount: createNewProp(memberCount),
|
||||||
emojis: createNewProp(
|
emojis: createNewProp(
|
||||||
new Collection(emojis.map((emoji) => [emoji.id ?? emoji.name, emoji]))
|
new Collection(emojis.map((emoji) => [emoji.id ?? emoji.name, emoji])),
|
||||||
),
|
),
|
||||||
voiceStates: createNewProp(
|
voiceStates: createNewProp(
|
||||||
new Collection(
|
new Collection(
|
||||||
@@ -165,11 +165,11 @@ export async function createGuildStruct(
|
|||||||
members.map(async (member) => {
|
members.map(async (member) => {
|
||||||
const memberStruct = await structures.createMemberStruct(
|
const memberStruct = await structures.createMemberStruct(
|
||||||
member,
|
member,
|
||||||
guild.id
|
guild.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
return cacheHandlers.set("members", memberStruct.id, memberStruct);
|
return cacheHandlers.set("members", memberStruct.id, memberStruct);
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,8 +221,8 @@ export interface GuildStruct extends
|
|||||||
size?: DiscordImageSize,
|
size?: DiscordImageSize,
|
||||||
format?: DiscordImageFormat,
|
format?: DiscordImageFormat,
|
||||||
): string | undefined;
|
): string | undefined;
|
||||||
/** The splash url for this server */
|
/** The splash url for this server */
|
||||||
splashURL(
|
splashURL(
|
||||||
size?: DiscordImageSize,
|
size?: DiscordImageSize,
|
||||||
format?: DiscordImageFormat,
|
format?: DiscordImageFormat,
|
||||||
): string | undefined;
|
): string | undefined;
|
||||||
|
|||||||
+20
-22
@@ -30,9 +30,8 @@ const baseMessage: Partial<Message> = {
|
|||||||
return this.member?.guilds.get(this.guildId);
|
return this.member?.guilds.get(this.guildId);
|
||||||
},
|
},
|
||||||
get link() {
|
get link() {
|
||||||
return `https://discord.com/channels/${this.guildId || "@me"}/${
|
return `https://discord.com/channels/${this.guildId ||
|
||||||
this.channelId
|
"@me"}/${this.channelId}/${this.id}`;
|
||||||
}/${this.id}`;
|
|
||||||
},
|
},
|
||||||
get mentionedRoles() {
|
get mentionedRoles() {
|
||||||
return this.mentionRoleIds?.map((id) => this.guild?.roles.get(id)) || [];
|
return this.mentionRoleIds?.map((id) => this.guild?.roles.get(id)) || [];
|
||||||
@@ -61,20 +60,19 @@ const baseMessage: Partial<Message> = {
|
|||||||
return addReactions(this.channelId!, this.id!, reactions, ordered);
|
return addReactions(this.channelId!, this.id!, reactions, ordered);
|
||||||
},
|
},
|
||||||
reply(content) {
|
reply(content) {
|
||||||
const contentWithMention =
|
const contentWithMention = typeof content === "string"
|
||||||
typeof content === "string"
|
? {
|
||||||
? {
|
content,
|
||||||
content,
|
mentions: { repliedUser: true },
|
||||||
mentions: { repliedUser: true },
|
replyMessageId: this.id,
|
||||||
replyMessageId: this.id,
|
failReplyIfNotExists: false,
|
||||||
failReplyIfNotExists: false,
|
}
|
||||||
}
|
: {
|
||||||
: {
|
...content,
|
||||||
...content,
|
mentions: { ...(content.mentions || {}), repliedUser: true },
|
||||||
mentions: { ...(content.mentions || {}), repliedUser: true },
|
replyMessageId: this.id,
|
||||||
replyMessageId: this.id,
|
failReplyIfNotExists: content.failReplyIfNotExists === true,
|
||||||
failReplyIfNotExists: content.failReplyIfNotExists === true,
|
};
|
||||||
};
|
|
||||||
|
|
||||||
if (this.guildId) return sendMessage(this.channelId!, contentWithMention);
|
if (this.guildId) return sendMessage(this.channelId!, contentWithMention);
|
||||||
return sendDirectMessage(this.author!.id, contentWithMention);
|
return sendDirectMessage(this.author!.id, contentWithMention);
|
||||||
@@ -132,8 +130,8 @@ export async function createMessageStruct(data: MessageCreateOptions) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Discord doesnt give guild id for getMessage() so this will fill it in
|
// Discord doesnt give guild id for getMessage() so this will fill it in
|
||||||
const guildIdFinal =
|
const guildIdFinal = guildId ||
|
||||||
guildId || (await cacheHandlers.get("channels", channelId))?.guildId || "";
|
(await cacheHandlers.get("channels", channelId))?.guildId || "";
|
||||||
|
|
||||||
const message = Object.create(baseMessage, {
|
const message = Object.create(baseMessage, {
|
||||||
...restProps,
|
...restProps,
|
||||||
@@ -150,16 +148,16 @@ export async function createMessageStruct(data: MessageCreateOptions) {
|
|||||||
...mentionChannelIds,
|
...mentionChannelIds,
|
||||||
// Add any other ids that can be validated in a channel mention format
|
// Add any other ids that can be validated in a channel mention format
|
||||||
...(rest.content.match(CHANNEL_MENTION_REGEX) || []).map((text) =>
|
...(rest.content.match(CHANNEL_MENTION_REGEX) || []).map((text) =>
|
||||||
// converts the <#123> into 123
|
// converts the <#123> into 123
|
||||||
text.substring(2, text.length - 1)
|
text.substring(2, text.length - 1)
|
||||||
),
|
),
|
||||||
].map((m) => m.id)
|
].map((m) => m.id),
|
||||||
),
|
),
|
||||||
webhookId: createNewProp(webhookId),
|
webhookId: createNewProp(webhookId),
|
||||||
messageReference: createNewProp(messageReference),
|
messageReference: createNewProp(messageReference),
|
||||||
timestamp: createNewProp(Date.parse(data.timestamp)),
|
timestamp: createNewProp(Date.parse(data.timestamp)),
|
||||||
editedTimestamp: createNewProp(
|
editedTimestamp: createNewProp(
|
||||||
editedTimestamp ? Date.parse(editedTimestamp) : undefined
|
editedTimestamp ? Date.parse(editedTimestamp) : undefined,
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { SnakeCaseProps } from "../util.ts";
|
import { SnakeCaseProps } from "../util.ts";
|
||||||
import { DiscordVisibilityTypes } from "./visibility_types.ts";
|
import { DiscordVisibilityTypes } from "./visibility_types.ts";
|
||||||
import { Integration } from "../guilds/integration.ts"
|
import { Integration } from "../guilds/integration.ts";
|
||||||
|
|
||||||
export interface Connection {
|
export interface Connection {
|
||||||
/** id of the connection account */
|
/** id of the connection account */
|
||||||
|
|||||||
@@ -177,4 +177,4 @@ export const endpoints = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const SLASH_COMMANDS_NAME_REGEX = /^[\w-]{1,32}$/;
|
export const SLASH_COMMANDS_NAME_REGEX = /^[\w-]{1,32}$/;
|
||||||
export const CHANNEL_MENTION_REGEX = /<#[0-9]+>/g;
|
export const CHANNEL_MENTION_REGEX = /<#[0-9]+>/g;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { DiscordGatewayOpcodes } from "../types/codes/gateway_opcodes.ts";
|
|||||||
import { Errors } from "../types/misc/errors.ts";
|
import { Errors } from "../types/misc/errors.ts";
|
||||||
import { DiscordImageFormat } from "../types/misc/image_format.ts";
|
import { DiscordImageFormat } from "../types/misc/image_format.ts";
|
||||||
import { DiscordImageSize } from "../types/misc/image_size.ts";
|
import { DiscordImageSize } from "../types/misc/image_size.ts";
|
||||||
import { basicShards, sendWS } from "../ws/shard.ts";
|
|
||||||
import { SLASH_COMMANDS_NAME_REGEX } from "./constants.ts";
|
import { SLASH_COMMANDS_NAME_REGEX } from "./constants.ts";
|
||||||
|
|
||||||
export const sleep = (timeout: number) => {
|
export const sleep = (timeout: number) => {
|
||||||
|
|||||||
+1
-1
@@ -201,4 +201,4 @@ export interface DiscordenoShard {
|
|||||||
intervalID: number;
|
intervalID: number;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -9,13 +9,13 @@ export async function cleanupLoadingShards() {
|
|||||||
console.log(
|
console.log(
|
||||||
now > loadingShard.startedAt + 60000,
|
now > loadingShard.startedAt + 60000,
|
||||||
now,
|
now,
|
||||||
loadingShard.startedAt
|
loadingShard.startedAt,
|
||||||
);
|
);
|
||||||
// Not a minute yet. Max should be few seconds but do a minute to be safe.
|
// Not a minute yet. Max should be few seconds but do a minute to be safe.
|
||||||
if (now < loadingShard.startedAt + 60000) return;
|
if (now < loadingShard.startedAt + 60000) return;
|
||||||
|
|
||||||
loadingShard.reject(
|
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.`,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { identify } from "./identify.ts";
|
import { identify } from "./identify.ts";
|
||||||
import { handleOnMessage } from "./proxy/shard.ts";
|
|
||||||
import { resume } from "./resume.ts";
|
import { resume } from "./resume.ts";
|
||||||
import { ws } from "./ws.ts";
|
import { ws } from "./ws.ts";
|
||||||
|
|
||||||
@@ -29,7 +28,7 @@ export async function createShard(shardID: number) {
|
|||||||
case 4013:
|
case 4013:
|
||||||
case 4014:
|
case 4014:
|
||||||
throw new Error(
|
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!
|
// THESE ERRORS CAN NO BE RESUMED! THEY MUST RE-IDENTIFY!
|
||||||
case 4003:
|
case 4003:
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { ws } from "./ws.ts";
|
|||||||
/** Handler for processing all dispatch payloads that should be sent/forwarded to another server/vps/process. */
|
/** Handler for processing all dispatch payloads that should be sent/forwarded to another server/vps/process. */
|
||||||
export async function handleDiscordPayload(
|
export async function handleDiscordPayload(
|
||||||
data: DiscordPayload,
|
data: DiscordPayload,
|
||||||
shardID: number
|
shardID: number,
|
||||||
) {
|
) {
|
||||||
await fetch(ws.url, {
|
await fetch(ws.url, {
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@@ -13,8 +13,10 @@ export function handleOnMessage(message: any, shardID: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (message instanceof Uint8Array) {
|
if (message instanceof Uint8Array) {
|
||||||
message = decompressWith(message, 0, (slice: Uint8Array) =>
|
message = decompressWith(
|
||||||
ws.utf8decoder.decode(slice)
|
message,
|
||||||
|
0,
|
||||||
|
(slice: Uint8Array) => ws.utf8decoder.decode(slice),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,7 +29,7 @@ export function handleOnMessage(message: any, shardID: number) {
|
|||||||
case DiscordGatewayOpcodes.Hello:
|
case DiscordGatewayOpcodes.Hello:
|
||||||
ws.heartbeat(
|
ws.heartbeat(
|
||||||
shardID,
|
shardID,
|
||||||
(messageData.d as DiscordHeartbeat).heartbeat_interval
|
(messageData.d as DiscordHeartbeat).heartbeat_interval,
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case DiscordGatewayOpcodes.HeartbeatACK:
|
case DiscordGatewayOpcodes.HeartbeatACK:
|
||||||
|
|||||||
+1
-1
@@ -34,7 +34,7 @@ export function heartbeat(shardID: number, interval: number) {
|
|||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
op: DiscordGatewayOpcodes.Heartbeat,
|
op: DiscordGatewayOpcodes.Heartbeat,
|
||||||
d: currentShard.previousSequenceNumber,
|
d: currentShard.previousSequenceNumber,
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
}, interval);
|
}, interval);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -30,7 +30,7 @@ export async function identify(shardID: number, maxShards: number) {
|
|||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
op: DiscordGatewayOpcodes.Identify,
|
op: DiscordGatewayOpcodes.Identify,
|
||||||
d: { ...ws.identifyPayload, shard: [shardID, maxShards] },
|
d: { ...ws.identifyPayload, shard: [shardID, maxShards] },
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -48,7 +48,7 @@ export async function resume(shardID: number) {
|
|||||||
session_id: sessionID,
|
session_id: sessionID,
|
||||||
seq: previousSequenceNumber,
|
seq: previousSequenceNumber,
|
||||||
},
|
},
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
-383
@@ -1,383 +0,0 @@
|
|||||||
import { botGatewayData, eventHandlers, proxyWSURL } from "../bot.ts";
|
|
||||||
import { DiscordGatewayOpcodes } from "../types/codes/gateway_opcodes.ts";
|
|
||||||
import { Collection } from "../util/collection.ts";
|
|
||||||
import { delay } from "../util/utils.ts";
|
|
||||||
import { decompressWith } from "./deps.ts";
|
|
||||||
import { handleDiscordPayload } from "./shard_manager.ts";
|
|
||||||
|
|
||||||
export const basicShards = new Collection<number, BasicShard>();
|
|
||||||
const heartbeating = new Map<number, boolean>();
|
|
||||||
const utf8decoder = new TextDecoder();
|
|
||||||
const RequestMembersQueue: RequestMemberQueuedRequest[] = [];
|
|
||||||
let processQueue = false;
|
|
||||||
|
|
||||||
export function createShard(
|
|
||||||
data: DiscordBotGatewayData,
|
|
||||||
identifyPayload: DiscordIdentify,
|
|
||||||
resuming = false,
|
|
||||||
shardId = 0,
|
|
||||||
) {
|
|
||||||
const oldShard = basicShards.get(shardId);
|
|
||||||
|
|
||||||
const ws = new WebSocket(proxyWSURL);
|
|
||||||
ws.binaryType = "arraybuffer";
|
|
||||||
const basicShard: BasicShard = {
|
|
||||||
id: shardId,
|
|
||||||
ws,
|
|
||||||
resumeInterval: 0,
|
|
||||||
sessionId: oldShard?.sessionId || "",
|
|
||||||
previousSequenceNumber: oldShard?.previousSequenceNumber || 0,
|
|
||||||
needToResume: false,
|
|
||||||
ready: false,
|
|
||||||
unavailableGuildIds: new Set<string>(),
|
|
||||||
};
|
|
||||||
|
|
||||||
basicShards.set(basicShard.id, basicShard);
|
|
||||||
|
|
||||||
ws.onopen = () => {
|
|
||||||
if (!resuming) {
|
|
||||||
// Initial identify with the gateway
|
|
||||||
identify(basicShard, identifyPayload);
|
|
||||||
} else {
|
|
||||||
resume(basicShard, identifyPayload);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ws.onerror = (errorEvent) => {
|
|
||||||
eventHandlers.debug?.({
|
|
||||||
type: "wsError",
|
|
||||||
data: { shardId: basicShard.id, ...errorEvent },
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
ws.onmessage = async ({ data: message }) => {
|
|
||||||
if (message instanceof ArrayBuffer) {
|
|
||||||
message = new Uint8Array(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (message instanceof Uint8Array) {
|
|
||||||
message = decompressWith(
|
|
||||||
message,
|
|
||||||
0,
|
|
||||||
(slice: Uint8Array) => utf8decoder.decode(slice),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof message === "string") {
|
|
||||||
const messageData = JSON.parse(message);
|
|
||||||
if (!messageData.t) eventHandlers.rawGateway?.(messageData);
|
|
||||||
switch (messageData.op) {
|
|
||||||
case DiscordGatewayOpcodes.Hello:
|
|
||||||
if (!heartbeating.has(basicShard.id)) {
|
|
||||||
await heartbeat(
|
|
||||||
basicShard,
|
|
||||||
(messageData.d as DiscordHello).heartbeat_interval,
|
|
||||||
identifyPayload,
|
|
||||||
data,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case DiscordGatewayOpcodes.HeartbeatACK:
|
|
||||||
heartbeating.set(shardId, true);
|
|
||||||
break;
|
|
||||||
case DiscordGatewayOpcodes.Reconnect:
|
|
||||||
eventHandlers.debug?.(
|
|
||||||
{ type: "gatewayReconnect", data: { shardId: basicShard.id } },
|
|
||||||
);
|
|
||||||
basicShard.needToResume = true;
|
|
||||||
await resumeConnection(data, identifyPayload, basicShard.id);
|
|
||||||
break;
|
|
||||||
case DiscordGatewayOpcodes.InvalidSession:
|
|
||||||
eventHandlers.debug?.(
|
|
||||||
{
|
|
||||||
type: "gatewayInvalidSession",
|
|
||||||
data: { shardId: basicShard.id, data },
|
|
||||||
},
|
|
||||||
);
|
|
||||||
// When d is false we need to reidentify
|
|
||||||
if (!messageData.d) {
|
|
||||||
createShard(data, identifyPayload, false, shardId);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
basicShard.needToResume = true;
|
|
||||||
await resumeConnection(data, identifyPayload, basicShard.id);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (messageData.t === "RESUMED") {
|
|
||||||
eventHandlers.debug?.(
|
|
||||||
{ type: "gatewayResumed", data: { shardId: basicShard.id } },
|
|
||||||
);
|
|
||||||
|
|
||||||
basicShard.needToResume = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// Important for RESUME
|
|
||||||
if (messageData.t === "READY") {
|
|
||||||
basicShard.sessionId = (messageData.d as ReadyPayload).session_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the sequence number if it is present
|
|
||||||
if (messageData.s) basicShard.previousSequenceNumber = messageData.s;
|
|
||||||
|
|
||||||
await handleDiscordPayload(messageData, basicShard.id);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ws.onclose = async ({ reason, code, wasClean }) => {
|
|
||||||
eventHandlers.debug?.(
|
|
||||||
{
|
|
||||||
type: "wsClose",
|
|
||||||
data: { shardId: basicShard.id, code, reason, wasClean },
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
if ([4001, 4002, 4004, 4005, 4010, 4011, 4012, 4013, 4014].includes(code)) {
|
|
||||||
throw new Error(reason);
|
|
||||||
} else if ([4000, 4003, 4007, 4008, 4009].includes(code)) {
|
|
||||||
eventHandlers.debug?.({
|
|
||||||
type: "wsReconnect",
|
|
||||||
data: { shardId: basicShard.id, code, reason, wasClean },
|
|
||||||
});
|
|
||||||
createShard(data, identifyPayload, false, shardId);
|
|
||||||
} else if (code === 3069 && reason === "[discordeno] requested closure") {
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
basicShard.needToResume = true;
|
|
||||||
await resumeConnection(botGatewayData, identifyPayload, shardId);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function identify(shard: BasicShard, payload: DiscordIdentify) {
|
|
||||||
eventHandlers.debug?.(
|
|
||||||
{
|
|
||||||
type: "gatewayIdentify",
|
|
||||||
data: {
|
|
||||||
shardId: shard.id,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
sendWS({
|
|
||||||
op: DiscordGatewayOpcodes.Identify,
|
|
||||||
d: { ...payload, shard: [shard.id, payload.shard[1]] },
|
|
||||||
}, shard.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
function resume(shard: BasicShard, payload: DiscordIdentify) {
|
|
||||||
sendWS({
|
|
||||||
op: DiscordGatewayOpcodes.Resume,
|
|
||||||
d: {
|
|
||||||
token: payload.token,
|
|
||||||
session_id: shard.sessionId,
|
|
||||||
seq: shard.previousSequenceNumber,
|
|
||||||
},
|
|
||||||
}, shard.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function heartbeat(
|
|
||||||
shard: BasicShard,
|
|
||||||
interval: number,
|
|
||||||
payload: DiscordIdentify,
|
|
||||||
data: DiscordGetGatewayBot,
|
|
||||||
) {
|
|
||||||
// We lost socket connection between heartbeats, resume connection
|
|
||||||
if (shard.ws.readyState === WebSocket.CLOSED) {
|
|
||||||
shard.needToResume = true;
|
|
||||||
await resumeConnection(data, payload, shard.id);
|
|
||||||
heartbeating.delete(shard.id);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (heartbeating.has(shard.id)) {
|
|
||||||
const receivedACK = heartbeating.get(shard.id);
|
|
||||||
// If a ACK response was not received since last heartbeat, issue invalid session close
|
|
||||||
if (!receivedACK) {
|
|
||||||
eventHandlers.debug?.(
|
|
||||||
{
|
|
||||||
type: "gatewayHeartbeatStopped",
|
|
||||||
data: {
|
|
||||||
interval,
|
|
||||||
previousSequenceNumber: shard.previousSequenceNumber,
|
|
||||||
shardId: shard.id,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
return shard.ws.close(4009, "Session timed out");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set it to false as we are issuing a new heartbeat
|
|
||||||
heartbeating.set(shard.id, false);
|
|
||||||
|
|
||||||
sendWS(
|
|
||||||
{ op: DiscordGatewayOpcodes.Heartbeat, d: shard.previousSequenceNumber },
|
|
||||||
shard.id,
|
|
||||||
);
|
|
||||||
eventHandlers.debug?.(
|
|
||||||
{
|
|
||||||
type: "gatewayHeartbeat",
|
|
||||||
data: {
|
|
||||||
interval,
|
|
||||||
previousSequenceNumber: shard.previousSequenceNumber,
|
|
||||||
shardId: shard.id,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
await delay(interval);
|
|
||||||
await heartbeat(shard, interval, payload, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function resumeConnection(
|
|
||||||
data: DiscordGetGatewayBot,
|
|
||||||
payload: DiscordIdentify,
|
|
||||||
shardId: number,
|
|
||||||
) {
|
|
||||||
const shard = basicShards.get(shardId);
|
|
||||||
if (!shard) {
|
|
||||||
eventHandlers.debug?.(
|
|
||||||
{ type: "missingShard", data: { shardId: shardId } },
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!shard.needToResume) return;
|
|
||||||
|
|
||||||
eventHandlers.debug?.({ type: "gatewayResume", data: { shardId: shard.id } });
|
|
||||||
// Run it once
|
|
||||||
createShard(data, payload, true, shard.id);
|
|
||||||
// Then retry every 15 seconds
|
|
||||||
await delay(1000 * 15);
|
|
||||||
if (shard.needToResume) await resumeConnection(data, payload, shardId);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function requestGuildMembers(
|
|
||||||
guildId: string,
|
|
||||||
shardId: number,
|
|
||||||
nonce: string,
|
|
||||||
options?: FetchMembersOptions,
|
|
||||||
queuedRequest = false,
|
|
||||||
) {
|
|
||||||
const shard = basicShards.get(shardId);
|
|
||||||
|
|
||||||
// This request was not from this queue so we add it to queue first
|
|
||||||
if (!queuedRequest) {
|
|
||||||
RequestMembersQueue.push({
|
|
||||||
guildId,
|
|
||||||
shardId,
|
|
||||||
nonce,
|
|
||||||
options,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!processQueue) {
|
|
||||||
processQueue = true;
|
|
||||||
return processGatewayQueue();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If its closed add back to queue to redo on resume
|
|
||||||
if (shard?.ws.readyState === WebSocket.CLOSED) {
|
|
||||||
await requestGuildMembers(guildId, shardId, nonce, options);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sendWS({
|
|
||||||
op: DiscordGatewayOpcodes.RequestGuildMembers,
|
|
||||||
d: {
|
|
||||||
guild_id: guildId,
|
|
||||||
// If a query is provided use it, OR if a limit is NOT provided use ""
|
|
||||||
query: options?.query || (options?.limit ? undefined : ""),
|
|
||||||
limit: options?.limit || 0,
|
|
||||||
presences: options?.presences || false,
|
|
||||||
user_ids: options?.userIds,
|
|
||||||
nonce,
|
|
||||||
},
|
|
||||||
}, shard?.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function processGatewayQueue() {
|
|
||||||
if (!RequestMembersQueue.length) {
|
|
||||||
processQueue = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await Promise.all(basicShards.map(async (shard) => {
|
|
||||||
const index = RequestMembersQueue.findIndex((q) => q.shardId === shard.id);
|
|
||||||
// 2 events per second is the rate limit.
|
|
||||||
const request = RequestMembersQueue[index];
|
|
||||||
if (request) {
|
|
||||||
eventHandlers.debug?.(
|
|
||||||
{
|
|
||||||
type: "requestMembersProcessing",
|
|
||||||
data: {
|
|
||||||
remaining: RequestMembersQueue.length,
|
|
||||||
request,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
await requestGuildMembers(
|
|
||||||
request.guildId,
|
|
||||||
request.shardId,
|
|
||||||
request.nonce,
|
|
||||||
request.options,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
// Remove item from queue
|
|
||||||
RequestMembersQueue.splice(index, 1);
|
|
||||||
|
|
||||||
const secondIndex = RequestMembersQueue.findIndex((q) =>
|
|
||||||
q.shardId === shard.id
|
|
||||||
);
|
|
||||||
const secondRequest = RequestMembersQueue[secondIndex];
|
|
||||||
if (secondRequest) {
|
|
||||||
eventHandlers.debug?.(
|
|
||||||
{
|
|
||||||
type: "requestMembersProcessing",
|
|
||||||
data: {
|
|
||||||
remaining: RequestMembersQueue.length,
|
|
||||||
request,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
await requestGuildMembers(
|
|
||||||
secondRequest.guildId,
|
|
||||||
secondRequest.shardId,
|
|
||||||
secondRequest.nonce,
|
|
||||||
secondRequest.options,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
// Remove item from queue
|
|
||||||
RequestMembersQueue.splice(secondIndex, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
await delay(1500);
|
|
||||||
|
|
||||||
await processGatewayQueue();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Enqueues the specified data to be transmitted to the server over the WebSocket connection, */
|
|
||||||
export function sendWS(payload: DiscordGatewayPayload, shardId = 0) {
|
|
||||||
const shard = basicShards.get(shardId);
|
|
||||||
if (!shard) return false;
|
|
||||||
|
|
||||||
const serialized = JSON.stringify(payload);
|
|
||||||
shard.ws.send(serialized);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Closes the WebSocket connection or connection attempt */
|
|
||||||
export function closeWS(shardId = 0) {
|
|
||||||
const shard = basicShards.get(shardId);
|
|
||||||
if (!shard) return false;
|
|
||||||
|
|
||||||
shard.ws.close(3069, "[discordeno] requested closure");
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
@@ -22,9 +22,13 @@ export async function startGateway(options: StartGatewayOptions) {
|
|||||||
setInterval(ws.resharder, 1000 * 60 * 60);
|
setInterval(ws.resharder, 1000 * 60 * 60);
|
||||||
|
|
||||||
ws.identifyPayload.intents = options.intents.reduce(
|
ws.identifyPayload.intents = options.intents.reduce(
|
||||||
(bits, next) =>
|
(
|
||||||
(bits |= typeof next === "string" ? DiscordGatewayIntents[next] : next),
|
bits,
|
||||||
0
|
next,
|
||||||
|
) => (bits |= typeof next === "string"
|
||||||
|
? DiscordGatewayIntents[next]
|
||||||
|
: next),
|
||||||
|
0,
|
||||||
);
|
);
|
||||||
|
|
||||||
const data = (await fetch(`https://discord.com/api/gateway/bot`, {
|
const data = (await fetch(`https://discord.com/api/gateway/bot`, {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { ws } from "./ws.ts";
|
|||||||
export async function tellClusterToIdentify(
|
export async function tellClusterToIdentify(
|
||||||
workerID: number,
|
workerID: number,
|
||||||
shardID: number,
|
shardID: number,
|
||||||
bucketID: number
|
bucketID: number,
|
||||||
) {
|
) {
|
||||||
// When resharding this may exist already
|
// When resharding this may exist already
|
||||||
const oldShard = ws.shards.get(shardID);
|
const oldShard = ws.shards.get(shardID);
|
||||||
|
|||||||
+10
-14
@@ -1,19 +1,15 @@
|
|||||||
import { Collection } from "../../util/collection.ts";
|
import { Collection } from "../util/collection.ts";
|
||||||
import {
|
|
||||||
cleanupLoadingShards,
|
|
||||||
spawnShards,
|
|
||||||
startGateway,
|
|
||||||
tellClusterToIdentify,
|
|
||||||
} from "./manager.ts";
|
|
||||||
import {
|
|
||||||
createShard,
|
|
||||||
handleDiscordPayload,
|
|
||||||
handleOnMessage,
|
|
||||||
heartbeat,
|
|
||||||
identify,
|
|
||||||
} from "./shard.ts";
|
|
||||||
import { log } from "./events.ts";
|
import { log } from "./events.ts";
|
||||||
import { resharder } from "./resharder.ts";
|
import { resharder } from "./resharder.ts";
|
||||||
|
import { startGateway } from "./start_gateway.ts";
|
||||||
|
import { spawnShards } from "./spawn_shards.ts";
|
||||||
|
import { createShard } from "./create_shard.ts";
|
||||||
|
import { identify } from "./identify.ts";
|
||||||
|
import { heartbeat } from "./heartbeat.ts";
|
||||||
|
import { handleDiscordPayload } from "./handle_discord_payload.ts";
|
||||||
|
import { tellClusterToIdentify } from "./tell_cluster_to_identify.ts";
|
||||||
|
import { cleanupLoadingShards } from "./cleanup_loading_shards.ts";
|
||||||
|
import { handleOnMessage } from "./handle_on_message.ts";
|
||||||
|
|
||||||
// CONTROLLER LIKE INTERFACE FOR WS HANDLING
|
// CONTROLLER LIKE INTERFACE FOR WS HANDLING
|
||||||
export const ws = {
|
export const ws = {
|
||||||
|
|||||||
Reference in New Issue
Block a user