const DiscordClient = require('./DiscordClient'); const StaticEventEmitter = require('./StaticEventEmitter'); module.exports = class Bot extends StaticEventEmitter { static start(token) { DiscordClient.start(token); this.bindEventListeners(); this.commands = new Map(); this.admin = []; this.prefix = "/"; // never change this this.loadCommands(); } static bindEventListeners() { this.on("chat.receive", msg => { console.log(msg.author.username + ": " + msg.content); let m = { referer: msg.author, }; this.runCommand(msg); }); this.on("chat.send", msg => { DiscordClient.sendChat(msg); }); } static runCommand(msg) { this.commands.forEach(cmd => { let usedCommand = false; cmd.cmd.forEach(c => { if (msg.cmd == c) { usedCommand = true; } }); if (!usedCommand) return; if (msg.rank == 'admin') { cmd.func(msg, true); } else { cmd.func(msg, false); } }); } static fixUsage(str) { return str.split("&PREFIX").join(this.prefix); } static getRank(id) { if (this.admin.indexOf(id) !== -1) { return "admin"; } else { return "none"; } } static async loadCommands() { (require('./Commands'))(this); } }