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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 362 - (show annotations)
Mon Jul 29 17:29:47 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 1180 byte(s)
feat: make the system prefix changable
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 configPath: string;
18
19 constructor(client: DiscordClient) {
20 this.client = client;
21 console.log(`ENV: ${process.env.SUDO_PREFIX}`);
22 this.configPath = path.resolve(process.env.SUDO_PREFIX ?? this.client.rootdir, "config", "config.json");
23 this.load();
24 }
25
26 load() {
27 fs.readFile(this.configPath, (err, data) => {
28 if (err) {
29 console.log(err);
30 }
31
32 this.props = JSON.parse(data.toString());
33 });
34 }
35
36 write() {
37 fs.writeFile(this.configPath, JSON.stringify(this.props, undefined, ' '), () => null);
38 }
39
40 get(key: string) {
41 return typeof this.props[this.client.msg!.guild!.id] === 'object' ? this.props[this.client.msg!.guild!.id][key] : null;
42 }
43
44 set(key: string, value: any) {
45 this.props[this.client.msg!.guild!.id][key] = value;
46 }
47 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26