More conversion

This commit is contained in:
TriForMine
2021-10-08 08:05:04 +02:00
parent 101fd50acb
commit dcbf0fcaaa
17 changed files with 166 additions and 164 deletions

View File

@@ -1,16 +1,16 @@
import { loopObject } from "../util/loop_object.ts";
import { delay } from "../util/utils.ts";
import { ws } from "./ws.ts";
import {GatewayManager} from "../bot.ts";
export async function processQueue(id: number) {
const shard = ws.shards.get(id);
export async function processQueue(gateway: GatewayManager, id: number) {
const shard = gateway.shards.get(id);
// If no items or its already processing then exit
if (!shard?.queue.length || shard.processingQueue) return;
shard.processingQueue = true;
while (shard.queue.length) {
if (shard.ws.readyState !== WebSocket.OPEN) {
if (shard.gateway.readyState !== WebSocket.OPEN) {
shard.processingQueue = false;
return;
}
@@ -34,20 +34,20 @@ export async function processQueue(id: number) {
: Array.isArray(value)
? value.map((v) => (typeof v === "bigint" ? v.toString() : v))
: value,
`Running forEach loop in ws.processQueue function for changing bigints to strings.`
`Running forEach loop in gateway.processQueue function for changing bigints to strings.`
);
}
ws.log("RAW_SEND", shard.id, request);
gateway.log("RAW_SEND", shard.id, request);
shard.ws.send(JSON.stringify(request));
shard.gateway.send(JSON.stringify(request));
// Counter is useful for preventing 120/m requests.
shard.queueCounter++;
// Handle if the requests have been maxed
if (shard.queueCounter >= 118) {
ws.log("DEBUG", {
gateway.log("DEBUG", {
message: "Max gateway requests per minute reached setting timeout for one minute",
shardId: shard.id,
});