UNPKG

1.26 kBJavaScriptView Raw
1"use strict";
2var __importStar = (this && this.__importStar) || function (mod) {
3 if (mod && mod.__esModule) return mod;
4 var result = {};
5 if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
6 result["default"] = mod;
7 return result;
8};
9Object.defineProperty(exports, "__esModule", { value: true });
10const log = logger.withScope('handleCommand');
11const discord_js_1 = require("discord.js");
12const utils_1 = require("./utils");
13const commands = __importStar(require("./commands"));
14exports.default = ({ content, author, channel }) => {
15 log.info('Command received!');
16 content = content.trim();
17 let command = content.split(' ')[0];
18 const argv = content.replace(command, '')
19 .split(' ')
20 .map(str => str.trim())
21 .filter(str => str);
22 if (!command)
23 command = 'help';
24 if (!Object.keys(commands).includes(command))
25 return channel.send(`Command \`${command}\` not found!`);
26 if (command === 'eval') {
27 // can be unsafe?
28 argv.unshift(channel instanceof discord_js_1.TextChannel && !utils_1.hasAdmin(author, channel.guild)
29 ? 'no'
30 : 'yes');
31 }
32 // @ts-ignore
33 commands[command].run(argv, channel);
34};