From 187e8235be199075f6d266e682cd9468293e2909 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Thu, 19 Aug 2021 21:15:31 +0300 Subject: [PATCH] Add REST request/429 debugging, temporarily disable message fetch hotfix --- backend/src/index.ts | 24 ++++++++++++++++++++++-- backend/src/utils/hotfixMessageFetch.ts | 22 ++++++++++++---------- debug/.gitignore | 2 ++ 3 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 debug/.gitignore diff --git a/backend/src/index.ts b/backend/src/index.ts index cdfbda9a..c2204193 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -22,6 +22,26 @@ import { errorMessage, isDiscordAPIError, isDiscordHTTPError, SECONDS, successMe import { loadYamlSafely } from "./utils/loadYamlSafely"; import { DecayingCounter } from "./utils/DecayingCounter"; +// === START REST DEBUG === +import fs from "fs"; +import path from "path"; +const APIRequest = require("discord.js/src/rest/APIRequest.js"); + +const dateStr = new Date().toISOString().replace(/[:.]/g, "-"); +const restDebugFile = path.join("../debug", `rest_${dateStr}.log`); +fs.writeFileSync(restDebugFile, ""); + +const originalMake = APIRequest.prototype.make; +// tslint:disable-next-line:only-arrow-functions +APIRequest.prototype.make = function(...args) { + const debugInfo = `${new Date().toISOString()} ${this.method.toUpperCase()} ${this.route}`; + fs.appendFileSync(restDebugFile, debugInfo + "\n", { encoding: "utf8" }); + // tslint:disable-next-line:no-console + console.log(`[API REQUEST] ${this.method} ${this.route}`); + return originalMake.call(this, ...args); +}; +// === END REST DEBUG === + if (!process.env.KEY) { // tslint:disable-next-line:no-console console.error("Project root .env with KEY is required!"); @@ -152,8 +172,8 @@ connect().then(async () => { const client = new Client({ partials: ["USER", "CHANNEL", "GUILD_MEMBER", "MESSAGE", "REACTION"], - restGlobalRateLimit: 20, - restTimeOffset: 1000, + restGlobalRateLimit: 50, + // restTimeOffset: 1000, // Disable mentions by default allowedMentions: { diff --git a/backend/src/utils/hotfixMessageFetch.ts b/backend/src/utils/hotfixMessageFetch.ts index 658c5aaf..63ab46c8 100644 --- a/backend/src/utils/hotfixMessageFetch.ts +++ b/backend/src/utils/hotfixMessageFetch.ts @@ -8,14 +8,16 @@ let n = 0; export function hotfixMessageFetch(channel: TextChannel | ThreadChannel, messageId: string): Promise { const thisN = ++n; - // tslint:disable-next-line:no-console - console.trace( - `[${thisN}] Queueing to fetch message id ${messageId} from channel ${channel.id} (queue size: ${queue.length})`, - ); - return queue.add(async () => { - await sleep(3000); - // tslint:disable-next-line:no-console - console.log(`[${thisN}] Fetching message id ${messageId} from channel ${channel.id}`); - return channel.messages.fetch(messageId); - }); + return channel.messages.fetch(messageId); + + // // tslint:disable-next-line:no-console + // console.trace( + // `[${thisN}] Queueing to fetch message id ${messageId} from channel ${channel.id} (queue size: ${queue.length})`, + // ); + // return queue.add(async () => { + // await sleep(3000); + // // tslint:disable-next-line:no-console + // console.log(`[${thisN}] Fetching message id ${messageId} from channel ${channel.id}`); + // return channel.messages.fetch(messageId); + // }); } diff --git a/debug/.gitignore b/debug/.gitignore new file mode 100644 index 00000000..120f485d --- /dev/null +++ b/debug/.gitignore @@ -0,0 +1,2 @@ +* +!/.gitignore