1 |
rakinar2 |
577 |
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 |
|
|
} |