/[sudobot]/branches/2.x/src/client/Client.ts
ViewVC logotype

Contents of /branches/2.x/src/client/Client.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (show annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 5933 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 import { Client, ClientOptions, Collection, Interaction, Message } from 'discord.js';
2 import BaseEvent from '../utils/structures/BaseEvent';
3 import BaseCommand from '../utils/structures/BaseCommand';
4 import { Config } from './Config';
5 import Database from './Database';
6 import path from 'path';
7 import Logger from '../automod/Logger';
8 import SnippetManager from '../services/SnippetManager';
9 import AFKEngine from '../services/AFKEngine';
10 import Auth from '../services/Auth';
11 import MessageFilter from '../automod/MessageFilter';
12 import AntiRaid from '../automod/AntiRaid';
13 import Starboard from '../services/Starboard';
14 import Server from '../api/Server';
15 import StartupManager from '../services/StartupManager';
16 import AutoClear from '../automod/AutoClear';
17 import RandomStatus from '../services/RandomStatus';
18 import DebugLogger from '../services/DebugLogger';
19 import BaseCLICommand from '../utils/structures/BaseCLICommand';
20 import discordModals from 'discord-modals';
21 import SpamFilter from '../automod/SpamFilter';
22 import Verification from '../services/Verification';
23 import Welcomer from '../services/Welcomer';
24 import Antijoin from '../automod/Antijoin';
25 import Automute from '../automod/Automute';
26 import ServiceManager from './ServiceManager';
27 import ChannelLockManager from '../services/ChannelLockManager';
28
29 export default class DiscordClient extends Client {
30 private _commands = new Collection<string, BaseCommand>();
31 private _cliCommands = new Collection<string, BaseCLICommand>();
32 private _events = new Collection<string, BaseEvent>();
33
34 rootdir: string;
35 msg: Message | Interaction | null = null;
36
37 config: Config;
38 db: Database;
39 server: Server;
40 serviceManager: ServiceManager;
41
42 logger: Logger = {} as Logger;
43 snippetManager: SnippetManager = {} as SnippetManager;
44 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 startupManager: StartupManager = {} as StartupManager;
51 autoClear: AutoClear = {} as AutoClear;
52 randomStatus: RandomStatus = {} as RandomStatus;
53 debugLogger: DebugLogger = {} as DebugLogger;
54 verification: Verification = {} as Verification;
55 welcomer: Welcomer = {} as Welcomer;
56 antijoin: Antijoin = {} as Antijoin;
57 automute: Automute = {} as Automute;
58 channelLock: ChannelLockManager = {} as ChannelLockManager;
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 "@services/StartupManager": "startupManager",
76 "@automod/AutoClear": "autoClear",
77 "@services/RandomStatus": "randomStatus",
78 "@services/Verification": "verification",
79 "@services/Welcomer": "welcomer",
80 "@services/ChannelLockManager": "channelLock",
81 "@automod/Antijoin": "antijoin",
82 "@automod/Automute": "automute",
83 };
84
85 static client: DiscordClient;
86
87 constructor(options: ClientOptions, rootdir: string = __dirname) {
88 super({
89 ws: {
90 properties: {
91 browser: "Discord iOS"
92 }
93 },
94 ...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;
108
109 DiscordClient.client = this;
110
111 this.config = new Config(this);
112 this.db = new Database(path.resolve(rootdir, 'database.db'), this);
113 this.serviceManager = new ServiceManager(this, this.aliases);
114 this.serviceManager.load(this.services);
115
116 // this.logger = new Logger(this);
117 // this.snippetManager = new SnippetManager(this);
118 // this.afkEngine = new AFKEngine(this);
119 // this.auth = new Auth(this);
120 // 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);
135
136 discordModals(this);
137 }
138
139 get commands(): Collection<string, BaseCommand> {
140 return this._commands;
141 }
142
143 get cliCommands(): Collection<string, BaseCLICommand> {
144 return this._cliCommands;
145 }
146
147 get events(): Collection<string, BaseEvent> {
148 return this._events;
149 }
150
151 setMessage(msg: Message | Interaction) {
152 this.msg = msg;
153 }
154
155 async handleCrash(error: Error, origin: NodeJS.UncaughtExceptionOrigin) {
156 console.log('here');
157 await this.debugLogger.logToHomeServer(`Uncaught ${error.name}: ${error.message}\n${error.stack}`);
158 }
159 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26