1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | const discord_js_1 = require("discord.js");
|
7 | const commands_1 = __importDefault(require("./commands"));
|
8 | const log = logger.withScope('handleCommand');
|
9 | const hasAdmin = (user, guild) => guild.members.find(member => member.id === user.id).hasPermission('ADMINISTRATOR') || guild.ownerID === user.id;
|
10 | exports.default = ({ content, author, channel }) => {
|
11 | log.info('Command received!');
|
12 | content = content.trim();
|
13 | let command = content.trim().split(' ')[0];
|
14 | const argv = content.replace(command, '').split(' ').map(str => str.trim()).filter(str => str);
|
15 | if (!command)
|
16 | command = 'help';
|
17 | if (!Object.keys(commands_1.default).includes(command))
|
18 | return channel.send(`Command \`${command}\` not found!`);
|
19 | if (command === 'eval' && (channel instanceof discord_js_1.TextChannel) && !hasAdmin(author, channel.guild))
|
20 | return channel.send(`You have no permission!`);
|
21 | if (command === 'config' && argv[1] && argv[1].startsWith('`') && (channel instanceof discord_js_1.TextChannel) && !hasAdmin(author, channel.guild))
|
22 | return channel.send(`You have no permission!`);
|
23 |
|
24 | commands_1.default[command].run(argv, channel);
|
25 | };
|