Skip to content

Commit 187e823

Browse files
committed
Add REST request/429 debugging, temporarily disable message fetch hotfix
1 parent 53fea6b commit 187e823

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

backend/src/index.ts

+22-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,26 @@ import { errorMessage, isDiscordAPIError, isDiscordHTTPError, SECONDS, successMe
2222
import { loadYamlSafely } from "./utils/loadYamlSafely";
2323
import { DecayingCounter } from "./utils/DecayingCounter";
2424

25+
// === START REST DEBUG ===
26+
import fs from "fs";
27+
import path from "path";
28+
const APIRequest = require("discord.js/src/rest/APIRequest.js");
29+
30+
const dateStr = new Date().toISOString().replace(/[:.]/g, "-");
31+
const restDebugFile = path.join("../debug", `rest_${dateStr}.log`);
32+
fs.writeFileSync(restDebugFile, "");
33+
34+
const originalMake = APIRequest.prototype.make;
35+
// tslint:disable-next-line:only-arrow-functions
36+
APIRequest.prototype.make = function(...args) {
37+
const debugInfo = `${new Date().toISOString()} ${this.method.toUpperCase()} ${this.route}`;
38+
fs.appendFileSync(restDebugFile, debugInfo + "\n", { encoding: "utf8" });
39+
// tslint:disable-next-line:no-console
40+
console.log(`[API REQUEST] ${this.method} ${this.route}`);
41+
return originalMake.call(this, ...args);
42+
};
43+
// === END REST DEBUG ===
44+
2545
if (!process.env.KEY) {
2646
// tslint:disable-next-line:no-console
2747
console.error("Project root .env with KEY is required!");
@@ -152,8 +172,8 @@ connect().then(async () => {
152172
const client = new Client({
153173
partials: ["USER", "CHANNEL", "GUILD_MEMBER", "MESSAGE", "REACTION"],
154174

155-
restGlobalRateLimit: 20,
156-
restTimeOffset: 1000,
175+
restGlobalRateLimit: 50,
176+
// restTimeOffset: 1000,
157177

158178
// Disable mentions by default
159179
allowedMentions: {

backend/src/utils/hotfixMessageFetch.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ let n = 0;
88
export function hotfixMessageFetch(channel: TextChannel | ThreadChannel, messageId: string): Promise<Message> {
99
const thisN = ++n;
1010

11-
// tslint:disable-next-line:no-console
12-
console.trace(
13-
`[${thisN}] Queueing to fetch message id ${messageId} from channel ${channel.id} (queue size: ${queue.length})`,
14-
);
15-
return queue.add(async () => {
16-
await sleep(3000);
17-
// tslint:disable-next-line:no-console
18-
console.log(`[${thisN}] Fetching message id ${messageId} from channel ${channel.id}`);
19-
return channel.messages.fetch(messageId);
20-
});
11+
return channel.messages.fetch(messageId);
12+
13+
// // tslint:disable-next-line:no-console
14+
// console.trace(
15+
// `[${thisN}] Queueing to fetch message id ${messageId} from channel ${channel.id} (queue size: ${queue.length})`,
16+
// );
17+
// return queue.add(async () => {
18+
// await sleep(3000);
19+
// // tslint:disable-next-line:no-console
20+
// console.log(`[${thisN}] Fetching message id ${messageId} from channel ${channel.id}`);
21+
// return channel.messages.fetch(messageId);
22+
// });
2123
}

debug/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!/.gitignore

0 commit comments

Comments
 (0)