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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 287 by rakin, Mon Jul 29 17:29:22 2024 UTC revision 299 by rakin, Mon Jul 29 17:29:25 2024 UTC
# Line 1  Line 1 
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 { exit } from "process";
6    import DiscordClient from "../../client/Client";
7    import { LogLevel } from "../../services/DebugLogger";
8  import BaseEvent from "../../utils/structures/BaseEvent";  import BaseEvent from "../../utils/structures/BaseEvent";
9    
10  export default class DebugEvent extends BaseEvent {  export default class DebugEvent extends BaseEvent {
11        logFile: string = path.resolve(__dirname, "..", "..", "..", "logs", 'debug.log');
12    
13      constructor() {      constructor() {
14          super("debug");          super("debug");
15            appendFile(this.logFile, `\n\n[${format(new Date(), "yyyy-MM-dd'T'HH:mm:ss.SSSxxx")}] [STARTUP] The system has started.\n`);
16      }      }
17    
18      async run(e: any): Promise <void> {      async run(client: DiscordClient, e: string): Promise <void> {
19         console.log("DEBUG: ", e);          if (e.includes("Provided token") || e.includes(process.env.TOKEN!) || e.includes("[READY] Session ")) {
20                console.log('DEBUG: [One hidden log]');
21                return;
22            }
23    
24            console.log("DEBUG: ", e);
25            await appendFile(this.logFile, `[${format(new Date(), "yyyy-MM-dd'T'HH:mm:ss.SSSxxx")}] [LOG] ${e}\n`);
26    
27            if (process.env.PLATFORM === 'replit' && e.includes("Hit a 429") && !client.isReady()) {
28                console.log("DEBUG: ", "Restart Required");
29                await appendFile(this.logFile, `[${format(new Date(), "yyyy-MM-dd'T'HH:mm:ss.SSSxxx")}] [LOG] ${e}\n`);
30                await appendFile(this.logFile, `[${format(new Date(), "yyyy-MM-dd'T'HH:mm:ss.SSSxxx")}] [FATAL] Restart Required\n`);
31                await client.debugLogger.logToHomeServer("Discord Ratelimit [429]: System restart required.\nAutomated restart is in progress.", LogLevel.WARN);
32    
33                exec("kill 1");
34                return;
35            }
36      }      }
37  }  }

Legend:
Removed from v.287  
changed lines
  Added in v.299

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26