2020-01-13 22:38:12 +00:00
|
|
|
import { Event } from './Event';
|
|
|
|
import { Message } from 'discord.js';
|
|
|
|
import { prefix } from '../config/bot';
|
|
|
|
import { PluginClient } from '../PluginClient';
|
2020-01-14 05:15:34 +00:00
|
|
|
import { calcUserLevel } from '../assertions/userLevel';
|
2020-01-13 22:38:12 +00:00
|
|
|
|
|
|
|
function parseContent(content: string) {
|
|
|
|
const split = content.split(' ');
|
|
|
|
const cmdName = split[0].slice(prefix.length);
|
|
|
|
split.shift();
|
|
|
|
return [cmdName, ...split];
|
|
|
|
}
|
|
|
|
|
|
|
|
function getCommandFromPlugin(lifeguard: PluginClient, cmdName: string) {
|
|
|
|
const plugin = lifeguard.plugins.find(p => p.has(cmdName));
|
|
|
|
const command = plugin?.get(cmdName);
|
|
|
|
return command;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const event = new Event(
|
|
|
|
'lifeguardCommandUsed',
|
|
|
|
async (lifeguard, msg: Message) => {
|
|
|
|
const [cmdName, ...args] = parseContent(msg.content);
|
|
|
|
const cmd = getCommandFromPlugin(lifeguard, cmdName);
|
2020-01-14 05:15:34 +00:00
|
|
|
|
|
|
|
if (cmd) {
|
|
|
|
if (msg.member && msg.guild) {
|
|
|
|
const userLevel = calcUserLevel(msg.member, msg.guild);
|
|
|
|
if (userLevel >= cmd.options.level) {
|
|
|
|
cmd.func(lifeguard, msg, args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-13 22:38:12 +00:00
|
|
|
}
|
|
|
|
);
|