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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 362 - (hide 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 rakin 51 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 rakin 360 configPath: string;
18 rakin 51
19     constructor(client: DiscordClient) {
20     this.client = client;
21 rakin 362 console.log(`ENV: ${process.env.SUDO_PREFIX}`);
22 rakin 360 this.configPath = path.resolve(process.env.SUDO_PREFIX ?? this.client.rootdir, "config", "config.json");
23 rakin 51 this.load();
24     }
25    
26     load() {
27 rakin 360 fs.readFile(this.configPath, (err, data) => {
28 rakin 51 if (err) {
29     console.log(err);
30     }
31    
32     this.props = JSON.parse(data.toString());
33     });
34     }
35    
36     write() {
37 rakin 360 fs.writeFile(this.configPath, JSON.stringify(this.props, undefined, ' '), () => null);
38 rakin 51 }
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 rakin 359 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26