feat(events): command user usage level checking

This commit is contained in:
Rauf 2020-01-14 00:15:34 -05:00
parent b12269f132
commit a62c0e3b78
2 changed files with 25 additions and 1 deletions

View File

@ -0,0 +1,15 @@
import { GuildMember, Guild } from 'discord.js';
import { developers } from '../config/bot';
export function calcUserLevel(user: GuildMember, guild: Guild) {
if (developers.includes(user.id)) {
return 5;
}
if (user.id === guild.ownerID) {
return 4;
}
if (user.permissions.has('ADMINISTRATOR', true)) {
return 3;
}
return 0;
}

View File

@ -2,6 +2,7 @@ import { Event } from './Event';
import { Message } from 'discord.js';
import { prefix } from '../config/bot';
import { PluginClient } from '../PluginClient';
import { calcUserLevel } from '../assertions/userLevel';
function parseContent(content: string) {
const split = content.split(' ');
@ -21,6 +22,14 @@ export const event = new Event(
async (lifeguard, msg: Message) => {
const [cmdName, ...args] = parseContent(msg.content);
const cmd = getCommandFromPlugin(lifeguard, cmdName);
cmd?.func(lifeguard, msg, args);
if (cmd) {
if (msg.member && msg.guild) {
const userLevel = calcUserLevel(msg.member, msg.guild);
if (userLevel >= cmd.options.level) {
cmd.func(lifeguard, msg, args);
}
}
}
}
);