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 {
|
||||
BotConfig,
|
||||
DiscordBotGatewayData,
|
||||
DiscordIdentify,
|
||||
EventHandlers,
|
||||
Intents,
|
||||
} from "./types/mod.ts";
|
||||
@@ -17,7 +18,7 @@ export let eventHandlers: EventHandlers = {};
|
||||
export let botGatewayData: DiscordBotGatewayData;
|
||||
export let proxyWSURL = `wss://gateway.discord.gg`;
|
||||
|
||||
export const identifyPayload: IdentifyPayload = {
|
||||
export const identifyPayload: DiscordIdentify = {
|
||||
token: "",
|
||||
compress: true,
|
||||
properties: {
|
||||
@@ -29,18 +30,6 @@ export const identifyPayload: IdentifyPayload = {
|
||||
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) {
|
||||
if (config.eventHandlers) eventHandlers = config.eventHandlers;
|
||||
authorization = `Bot ${config.token}`;
|
||||
|
||||
+7
-11
@@ -1,12 +1,8 @@
|
||||
import {
|
||||
botGatewayData,
|
||||
eventHandlers,
|
||||
IdentifyPayload,
|
||||
proxyWSURL,
|
||||
} from "../bot.ts";
|
||||
import { botGatewayData, eventHandlers, proxyWSURL } from "../bot.ts";
|
||||
import {
|
||||
DiscordBotGatewayData,
|
||||
DiscordHeartbeatPayload,
|
||||
DiscordIdentify,
|
||||
DiscordPayload,
|
||||
FetchMembersOptions,
|
||||
GatewayOpcode,
|
||||
@@ -41,7 +37,7 @@ interface RequestMemberQueuedRequest {
|
||||
|
||||
export function createShard(
|
||||
data: DiscordBotGatewayData,
|
||||
identifyPayload: IdentifyPayload,
|
||||
identifyPayload: DiscordIdentify,
|
||||
resuming = false,
|
||||
shardID = 0,
|
||||
) {
|
||||
@@ -174,7 +170,7 @@ export function createShard(
|
||||
};
|
||||
}
|
||||
|
||||
function identify(shard: BasicShard, payload: IdentifyPayload) {
|
||||
function identify(shard: BasicShard, payload: DiscordIdentify) {
|
||||
eventHandlers.debug?.(
|
||||
{
|
||||
type: "gatewayIdentify",
|
||||
@@ -190,7 +186,7 @@ function identify(shard: BasicShard, payload: IdentifyPayload) {
|
||||
}, shard.id);
|
||||
}
|
||||
|
||||
function resume(shard: BasicShard, payload: IdentifyPayload) {
|
||||
function resume(shard: BasicShard, payload: DiscordIdentify) {
|
||||
sendWS({
|
||||
op: GatewayOpcode.Resume,
|
||||
d: {
|
||||
@@ -204,7 +200,7 @@ function resume(shard: BasicShard, payload: IdentifyPayload) {
|
||||
async function heartbeat(
|
||||
shard: BasicShard,
|
||||
interval: number,
|
||||
payload: IdentifyPayload,
|
||||
payload: DiscordIdentify,
|
||||
data: DiscordBotGatewayData,
|
||||
) {
|
||||
// We lost socket connection between heartbeats, resume connection
|
||||
@@ -257,7 +253,7 @@ async function heartbeat(
|
||||
|
||||
async function resumeConnection(
|
||||
data: DiscordBotGatewayData,
|
||||
payload: IdentifyPayload,
|
||||
payload: DiscordIdentify,
|
||||
shardID: number,
|
||||
) {
|
||||
const shard = basicShards.get(shardID);
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { controllers } from "../api/controllers/mod.ts";
|
||||
import { Guild } from "../api/structures/guild.ts";
|
||||
import { Member } from "../api/structures/mod.ts";
|
||||
import { eventHandlers, IdentifyPayload } from "../bot.ts";
|
||||
import { eventHandlers } from "../bot.ts";
|
||||
import {
|
||||
DiscordBotGatewayData,
|
||||
DiscordIdentify,
|
||||
DiscordPayload,
|
||||
FetchMembersOptions,
|
||||
GatewayOpcode,
|
||||
@@ -26,7 +27,7 @@ export function allowNextShard(enabled = true) {
|
||||
|
||||
export async function spawnShards(
|
||||
data: DiscordBotGatewayData,
|
||||
payload: IdentifyPayload,
|
||||
payload: DiscordIdentify,
|
||||
shardID: number,
|
||||
lastShardID: number,
|
||||
skipChecks?: number,
|
||||
|
||||
Reference in New Issue
Block a user