bigint fixxess

This commit is contained in:
ITOH
2021-05-08 11:30:46 +02:00
parent c2bf01de82
commit 68111c7d65
3 changed files with 19 additions and 5 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
import { eventHandlers } from "../bot.ts";
export function loopObject(
export function loopObject<T = Record<string, unknown>>(
obj: Record<string, unknown>,
handler: (value: unknown, key: string) => unknown,
log: string,
@@ -35,5 +35,5 @@ export function loopObject(
}
}
return res;
return res as T;
}
+15 -1
View File
@@ -1,5 +1,6 @@
import { loopObject } from "../util/loop_object.ts";
import { delay } from "../util/utils.ts";
import { ws } from "./ws.ts";
import { WebSocketRequest, ws } from "./ws.ts";
export async function processQueue(id: number) {
const shard = ws.shards.get(id);
@@ -23,6 +24,19 @@ export async function processQueue(id: number) {
// Send a request that is next in line
const request = shard.queue.shift();
if (request?.d) {
request.d = loopObject(
request.d as Record<string, unknown>,
(value) =>
typeof value === "bigint"
? value.toString()
: 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.`,
);
}
shard.ws.send(JSON.stringify(request));
// Counter is useful for preventing 120/m requests.
+2 -2
View File
@@ -162,8 +162,8 @@ export interface DiscordenoShard {
export interface WebSocketRequest {
op: DiscordGatewayOpcodes;
d: unknown;
// guildId: string;
// guildId: bigint;
// shardId: number;
// nonce?: string;
// nonce?: bigint;
// options?: Record<string, unknown>;
}