mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
refactor: use updated identify payload instead
This commit is contained in:
+2
-13
@@ -2,6 +2,7 @@ import { getGatewayBot } from "./api/handlers/gateway.ts";
|
|||||||
import {
|
import {
|
||||||
BotConfig,
|
BotConfig,
|
||||||
DiscordBotGatewayData,
|
DiscordBotGatewayData,
|
||||||
|
DiscordIdentify,
|
||||||
EventHandlers,
|
EventHandlers,
|
||||||
Intents,
|
Intents,
|
||||||
} from "./types/mod.ts";
|
} from "./types/mod.ts";
|
||||||
@@ -17,7 +18,7 @@ export let eventHandlers: EventHandlers = {};
|
|||||||
export let botGatewayData: DiscordBotGatewayData;
|
export let botGatewayData: DiscordBotGatewayData;
|
||||||
export let proxyWSURL = `wss://gateway.discord.gg`;
|
export let proxyWSURL = `wss://gateway.discord.gg`;
|
||||||
|
|
||||||
export const identifyPayload: IdentifyPayload = {
|
export const identifyPayload: DiscordIdentify = {
|
||||||
token: "",
|
token: "",
|
||||||
compress: true,
|
compress: true,
|
||||||
properties: {
|
properties: {
|
||||||
@@ -29,18 +30,6 @@ export const identifyPayload: IdentifyPayload = {
|
|||||||
shard: [0, 0],
|
shard: [0, 0],
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface IdentifyPayload {
|
|
||||||
token: string;
|
|
||||||
compress: boolean;
|
|
||||||
properties: {
|
|
||||||
$os: string;
|
|
||||||
$browser: string;
|
|
||||||
$device: string;
|
|
||||||
};
|
|
||||||
intents: number;
|
|
||||||
shard: [number, number];
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function startBot(config: BotConfig) {
|
export async function startBot(config: BotConfig) {
|
||||||
if (config.eventHandlers) eventHandlers = config.eventHandlers;
|
if (config.eventHandlers) eventHandlers = config.eventHandlers;
|
||||||
authorization = `Bot ${config.token}`;
|
authorization = `Bot ${config.token}`;
|
||||||
|
|||||||
+7
-11
@@ -1,12 +1,8 @@
|
|||||||
import {
|
import { botGatewayData, eventHandlers, proxyWSURL } from "../bot.ts";
|
||||||
botGatewayData,
|
|
||||||
eventHandlers,
|
|
||||||
IdentifyPayload,
|
|
||||||
proxyWSURL,
|
|
||||||
} from "../bot.ts";
|
|
||||||
import {
|
import {
|
||||||
DiscordBotGatewayData,
|
DiscordBotGatewayData,
|
||||||
DiscordHeartbeatPayload,
|
DiscordHeartbeatPayload,
|
||||||
|
DiscordIdentify,
|
||||||
DiscordPayload,
|
DiscordPayload,
|
||||||
FetchMembersOptions,
|
FetchMembersOptions,
|
||||||
GatewayOpcode,
|
GatewayOpcode,
|
||||||
@@ -41,7 +37,7 @@ interface RequestMemberQueuedRequest {
|
|||||||
|
|
||||||
export function createShard(
|
export function createShard(
|
||||||
data: DiscordBotGatewayData,
|
data: DiscordBotGatewayData,
|
||||||
identifyPayload: IdentifyPayload,
|
identifyPayload: DiscordIdentify,
|
||||||
resuming = false,
|
resuming = false,
|
||||||
shardID = 0,
|
shardID = 0,
|
||||||
) {
|
) {
|
||||||
@@ -174,7 +170,7 @@ export function createShard(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function identify(shard: BasicShard, payload: IdentifyPayload) {
|
function identify(shard: BasicShard, payload: DiscordIdentify) {
|
||||||
eventHandlers.debug?.(
|
eventHandlers.debug?.(
|
||||||
{
|
{
|
||||||
type: "gatewayIdentify",
|
type: "gatewayIdentify",
|
||||||
@@ -190,7 +186,7 @@ function identify(shard: BasicShard, payload: IdentifyPayload) {
|
|||||||
}, shard.id);
|
}, shard.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function resume(shard: BasicShard, payload: IdentifyPayload) {
|
function resume(shard: BasicShard, payload: DiscordIdentify) {
|
||||||
sendWS({
|
sendWS({
|
||||||
op: GatewayOpcode.Resume,
|
op: GatewayOpcode.Resume,
|
||||||
d: {
|
d: {
|
||||||
@@ -204,7 +200,7 @@ function resume(shard: BasicShard, payload: IdentifyPayload) {
|
|||||||
async function heartbeat(
|
async function heartbeat(
|
||||||
shard: BasicShard,
|
shard: BasicShard,
|
||||||
interval: number,
|
interval: number,
|
||||||
payload: IdentifyPayload,
|
payload: DiscordIdentify,
|
||||||
data: DiscordBotGatewayData,
|
data: DiscordBotGatewayData,
|
||||||
) {
|
) {
|
||||||
// We lost socket connection between heartbeats, resume connection
|
// We lost socket connection between heartbeats, resume connection
|
||||||
@@ -257,7 +253,7 @@ async function heartbeat(
|
|||||||
|
|
||||||
async function resumeConnection(
|
async function resumeConnection(
|
||||||
data: DiscordBotGatewayData,
|
data: DiscordBotGatewayData,
|
||||||
payload: IdentifyPayload,
|
payload: DiscordIdentify,
|
||||||
shardID: number,
|
shardID: number,
|
||||||
) {
|
) {
|
||||||
const shard = basicShards.get(shardID);
|
const shard = basicShards.get(shardID);
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { controllers } from "../api/controllers/mod.ts";
|
import { controllers } from "../api/controllers/mod.ts";
|
||||||
import { Guild } from "../api/structures/guild.ts";
|
import { Guild } from "../api/structures/guild.ts";
|
||||||
import { Member } from "../api/structures/mod.ts";
|
import { Member } from "../api/structures/mod.ts";
|
||||||
import { eventHandlers, IdentifyPayload } from "../bot.ts";
|
import { eventHandlers } from "../bot.ts";
|
||||||
import {
|
import {
|
||||||
DiscordBotGatewayData,
|
DiscordBotGatewayData,
|
||||||
|
DiscordIdentify,
|
||||||
DiscordPayload,
|
DiscordPayload,
|
||||||
FetchMembersOptions,
|
FetchMembersOptions,
|
||||||
GatewayOpcode,
|
GatewayOpcode,
|
||||||
@@ -26,7 +27,7 @@ export function allowNextShard(enabled = true) {
|
|||||||
|
|
||||||
export async function spawnShards(
|
export async function spawnShards(
|
||||||
data: DiscordBotGatewayData,
|
data: DiscordBotGatewayData,
|
||||||
payload: IdentifyPayload,
|
payload: DiscordIdentify,
|
||||||
shardID: number,
|
shardID: number,
|
||||||
lastShardID: number,
|
lastShardID: number,
|
||||||
skipChecks?: number,
|
skipChecks?: number,
|
||||||
|
|||||||
Reference in New Issue
Block a user