mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2025-03-25 11:30:25 -04:00
improve command handler
This commit is contained in:
parent
1dfaff8cb2
commit
a8e21f8b7b
1 changed files with 7 additions and 13 deletions
|
@ -1,4 +1,3 @@
|
|||
/* eslint-disable no-var */
|
||||
/* eslint-disable max-len */
|
||||
const loadFiles = require('../util/load_files');
|
||||
const path = require('path');
|
||||
|
@ -12,28 +11,23 @@ function inject(bot, dcclient, config) {
|
|||
reload();
|
||||
let raw;
|
||||
let command;
|
||||
if (typeof message.content!=='undefined') raw = message.content.substring(prefix.length);
|
||||
if (typeof message.content==='undefined') raw = message.substring(prefix.length);
|
||||
message.content ? raw = message.content.substring(prefix.length) : raw = message.substring(prefix.length);
|
||||
const [commandName, ...args] = raw.split(' ');
|
||||
command = bot.command_handler.commands.find((command) => command.name === commandName.toLowerCase());
|
||||
try {
|
||||
var alias = bot.command_handler.commands.find((command) => command.alias.includes(commandName.toLowerCase()));
|
||||
if (alias !== undefined) {
|
||||
command = bot.command_handler.commands.find((command) => command.alias.includes(commandName.toLowerCase()));
|
||||
}
|
||||
const alias = bot.command_handler.commands.find((command) => command.alias.includes(commandName.toLowerCase()));
|
||||
if (alias) command = bot.command_handler.commands.find((command) => command.alias.includes(commandName.toLowerCase()));
|
||||
if (prefix === '*' && message.endsWith('*') && message !== '*') return;
|
||||
if (command === undefined) {
|
||||
throw new Error(`Unknown command: "${commandName}"`);
|
||||
}
|
||||
if (!command) throw new Error(`Unknown command: "${commandName}"`);
|
||||
|
||||
if (prefix==='!') {
|
||||
if (typeof command.discordExecute==='undefined') throw new Error('This command is not yet supported on discord!');
|
||||
if (prefix === config.discord.prefix) {
|
||||
if (typeof command.discordExecute === 'undefined') throw new Error('This command is not yet supported on discord!');
|
||||
command.discordExecute(bot, username, usernameraw, sender, prefix, args, channeldc, message, config);
|
||||
} else {
|
||||
command.execute(bot, username, usernameraw, sender, prefix, args, config);
|
||||
}
|
||||
} catch (e) {
|
||||
if (prefix==='!') {
|
||||
if (prefix === config.discord.prefix) {
|
||||
const Embed = new MessageEmbed()
|
||||
.setColor('#FF0000')
|
||||
.setTitle('Error')
|
||||
|
|
Loading…
Add table
Reference in a new issue