1 |
import DiscordClient from "./Client"; |
2 |
|
3 |
import path from "path"; |
4 |
import fs from "fs"; |
5 |
|
6 |
export type config = { |
7 |
[key: string]: any; |
8 |
}; |
9 |
|
10 |
export type configContainer = { |
11 |
[guildID: string | number]: config; |
12 |
}; |
13 |
|
14 |
export class Config { |
15 |
props: configContainer = {}; |
16 |
client: DiscordClient; |
17 |
|
18 |
constructor(client: DiscordClient) { |
19 |
this.client = client; |
20 |
this.load(); |
21 |
} |
22 |
|
23 |
load() { |
24 |
fs.readFile(path.resolve(__dirname, this.client.rootdir, "config", "config.json"), (err, data) => { |
25 |
if (err) { |
26 |
console.log(err); |
27 |
} |
28 |
|
29 |
this.props = JSON.parse(data.toString()); |
30 |
}); |
31 |
} |
32 |
|
33 |
write() { |
34 |
fs.writeFile(path.resolve(__dirname, this.client.rootdir, "config", "config.json"), JSON.stringify(this.props, undefined, ' '), () => null); |
35 |
} |
36 |
|
37 |
get(key: string) { |
38 |
return typeof this.props[this.client.msg!.guild!.id] === 'object' ? this.props[this.client.msg!.guild!.id][key] : null; |
39 |
} |
40 |
|
41 |
set(key: string, value: any) { |
42 |
this.props[this.client.msg!.guild!.id][key] = value; |
43 |
} |
44 |
} |