MCPcopy Create free account
hub / github.com/esmBot/esmBot / getGatewayData

Function getGatewayData

src/cluster/common.ts:31–58  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

29export type IncomingProcMessage = BaseProcMessage | ServerCountMessage;
30
31export async function getGatewayData() {
32 const base =
33 process.env.REST_PROXY && process.env.REST_PROXY !== "" ? process.env.REST_PROXY : "https://discord.com/api/v10";
34
35 const request = await fetch(`${base}/gateway/bot`, {
36 headers: {
37 Authorization: `Bot ${process.env.TOKEN}`,
38 },
39 });
40 if (!request.ok) {
41 throw new Error(`Failed to get gateway connection data: ${request.statusText}`);
42 }
43
44 const connectionData = (await request.json()) as {
45 shards?: number;
46 message: string;
47 };
48 if (!connectionData.shards) {
49 throw new Error(`Failed to read gateway connection data: ${connectionData.message}`);
50 }
51
52 const cpuAmount = availableParallelism();
53 const procAmount = Math.min(connectionData.shards, cpuAmount);
54 return {
55 procAmount,
56 shards: connectionData.shards,
57 };
58}
59
60// from eris-fleet
61export function calcShards(shards: number[], procs: number) {

Callers 2

node.tsFile · 0.90
createManageServerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected