UNPKG

msg.ts

Version:

MSG is the framework for make discord bot easily

55 lines 2.38 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const discord_js_1 = __importDefault(require("discord.js")); const chalk_1 = __importDefault(require("chalk")); const MsgToContext_1 = __importDefault(require("../utils/MsgToContext")); const MiddlewareManager_1 = __importDefault(require("./MiddlewareManager")); const MiddlewareChainRunner_1 = __importDefault(require("./MiddlewareChainRunner")); const isBot_1 = __importDefault(require("../commands/isBot")); const prefixCheck_1 = __importDefault(require("../commands/prefixCheck")); const parseArgs_1 = __importDefault(require("../commands/parseArgs")); const Command_1 = require("./Command"); class Bot extends discord_js_1.default.Client { constructor(options, config = {}) { super(options); this.middlewareManager = new MiddlewareManager_1.default([isBot_1.default, prefixCheck_1.default, parseArgs_1.default]); this.owner = null; this.config = config; } setConfig(config) { this.config = config; return this; } addCommand(...cmds) { this.middlewareManager.addCommand(...cmds); return this; } indent(condString, subCommands) { this.middlewareManager.addCommand(Command_1.indent(condString, subCommands)); return this; } login(token) { this.on('ready', async () => { this.owner = (await this.fetchApplication()).owner; this.emit('readyState', this); }) .on('message', async (msg) => { if (process.argv.includes('--log')) { console.log(`\n${chalk_1.default.hex('#E38833')('New message received!')}: ${msg.content}`); } const context = MsgToContext_1.default(msg); context.ex.bot = this; const finalContext = await new MiddlewareChainRunner_1.default(this.middlewareManager.array()).run(context); this.emit('final', finalContext); }) .on('final', async (context) => { console.log('finished!'); }); return super.login(token); } } exports.default = Bot; //# sourceMappingURL=../../src/dist/class/Bot.js.map