/[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 81 by rakin, Mon Jul 29 17:28:31 2024 UTC revision 237 by rakin, Mon Jul 29 17:29:09 2024 UTC
# Line 5  import { Config } from './Config'; Line 5  import { Config } from './Config';
5  import Database from './Database';  import Database from './Database';
6  import path from 'path';  import path from 'path';
7  import Logger from '../automod/Logger';  import Logger from '../automod/Logger';
 import SpamFilter from '../automod/SpamFilter';  
8  import SnippetManager from '../services/SnippetManager';  import SnippetManager from '../services/SnippetManager';
9  import AFKEngine from '../services/AFKEngine';  import AFKEngine from '../services/AFKEngine';
10  import Auth from '../services/Auth';  import Auth from '../services/Auth';
# Line 20  import RandomStatus from '../services/Ra Line 19  import RandomStatus from '../services/Ra
19  import DebugLogger from '../services/DebugLogger';  import DebugLogger from '../services/DebugLogger';
20  import BaseCLICommand from '../utils/structures/BaseCLICommand';  import BaseCLICommand from '../utils/structures/BaseCLICommand';
21  import discordModals from 'discord-modals';  import discordModals from 'discord-modals';
22    import SpamFilter from '../automod/SpamFilter';
23    import Verification from '../services/Verification';
24    import Welcomer from '../services/Welcomer';
25    import Antijoin from '../automod/Antijoin';
26    import Automute from '../automod/Automute';
27    import ServiceManager from './ServiceManager';
28    
29  export default class DiscordClient extends Client {  export default class DiscordClient extends Client {
30      private _commands = new Collection<string, BaseCommand>();      private _commands = new Collection<string, BaseCommand>();
# Line 31  export default class DiscordClient exten Line 36  export default class DiscordClient exten
36    
37      config: Config;      config: Config;
38      db: Database;      db: Database;
     logger: Logger;  
     snippetManager: SnippetManager;  
     afkEngine: AFKEngine;  
     auth: Auth;  
     spamFilter: SpamFilter;  
     messageFilter: MessageFilter;  
     antiraid: AntiRaid;  
     starboard: Starboard;  
39      server: Server;      server: Server;
40      cooldown: Cooldown;      serviceManager: ServiceManager;
41      startupManager: StartupManager;  
42      autoClear: AutoClear;      logger: Logger = {} as Logger;
43      randomStatus: RandomStatus;      snippetManager: SnippetManager = {} as SnippetManager;
44      debugLogger: DebugLogger;      afkEngine: AFKEngine = {} as AFKEngine;
45        auth: Auth = {} as Auth;
46        spamFilter: SpamFilter = {} as SpamFilter;
47        messageFilter: MessageFilter = {} as MessageFilter;
48        antiraid: AntiRaid = {} as AntiRaid;
49        starboard: Starboard = {} as Starboard;
50        cooldown: Cooldown = {} as Cooldown;
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    
60        aliases = {
61            automod: path.resolve(__dirname, '..', 'automod'),
62            services: path.resolve(__dirname, '..', 'services'),
63        };
64    
65        services = {
66            "@services/DebugLogger": "debugLogger",
67            "@automod/Logger": "logger",
68            "@services/SnippetManager": "snippetManager",
69            "@services/AFKEngine": "afkEngine",
70            "@services/Auth": "auth",
71            "@automod/SpamFilter": "spamFilter",
72            "@automod/MessageFilter": "messageFilter",
73            "@automod/AntiRaid": "antiraid",
74            "@services/Starboard": "starboard",
75            "@automod/Cooldown": "cooldown",
76            "@services/StartupManager": "startupManager",
77            "@automod/AutoClear": "autoClear",
78            "@services/RandomStatus": "randomStatus",
79            "@services/Verification": "verification",
80            "@services/Welcomer": "welcomer",
81            "@automod/Antijoin": "antijoin",
82            "@automod/Automute": "automute",
83        };
84    
85      static client: DiscordClient;      static client: DiscordClient;
86    
87      constructor(options: ClientOptions, rootdir: string = __dirname) {      constructor(options: ClientOptions, rootdir: string = __dirname) {
88          super({          super({
89              ws: {              ws: {
90                  properties: {                  properties: {
91                      $browser: "Discord iOS"                      browser: "Discord iOS"
92                  }                  }
93              },              },
94              ...options              ...options
95          });          });
96    
97            process.on('uncaughtException', (error, origin) => {
98                console.log('Uncaught', error);
99                this.handleCrash(error, origin).then(() => process.exit(-1)).catch(err => {
100                    console.log(err);
101                    process.exit(-1);
102                });
103            });
104            
105            console.log('init');        
106    
107          this.rootdir = rootdir;          this.rootdir = rootdir;
108            
109            DiscordClient.client = this;
110    
111          this.config = new Config(this);          this.config = new Config(this);
112          this.db = new Database(path.resolve(rootdir, 'database.db'), this);          this.db = new Database(path.resolve(rootdir, 'database.db'), this);
113          this.logger = new Logger(this);          this.serviceManager = new ServiceManager(this, this.aliases);
114          this.snippetManager = new SnippetManager(this);          this.serviceManager.load(this.services);
115          this.afkEngine = new AFKEngine(this);  
116          this.auth = new Auth(this);          // this.logger = new Logger(this);
117          this.spamFilter = new SpamFilter(this);          // this.snippetManager = new SnippetManager(this);
118          this.messageFilter = new MessageFilter(this);          // this.afkEngine = new AFKEngine(this);
119          this.antiraid = new AntiRaid(this);          // this.auth = new Auth(this);
120          this.starboard = new Starboard(this);          // this.spamFilter = new SpamFilter(this);
121            // this.messageFilter = new MessageFilter(this);
122            // this.antiraid = new AntiRaid(this);
123            // this.starboard = new Starboard(this);
124            // this.cooldown = new Cooldown(this);
125            // this.startupManager = new StartupManager(this);
126            // this.autoClear = new AutoClear(this);
127            // this.randomStatus = new RandomStatus(this);
128            // this.debugLogger = new DebugLogger(this);
129            // this.verification = new Verification(this);
130            // this.welcomer = new Welcomer(this);
131            // this.antijoin = new Antijoin(this);
132            // this.automute = new Automute(this);
133    
134          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);  
135                    
136          DiscordClient.client = this;          discordModals(this);        
         discordModals(this);  
137      }      }
138    
139      get commands(): Collection<string, BaseCommand> {      get commands(): Collection<string, BaseCommand> {
# Line 96  export default class DiscordClient exten Line 151  export default class DiscordClient exten
151      setMessage(msg: Message | Interaction) {      setMessage(msg: Message | Interaction) {
152          this.msg = msg;          this.msg = msg;
153      }      }
154    
155        async handleCrash(error: Error, origin: NodeJS.UncaughtExceptionOrigin) {
156            await this.debugLogger.logToHomeServer(`Uncaught ${error.name}: ${error.message}\n${error.stack}`);
157        }
158  }  }

Legend:
Removed from v.81  
changed lines
  Added in v.237

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26