2 |
import { format } from "date-fns"; |
import { format } from "date-fns"; |
3 |
import { appendFile } from "fs/promises"; |
import { appendFile } from "fs/promises"; |
4 |
import path from "path"; |
import path from "path"; |
|
import { exit } from "process"; |
|
5 |
import DiscordClient from "../../client/Client"; |
import DiscordClient from "../../client/Client"; |
6 |
|
import { LogLevel } from "../../services/DebugLogger"; |
7 |
import BaseEvent from "../../utils/structures/BaseEvent"; |
import BaseEvent from "../../utils/structures/BaseEvent"; |
8 |
|
|
9 |
export default class DebugEvent extends BaseEvent { |
export default class DebugEvent extends BaseEvent { |
10 |
logFile: string = path.resolve(__dirname, "..", "..", "..", "logs", 'debug.log'); |
logFile: string = path.join(process.env.SUDO_PREFIX ?? (__dirname + "/../../../"), "logs", 'debug.log'); |
11 |
|
|
12 |
constructor() { |
constructor() { |
13 |
super("debug"); |
super("debug"); |
23 |
console.log("DEBUG: ", e); |
console.log("DEBUG: ", e); |
24 |
await appendFile(this.logFile, `[${format(new Date(), "yyyy-MM-dd'T'HH:mm:ss.SSSxxx")}] [LOG] ${e}\n`); |
await appendFile(this.logFile, `[${format(new Date(), "yyyy-MM-dd'T'HH:mm:ss.SSSxxx")}] [LOG] ${e}\n`); |
25 |
|
|
26 |
if (process.env.PLATFORM === 'replit' && e.includes("Hit a 429 while executing a request") && !client.isReady()) { |
if (process.env.PLATFORM === 'replit' && e.includes("Hit a 429") && !client.isReady()) { |
27 |
|
console.log("DEBUG: ", "Restart Required"); |
28 |
|
await appendFile(this.logFile, `[${format(new Date(), "yyyy-MM-dd'T'HH:mm:ss.SSSxxx")}] [LOG] ${e}\n`); |
29 |
|
await appendFile(this.logFile, `[${format(new Date(), "yyyy-MM-dd'T'HH:mm:ss.SSSxxx")}] [FATAL] Restart Required\n`); |
30 |
|
await client.debugLogger.logToHomeServer("Discord Ratelimit [429]: System restart required.\nAutomated restart is in progress.", LogLevel.WARN); |
31 |
|
|
32 |
exec("kill 1"); |
exec("kill 1"); |
33 |
return; |
return; |
34 |
} |
} |