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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26