UNPKG

1.47 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6const discord_js_1 = require("discord.js");
7const commands_1 = __importDefault(require("./commands"));
8const log = logger.withScope('handleCommand');
9const hasAdmin = (user, guild) => guild.members.find(member => member.id === user.id).hasPermission('ADMINISTRATOR') || guild.ownerID === user.id;
10exports.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 // @ts-ignore Somehow TypeScript still doesn't allow me to get a command this way...
24 commands_1.default[command].run(argv, channel);
25};