()
| 29 | export type IncomingProcMessage = BaseProcMessage | ServerCountMessage; |
| 30 | |
| 31 | export 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 |
| 61 | export function calcShards(shards: number[], procs: number) { |
no outgoing calls
no test coverage detected