/[sudobot]/trunk/src/client/Client.ts
ViewVC logotype

Diff of /trunk/src/client/Client.ts

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

revision 225 by rakin, Mon Jul 29 17:29:06 2024 UTC revision 372 by rakin, Mon Jul 29 17:29:50 2024 UTC
# Line 4  import BaseCommand from '../utils/struct Line 4  import BaseCommand from '../utils/struct
4  import { Config } from './Config';  import { Config } from './Config';
5  import Database from './Database';  import Database from './Database';
6  import path from 'path';  import path from 'path';
7    import { appendFile } from "fs/promises";
8  import Logger from '../automod/Logger';  import Logger from '../automod/Logger';
9  import SnippetManager from '../services/SnippetManager';  import SnippetManager from '../services/SnippetManager';
10  import AFKEngine from '../services/AFKEngine';  import AFKEngine from '../services/AFKEngine';
# Line 12  import MessageFilter from '../automod/Me Line 13  import MessageFilter from '../automod/Me
13  import AntiRaid from '../automod/AntiRaid';  import AntiRaid from '../automod/AntiRaid';
14  import Starboard from '../services/Starboard';  import Starboard from '../services/Starboard';
15  import Server from '../api/Server';  import Server from '../api/Server';
 import Cooldown from '../automod/Cooldown';  
16  import StartupManager from '../services/StartupManager';  import StartupManager from '../services/StartupManager';
17  import AutoClear from '../automod/AutoClear';  import AutoClear from '../automod/AutoClear';
18  import RandomStatus from '../services/RandomStatus';  import RandomStatus from '../services/RandomStatus';
# Line 23  import SpamFilter from '../automod/SpamF Line 23  import SpamFilter from '../automod/SpamF
23  import Verification from '../services/Verification';  import Verification from '../services/Verification';
24  import Welcomer from '../services/Welcomer';  import Welcomer from '../services/Welcomer';
25  import Antijoin from '../automod/Antijoin';  import Antijoin from '../automod/Antijoin';
26    import Automute from '../automod/Automute';
27    import ServiceManager from './ServiceManager';
28    import ChannelLockManager from '../services/ChannelLockManager';
29    
30  export default class DiscordClient extends Client {  export default class DiscordClient extends Client {
31      private _commands = new Collection<string, BaseCommand>();      private _commands = new Collection<string, BaseCommand>();
# Line 34  export default class DiscordClient exten Line 37  export default class DiscordClient exten
37    
38      config: Config;      config: Config;
39      db: Database;      db: Database;
     logger: Logger;  
     snippetManager: SnippetManager;  
     afkEngine: AFKEngine;  
     auth: Auth;  
     spamFilter: SpamFilter;  
     messageFilter: MessageFilter;  
     antiraid: AntiRaid;  
     starboard: Starboard;  
40      server: Server;      server: Server;
41      cooldown: Cooldown;      serviceManager: ServiceManager;
42      startupManager: StartupManager;  
43      autoClear: AutoClear;      logger: Logger = {} as Logger;
44      randomStatus: RandomStatus;      snippetManager: SnippetManager = {} as SnippetManager;
45      debugLogger: DebugLogger;      afkEngine: AFKEngine = {} as AFKEngine;
46      verification: Verification;      auth: Auth = {} as Auth;
47      welcomer: Welcomer;      spamFilter: SpamFilter = {} as SpamFilter;
48      antijoin: Antijoin;      messageFilter: MessageFilter = {} as MessageFilter;
49        antiraid: AntiRaid = {} as AntiRaid;
50        starboard: Starboard = {} as Starboard;
51        startupManager: StartupManager = {} as StartupManager;
52        autoClear: AutoClear = {} as AutoClear;
53        randomStatus: RandomStatus = {} as RandomStatus;
54        debugLogger: DebugLogger = {} as DebugLogger;
55        verification: Verification = {} as Verification;
56        welcomer: Welcomer = {} as Welcomer;
57        antijoin: Antijoin = {} as Antijoin;
58        automute: Automute = {} as Automute;
59        channelLock: ChannelLockManager = {} as ChannelLockManager;
60    
61        aliases = {
62            automod: path.resolve(__dirname, '..', 'automod'),
63            services: path.resolve(__dirname, '..', 'services'),
64        };
65    
66        services = {
67            "@services/DebugLogger": "debugLogger",
68            "@automod/Logger": "logger",
69            "@services/SnippetManager": "snippetManager",
70            "@services/AFKEngine": "afkEngine",
71            "@services/Auth": "auth",
72            "@automod/SpamFilter": "spamFilter",
73            "@automod/MessageFilter": "messageFilter",
74            "@automod/AntiRaid": "antiraid",
75            "@services/Starboard": "starboard",
76            "@services/StartupManager": "startupManager",
77            "@automod/AutoClear": "autoClear",
78            "@services/RandomStatus": "randomStatus",
79            "@services/Verification": "verification",
80            "@services/Welcomer": "welcomer",
81            "@services/ChannelLockManager": "channelLock",
82            "@automod/Antijoin": "antijoin",
83            "@automod/Automute": "automute",
84        };
85    
86      static client: DiscordClient;      static client: DiscordClient;
87    
# Line 63  export default class DiscordClient exten Line 94  export default class DiscordClient exten
94              },              },
95              ...options              ...options
96          });          });
97    
98            process.on('uncaughtException', (error, origin) => {
99                console.log('Uncaught', error);
100                this.handleCrash(error, origin).then(() => process.exit(-1)).catch(err => {
101                    console.log(err);
102                    process.exit(-1);
103                });
104            });
105                    
106          console.log('init');                  console.log('init');        
107    
# Line 71  export default class DiscordClient exten Line 110  export default class DiscordClient exten
110          DiscordClient.client = this;          DiscordClient.client = this;
111    
112          this.config = new Config(this);          this.config = new Config(this);
113          this.db = new Database(path.resolve(rootdir, 'database.db'), this);          this.db = new Database(this);
114          this.logger = new Logger(this);          this.serviceManager = new ServiceManager(this, this.aliases);
115          this.snippetManager = new SnippetManager(this);          this.serviceManager.load(this.services);
116          this.afkEngine = new AFKEngine(this);  
117          this.auth = new Auth(this);          // this.logger = new Logger(this);
118          this.spamFilter = new SpamFilter(this);          // this.snippetManager = new SnippetManager(this);
119          this.messageFilter = new MessageFilter(this);          // this.afkEngine = new AFKEngine(this);
120          this.antiraid = new AntiRaid(this);          // this.auth = new Auth(this);
121          this.starboard = new Starboard(this);          // this.spamFilter = new SpamFilter(this);
122            // this.messageFilter = new MessageFilter(this);
123            // this.antiraid = new AntiRaid(this);
124            // this.starboard = new Starboard(this);
125            // this.cooldown = new Cooldown(this);
126            // this.startupManager = new StartupManager(this);
127            // this.autoClear = new AutoClear(this);
128            // this.randomStatus = new RandomStatus(this);
129            // this.debugLogger = new DebugLogger(this);
130            // this.verification = new Verification(this);
131            // this.welcomer = new Welcomer(this);
132            // this.antijoin = new Antijoin(this);
133            // this.automute = new Automute(this);
134    
135          this.server = new Server(this);          this.server = new Server(this);
         this.cooldown = new Cooldown(this);  
         this.startupManager = new StartupManager(this);  
         this.autoClear = new AutoClear(this);  
         this.randomStatus = new RandomStatus(this);  
         this.debugLogger = new DebugLogger(this);  
         this.verification = new Verification(this);  
         this.welcomer = new Welcomer(this);  
         this.antijoin = new Antijoin(this);  
136                    
137          discordModals(this);                  discordModals(this);        
138      }      }
# Line 108  export default class DiscordClient exten Line 152  export default class DiscordClient exten
152      setMessage(msg: Message | Interaction) {      setMessage(msg: Message | Interaction) {
153          this.msg = msg;          this.msg = msg;
154      }      }
155    
156        async handleCrash(error: Error, origin: NodeJS.UncaughtExceptionOrigin) {
157            console.log('here');
158            await appendFile(path.join(process.env.SUDO_PREFIX ?? (__dirname + "/../../"), "logs", "error.log"), `Uncaught ${error.name}: ${error.message}\n+ ${error.stack}`);
159            await this.debugLogger.logToHomeServer(`Uncaught ${error.name}: ${error.message}\n${error.stack}`);
160        }
161  }  }

Legend:
Removed from v.225  
changed lines
  Added in v.372

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26