/[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 51 by rakin, Mon Jul 29 17:28:23 2024 UTC revision 318 by rakin, Mon Jul 29 17:29:31 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';
 import SpamFilter from '../automod/SpamFilter';  
9  import SnippetManager from '../services/SnippetManager';  import SnippetManager from '../services/SnippetManager';
10  import AFKEngine from '../services/AFKEngine';  import AFKEngine from '../services/AFKEngine';
11  import Auth from '../services/Auth';  import Auth from '../services/Auth';
# Line 13  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';
16    import StartupManager from '../services/StartupManager';
17    import AutoClear from '../automod/AutoClear';
18    import RandomStatus from '../services/RandomStatus';
19    import DebugLogger from '../services/DebugLogger';
20    import BaseCLICommand from '../utils/structures/BaseCLICommand';
21    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    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>();
32        private _cliCommands = new Collection<string, BaseCLICommand>();
33      private _events = new Collection<string, BaseEvent>();      private _events = new Collection<string, BaseEvent>();
34    
35      rootdir: string;      rootdir: string;
# Line 23  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        serviceManager: ServiceManager;
42    
43        logger: Logger = {} as Logger;
44        snippetManager: SnippetManager = {} as SnippetManager;
45        afkEngine: AFKEngine = {} as AFKEngine;
46        auth: Auth = {} as Auth;
47        spamFilter: SpamFilter = {} as SpamFilter;
48        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    
88      constructor(options: ClientOptions, rootdir: string = __dirname) {      constructor(options: ClientOptions, rootdir: string = __dirname) {
89          super({          super({
90              ws: {              ws: {
91                  properties: {                  properties: {
92                      $browser: "Discord iOS"                      browser: "Discord iOS"
93                  }                  }
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');        
107    
108          this.rootdir = rootdir;          this.rootdir = rootdir;
109            
110            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(path.resolve(rootdir, 'database.db'), 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);
136                    
137          DiscordClient.client = this;          discordModals(this);        
138      }      }
139    
140      get commands(): Collection<string, BaseCommand> {      get commands(): Collection<string, BaseCommand> {
141          return this._commands;          return this._commands;
142      }      }
143    
144        get cliCommands(): Collection<string, BaseCLICommand> {
145            return this._cliCommands;
146        }
147    
148      get events(): Collection<string, BaseEvent> {      get events(): Collection<string, BaseEvent> {
149          return this._events;          return this._events;
150      }      }
# Line 73  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.resolve(__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.51  
changed lines
  Added in v.318

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26