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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 234 - (show annotations)
Mon Jul 29 17:29:08 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 5363 byte(s)
refactor: update service loading strategy (#51)

From now all services will be loaded dynamically.
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 Cooldown from '../automod/Cooldown';
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
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 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 "@automod/Logger": "logger",
67 "@services/SnippetManager": "snippetManager",
68 "@services/AFKEngine": "afkEngine",
69 "@services/Auth": "auth",
70 "@automod/SpamFilter": "spamFilter",
71 "@automod/MessageFilter": "messageFilter",
72 "@automod/AntiRaid": "antiraid",
73 "@services/Starboard": "starboard",
74 "@automod/Cooldown": "cooldown",
75 "@services/StartupManager": "startupManager",
76 "@automod/AutoClear": "autoClear",
77 "@services/RandomStatus": "randomStatus",
78 "@services/DebugLogger": "debugLogger",
79 "@services/Verification": "verification",
80 "@services/Welcomer": "welcomer",
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 console.log('init');
98
99 this.rootdir = rootdir;
100
101 DiscordClient.client = this;
102
103 this.config = new Config(this);
104 this.db = new Database(path.resolve(rootdir, 'database.db'), this);
105 this.serviceManager = new ServiceManager(this, this.aliases);
106 this.serviceManager.load(this.services);
107
108 // this.logger = new Logger(this);
109 // this.snippetManager = new SnippetManager(this);
110 // this.afkEngine = new AFKEngine(this);
111 // this.auth = new Auth(this);
112 // this.spamFilter = new SpamFilter(this);
113 // this.messageFilter = new MessageFilter(this);
114 // this.antiraid = new AntiRaid(this);
115 // this.starboard = new Starboard(this);
116 // this.cooldown = new Cooldown(this);
117 // this.startupManager = new StartupManager(this);
118 // this.autoClear = new AutoClear(this);
119 // this.randomStatus = new RandomStatus(this);
120 // this.debugLogger = new DebugLogger(this);
121 // this.verification = new Verification(this);
122 // this.welcomer = new Welcomer(this);
123 // this.antijoin = new Antijoin(this);
124 // this.automute = new Automute(this);
125
126 this.server = new Server(this);
127
128 discordModals(this);
129 }
130
131 get commands(): Collection<string, BaseCommand> {
132 return this._commands;
133 }
134
135 get cliCommands(): Collection<string, BaseCLICommand> {
136 return this._cliCommands;
137 }
138
139 get events(): Collection<string, BaseEvent> {
140 return this._events;
141 }
142
143 setMessage(msg: Message | Interaction) {
144 this.msg = msg;
145 }
146 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26