feat(events): command user usage level checking
This commit is contained in:
parent
b12269f132
commit
a62c0e3b78
2 changed files with 25 additions and 1 deletions
15
src/assertions/userLevel.ts
Normal file
15
src/assertions/userLevel.ts
Normal 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;
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ import { Event } from './Event';
|
||||||
import { Message } from 'discord.js';
|
import { Message } from 'discord.js';
|
||||||
import { prefix } from '../config/bot';
|
import { prefix } from '../config/bot';
|
||||||
import { PluginClient } from '../PluginClient';
|
import { PluginClient } from '../PluginClient';
|
||||||
|
import { calcUserLevel } from '../assertions/userLevel';
|
||||||
|
|
||||||
function parseContent(content: string) {
|
function parseContent(content: string) {
|
||||||
const split = content.split(' ');
|
const split = content.split(' ');
|
||||||
|
@ -21,6 +22,14 @@ export const event = new Event(
|
||||||
async (lifeguard, msg: Message) => {
|
async (lifeguard, msg: Message) => {
|
||||||
const [cmdName, ...args] = parseContent(msg.content);
|
const [cmdName, ...args] = parseContent(msg.content);
|
||||||
const cmd = getCommandFromPlugin(lifeguard, cmdName);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue