From 68111c7d653168f3223c26cc5ef845d9ff317c11 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 8 May 2021 11:30:46 +0200 Subject: [PATCH] bigint fixxess --- src/util/loop_object.ts | 4 ++-- src/ws/process_queue.ts | 16 +++++++++++++++- src/ws/ws.ts | 4 ++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/util/loop_object.ts b/src/util/loop_object.ts index 41d31ec46..d31422f6e 100644 --- a/src/util/loop_object.ts +++ b/src/util/loop_object.ts @@ -1,6 +1,6 @@ import { eventHandlers } from "../bot.ts"; -export function loopObject( +export function loopObject>( obj: Record, handler: (value: unknown, key: string) => unknown, log: string, @@ -35,5 +35,5 @@ export function loopObject( } } - return res; + return res as T; } diff --git a/src/ws/process_queue.ts b/src/ws/process_queue.ts index 5a87770ac..f21ae987d 100644 --- a/src/ws/process_queue.ts +++ b/src/ws/process_queue.ts @@ -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, + (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. diff --git a/src/ws/ws.ts b/src/ws/ws.ts index 76519d39f..b9611681a 100644 --- a/src/ws/ws.ts +++ b/src/ws/ws.ts @@ -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; }