summaryrefslogtreecommitdiff
path: root/src/Troffman.js
blob: 2b8860c64db561eae10ec35e344f29964518596f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const Eris = require('eris');
const toml = require('toml');
const fs = require('fs');

const RegexFramework = require('./RegexFramework');
const Events = require('./Events');
const CommandLoader = require('./CommandLoader');
const TroffmanDatabase = require('./TroffmanDatabase');

module.exports = class Troffman extends Eris {
    constructor(configPath, options) {
        if (!fs.existsSync(configPath)) {
            fs.copyFileSync("./config.def.toml", configPath);
            process.exit(0);
        }
        let c = toml.parse(fs.readFileSync(configPath));
        super(c.token, options);
        this.config = c;
        if (!this.config.sudoers) {
            this.config.sudoers = [''];
        }
        else if (!Array.isArray(this.config.sudoers)) {
            this.config.sudoers = [''];
        }
        else if (this.config.sudoers.length <= 0) {
            this.config.sudoers = [''];
        }
        this._ds = Array.from(this.config.sudoers);
        this.db = new TroffmanDatabase(c.database);
        this.handler = new RegexFramework();
        Events(this);
        CommandLoader(this);
        this.db.sync();
    }
};