/[sudobot]/branches/2.x/src/client/Config.ts
ViewVC logotype

Annotation of /branches/2.x/src/client/Config.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (hide annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 1094 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 rakinar2 577 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     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26