mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-14 21:31:50 +00:00
Add REST request/429 debugging, temporarily disable message fetch hotfix
This commit is contained in:
parent
53fea6b88c
commit
187e8235be
3 changed files with 36 additions and 12 deletions
|
@ -22,6 +22,26 @@ import { errorMessage, isDiscordAPIError, isDiscordHTTPError, SECONDS, successMe
|
||||||
import { loadYamlSafely } from "./utils/loadYamlSafely";
|
import { loadYamlSafely } from "./utils/loadYamlSafely";
|
||||||
import { DecayingCounter } from "./utils/DecayingCounter";
|
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) {
|
if (!process.env.KEY) {
|
||||||
// tslint:disable-next-line:no-console
|
// tslint:disable-next-line:no-console
|
||||||
console.error("Project root .env with KEY is required!");
|
console.error("Project root .env with KEY is required!");
|
||||||
|
@ -152,8 +172,8 @@ connect().then(async () => {
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
partials: ["USER", "CHANNEL", "GUILD_MEMBER", "MESSAGE", "REACTION"],
|
partials: ["USER", "CHANNEL", "GUILD_MEMBER", "MESSAGE", "REACTION"],
|
||||||
|
|
||||||
restGlobalRateLimit: 20,
|
restGlobalRateLimit: 50,
|
||||||
restTimeOffset: 1000,
|
// restTimeOffset: 1000,
|
||||||
|
|
||||||
// Disable mentions by default
|
// Disable mentions by default
|
||||||
allowedMentions: {
|
allowedMentions: {
|
||||||
|
|
|
@ -8,14 +8,16 @@ let n = 0;
|
||||||
export function hotfixMessageFetch(channel: TextChannel | ThreadChannel, messageId: string): Promise<Message> {
|
export function hotfixMessageFetch(channel: TextChannel | ThreadChannel, messageId: string): Promise<Message> {
|
||||||
const thisN = ++n;
|
const thisN = ++n;
|
||||||
|
|
||||||
// tslint:disable-next-line:no-console
|
return channel.messages.fetch(messageId);
|
||||||
console.trace(
|
|
||||||
`[${thisN}] Queueing to fetch message id ${messageId} from channel ${channel.id} (queue size: ${queue.length})`,
|
// // tslint:disable-next-line:no-console
|
||||||
);
|
// console.trace(
|
||||||
return queue.add(async () => {
|
// `[${thisN}] Queueing to fetch message id ${messageId} from channel ${channel.id} (queue size: ${queue.length})`,
|
||||||
await sleep(3000);
|
// );
|
||||||
// tslint:disable-next-line:no-console
|
// return queue.add(async () => {
|
||||||
console.log(`[${thisN}] Fetching message id ${messageId} from channel ${channel.id}`);
|
// await sleep(3000);
|
||||||
return channel.messages.fetch(messageId);
|
// // tslint:disable-next-line:no-console
|
||||||
});
|
// console.log(`[${thisN}] Fetching message id ${messageId} from channel ${channel.id}`);
|
||||||
|
// return channel.messages.fetch(messageId);
|
||||||
|
// });
|
||||||
}
|
}
|
||||||
|
|
2
debug/.gitignore
vendored
Normal file
2
debug/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
*
|
||||||
|
!/.gitignore
|
Loading…
Add table
Reference in a new issue