/[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 65 by rakin, Mon Jul 29 17:28:27 2024 UTC revision 241 by rakin, Mon Jul 29 17:29:10 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 16  import Server from '../api/Server'; Line 15  import Server from '../api/Server';
15  import Cooldown from '../automod/Cooldown';  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';
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 26  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        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        cooldown: Cooldown = {} as Cooldown;
52        startupManager: StartupManager = {} as StartupManager;
53        autoClear: AutoClear = {} as AutoClear;
54        randomStatus: RandomStatus = {} as RandomStatus;
55        debugLogger: DebugLogger = {} as DebugLogger;
56        verification: Verification = {} as Verification;
57        welcomer: Welcomer = {} as Welcomer;
58        antijoin: Antijoin = {} as Antijoin;
59        automute: Automute = {} as Automute;
60        channelLock: ChannelLockManager = {} as ChannelLockManager;
61    
62        aliases = {
63            automod: path.resolve(__dirname, '..', 'automod'),
64            services: path.resolve(__dirname, '..', 'services'),
65        };
66    
67        services = {
68            "@services/DebugLogger": "debugLogger",
69            "@automod/Logger": "logger",
70            "@services/SnippetManager": "snippetManager",
71            "@services/AFKEngine": "afkEngine",
72            "@services/Auth": "auth",
73            "@automod/SpamFilter": "spamFilter",
74            "@automod/MessageFilter": "messageFilter",
75            "@automod/AntiRaid": "antiraid",
76            "@services/Starboard": "starboard",
77            "@automod/Cooldown": "cooldown",
78            "@services/StartupManager": "startupManager",
79            "@automod/AutoClear": "autoClear",
80            "@services/RandomStatus": "randomStatus",
81            "@services/Verification": "verification",
82            "@services/Welcomer": "welcomer",
83            "@services/ChannelLockManager": "channelLock",
84            "@automod/Antijoin": "antijoin",
85            "@automod/Automute": "automute",
86        };
87    
88      static client: DiscordClient;      static client: DiscordClient;
89    
90      constructor(options: ClientOptions, rootdir: string = __dirname) {      constructor(options: ClientOptions, rootdir: string = __dirname) {
91          super({          super({
92              ws: {              ws: {
93                  properties: {                  properties: {
94                      $browser: "Discord iOS"                      browser: "Discord iOS"
95                  }                  }
96              },              },
97              ...options              ...options
98          });          });
99    
100            process.on('uncaughtException', (error, origin) => {
101                console.log('Uncaught', error);
102                this.handleCrash(error, origin).then(() => process.exit(-1)).catch(err => {
103                    console.log(err);
104                    process.exit(-1);
105                });
106            });
107            
108            console.log('init');        
109    
110          this.rootdir = rootdir;          this.rootdir = rootdir;
111            
112            DiscordClient.client = this;
113    
114          this.config = new Config(this);          this.config = new Config(this);
115          this.db = new Database(path.resolve(rootdir, 'database.db'), this);          this.db = new Database(path.resolve(rootdir, 'database.db'), this);
116          this.logger = new Logger(this);          this.serviceManager = new ServiceManager(this, this.aliases);
117          this.snippetManager = new SnippetManager(this);          this.serviceManager.load(this.services);
118          this.afkEngine = new AFKEngine(this);  
119          this.auth = new Auth(this);          // this.logger = new Logger(this);
120          this.spamFilter = new SpamFilter(this);          // this.snippetManager = new SnippetManager(this);
121          this.messageFilter = new MessageFilter(this);          // this.afkEngine = new AFKEngine(this);
122          this.antiraid = new AntiRaid(this);          // this.auth = new Auth(this);
123          this.starboard = new Starboard(this);          // this.spamFilter = new SpamFilter(this);
124            // this.messageFilter = new MessageFilter(this);
125            // this.antiraid = new AntiRaid(this);
126            // this.starboard = new Starboard(this);
127            // this.cooldown = new Cooldown(this);
128            // this.startupManager = new StartupManager(this);
129            // this.autoClear = new AutoClear(this);
130            // this.randomStatus = new RandomStatus(this);
131            // this.debugLogger = new DebugLogger(this);
132            // this.verification = new Verification(this);
133            // this.welcomer = new Welcomer(this);
134            // this.antijoin = new Antijoin(this);
135            // this.automute = new Automute(this);
136    
137          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);  
138                    
139          DiscordClient.client = this;          discordModals(this);        
140      }      }
141    
142      get commands(): Collection<string, BaseCommand> {      get commands(): Collection<string, BaseCommand> {
143          return this._commands;          return this._commands;
144      }      }
145    
146        get cliCommands(): Collection<string, BaseCLICommand> {
147            return this._cliCommands;
148        }
149    
150      get events(): Collection<string, BaseEvent> {      get events(): Collection<string, BaseEvent> {
151          return this._events;          return this._events;
152      }      }
# Line 82  export default class DiscordClient exten Line 154  export default class DiscordClient exten
154      setMessage(msg: Message | Interaction) {      setMessage(msg: Message | Interaction) {
155          this.msg = msg;          this.msg = msg;
156      }      }
157    
158        async handleCrash(error: Error, origin: NodeJS.UncaughtExceptionOrigin) {
159            console.log('here');
160            await this.debugLogger.logToHomeServer(`Uncaught ${error.name}: ${error.message}\n${error.stack}`);
161        }
162  }  }

Legend:
Removed from v.65  
changed lines
  Added in v.241

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26