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

Contents of /trunk/src/client/ServiceManager.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: 777 byte(s)
refactor: update service loading strategy (#51)

From now all services will be loaded dynamically.
1 import Service from "../utils/structures/Service";
2 import DiscordClient from "./Client";
3
4 export default class ServiceManager {
5 constructor(protected client: DiscordClient, protected aliases: { [alias: string]: string }= {}) {
6
7 }
8
9 load(services: { [alias: string]: string }) {
10 for (const service of Object.keys(services)) {
11 let path = service;
12
13 for (const alias in this.aliases) {
14 path = path.replace('@' + alias, this.aliases[alias]);
15 }
16
17 console.log('Loading service: ', service);
18
19 const { default: ServiceClass }: { default: typeof Service } = require(path);
20
21 // @ts-ignore
22 this.client[services[service]] = new ServiceClass(this.client);
23 }
24 }
25 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26