bug fixes for proxy ws

This commit is contained in:
Skillz
2021-02-25 15:29:34 -05:00
parent 5f7269e0d1
commit cc6a93c180
+13 -9
View File
@@ -10,7 +10,7 @@ import { baseEndpoints, GATEWAY_VERSION } from "./util/constants.ts";
import { spawnShards } from "./ws/shard_manager.ts"; import { spawnShards } from "./ws/shard_manager.ts";
export let authorization = ""; export let authorization = "";
export let restAuthorization = ""; export let secretKey = "";
export let botID = ""; export let botID = "";
export let applicationID = ""; export let applicationID = "";
@@ -95,10 +95,9 @@ export async function startBigBrainBot(data: BigBrainBotConfig) {
authorization = `Bot ${data.token}`; authorization = `Bot ${data.token}`;
identifyPayload.token = `Bot ${data.token}`; identifyPayload.token = `Bot ${data.token}`;
if (data.restAuthorization) restAuthorization = data.restAuthorization; if (data.secretKey) secretKey = data.secretKey;
if (data.restURL) baseEndpoints.BASE_URL = data.restURL; if (data.restURL) baseEndpoints.BASE_URL = data.restURL;
if (data.cdnURL) baseEndpoints.CDN_URL = data.cdnURL; if (data.cdnURL) baseEndpoints.CDN_URL = data.cdnURL;
if (data.wsURL) proxyWSURL = data.wsURL;
if (data.eventHandlers) eventHandlers = data.eventHandlers; if (data.eventHandlers) eventHandlers = data.eventHandlers;
if (data.compress) { if (data.compress) {
identifyPayload.compress = data.compress; identifyPayload.compress = data.compress;
@@ -109,10 +108,14 @@ export async function startBigBrainBot(data: BigBrainBotConfig) {
0, 0,
); );
// PROXY DOESNT NEED US SPAWNING SHARDS
if (data.wsPort) {
// Need HTTP Server to listen to proxy
console.log("TODO: make http");
} else {
// Initial API connection to get info about bots connection // Initial API connection to get info about bots connection
botGatewayData = await getGatewayBot(); botGatewayData = await getGatewayBot();
proxyWSURL = botGatewayData.url;
if (!data.wsURL) proxyWSURL = botGatewayData.url;
await spawnShards( await spawnShards(
botGatewayData, botGatewayData,
identifyPayload, identifyPayload,
@@ -123,18 +126,19 @@ export async function startBigBrainBot(data: BigBrainBotConfig) {
: botGatewayData.shards), : botGatewayData.shards),
); );
} }
}
export interface BigBrainBotConfig extends BotConfig { export interface BigBrainBotConfig extends BotConfig {
/** The first shard to start at for this worker. Use this to control which shards to run in each worker. */ /** The first shard to start at for this worker. Use this to control which shards to run in each worker. */
firstShardID: number; firstShardID: number;
/** The last shard to start for this worker. By default it will be 25 + the firstShardID. */ /** The last shard to start for this worker. By default it will be 25 + the firstShardID. */
lastShardID?: number; lastShardID?: number;
/** This can be used to forward the ws handling to a proxy. */ /** This can be used to forward the ws handling to a proxy. It will disable the sharding done by the bot side. */
wsURL?: string; wsPort?: number;
/** This can be used to forward the REST handling to a proxy. */ /** This can be used to forward the REST handling to a proxy. */
restURL?: string; restURL?: string;
/** This can be used to forward the CDN handling to a proxy. */ /** This can be used to forward the CDN handling to a proxy. */
cdnURL?: string; cdnURL?: string;
/** This is the authorization header that your rest proxy will validate */ /** This is the authorization header that your servers will send. Helpful to prevent DDOS attacks and such. */
restAuthorization?: string; secretKey?: string;
} }