/[sudobot]/trunk/src/events/debug/DebugEvent.ts
ViewVC logotype

Contents of /trunk/src/events/debug/DebugEvent.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 372 - (show annotations)
Mon Jul 29 17:29:50 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 1681 byte(s)
fix(errors): error handler
1 import { exec } from "child_process";
2 import { format } from "date-fns";
3 import { appendFile } from "fs/promises";
4 import path from "path";
5 import DiscordClient from "../../client/Client";
6 import { LogLevel } from "../../services/DebugLogger";
7 import BaseEvent from "../../utils/structures/BaseEvent";
8
9 export default class DebugEvent extends BaseEvent {
10 logFile: string = path.join(process.env.SUDO_PREFIX ?? (__dirname + "/../../../"), "logs", 'debug.log');
11
12 constructor() {
13 super("debug");
14 appendFile(this.logFile, `\n\n[${format(new Date(), "yyyy-MM-dd'T'HH:mm:ss.SSSxxx")}] [STARTUP] The system has started.\n`);
15 }
16
17 async run(client: DiscordClient, e: string): Promise <void> {
18 if (e.includes("Provided token") || e.includes(process.env.TOKEN!) || e.includes("[READY] Session ")) {
19 console.log('DEBUG: [One hidden log]');
20 return;
21 }
22
23 console.log("DEBUG: ", e);
24 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") && !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");
33 return;
34 }
35 }
36 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26