Seperate permissions from command plugin; add command rewriter
This commit is contained in:
parent
316fcd1f86
commit
cde624bbcf
3 changed files with 42 additions and 27 deletions
|
@ -1,5 +1,4 @@
|
|||
const Command = require('../util/Command.js')
|
||||
const hashcheck = require('../util/hashcheck.js')
|
||||
const settings = require('../settings.json')
|
||||
const { getMessage } = require('../util/lang.js')
|
||||
const cmds = require('../util/commands.js')
|
||||
|
@ -36,36 +35,15 @@ module.exports = {
|
|||
if (Date.now() - b.lastCmd <= 1000) return
|
||||
const userSettings = loadSettings(uuid)
|
||||
b.lastCmd = Date.now()
|
||||
const cmd = text.split(' ')
|
||||
const lang = settings.defaultLang
|
||||
const verify = hashcheck(cmd, uuid)
|
||||
if (verify > 0) {
|
||||
text = cmd.slice(0, cmd.length - 1).join(' ')
|
||||
}
|
||||
|
||||
const commandClass = new Command(uuid, name, nickname, text, msgType, prefix, b, verify, userSettings);
|
||||
const commandClass = new Command(uuid, name, nickname, text, msgType, prefix, b, userSettings);
|
||||
b.emit("command",commandClass)
|
||||
if(commandClass.cancel === true) return
|
||||
|
||||
if (cmds[cmd[0].toLowerCase()]) {
|
||||
const command = cmds[cmd[0].toLowerCase()]
|
||||
const permsN = getMessage(lang, 'command.help.permsNormal')
|
||||
const permsT = getMessage(lang, 'command.help.permsTrusted')
|
||||
const permsO = getMessage(lang, 'command.help.permsOwner')
|
||||
if (command.level !== undefined && command.level > verify) {
|
||||
b.tellraw(uuid, {
|
||||
text: getMessage(lang, 'command.disallowed.perms')
|
||||
})
|
||||
b.tellraw(uuid, {
|
||||
text: getMessage(lang, 'command.disallowed.perms.yourLevel', [[permsN, permsT, permsO][verify]])
|
||||
})
|
||||
b.tellraw(uuid, {
|
||||
text: getMessage(lang, 'command.disallowed.perms.cmdLevel', [[permsN, permsT, permsO][command.level]])
|
||||
})
|
||||
return
|
||||
}
|
||||
if (cmds[commandClass.cmdName.toLowerCase()]) {
|
||||
try {
|
||||
if(commandClass.cancel === false) cmds[cmd[0].toLowerCase()].execute(commandClass)
|
||||
cmds[commandClass.cmdName.toLowerCase()].execute(commandClass)
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
b.tellraw(uuid, {
|
||||
|
|
31
plugins/perms.js
Executable file
31
plugins/perms.js
Executable file
|
@ -0,0 +1,31 @@
|
|||
const cmds = require('../util/commands.js')
|
||||
const { getMessage } = require('../util/lang.js')
|
||||
const hashcheck = require('../util/hashcheck.js')
|
||||
|
||||
module.exports = {
|
||||
load: (b) => {
|
||||
b.on("command", c => {
|
||||
const cmd = c.command.split(' ')
|
||||
const command = cmds[c.cmdName.toLowerCase()]
|
||||
const verify = hashcheck(cmd, c.uuid)
|
||||
const permsN = getMessage(c.lang, 'command.help.permsNormal')
|
||||
const permsT = getMessage(c.lang, 'command.help.permsTrusted')
|
||||
const permsO = getMessage(c.lang, 'command.help.permsOwner')
|
||||
if (command.level !== undefined && command.level > verify) {
|
||||
b.tellraw(c.uuid, {
|
||||
text: getMessage(c.lang, 'command.disallowed.perms')
|
||||
})
|
||||
b.tellraw(c.uuid, {
|
||||
text: getMessage(c.lang, 'command.disallowed.perms.yourLevel', [[permsN, permsT, permsO][verify]])
|
||||
})
|
||||
b.tellraw(c.uuid, {
|
||||
text: getMessage(c.lang, 'command.disallowed.perms.cmdLevel', [[permsN, permsT, permsO][command.level]])
|
||||
})
|
||||
c.cancel = true
|
||||
} else if (verify > 0) {
|
||||
c.rewriteCommand(cmd.slice(0, cmd.length - 1).join(' '))
|
||||
c.verify = verify;
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
const settings = require('../settings.json')
|
||||
class Command {
|
||||
constructor (uuid, user, nick, cmd, msgType, prefix, bot, verify, prefs) {
|
||||
constructor (uuid, user, nick, cmd, msgType, prefix, bot, prefs) {
|
||||
this.send = (text, uuid) => { bot.tellraw(uuid || '@a', text) }
|
||||
this.reply = text => bot.tellraw(uuid, text)
|
||||
this.uuid = uuid
|
||||
|
@ -13,7 +13,7 @@ class Command {
|
|||
this.type = 'minecraft'
|
||||
this.args = cmd.split(' ').slice(1)
|
||||
this.cmdName = cmd.split(' ')[0]
|
||||
this.verify = verify
|
||||
this.verify = 0
|
||||
this.host = bot.host.host
|
||||
this.port = bot.host.port
|
||||
this.serverName = bot.host.options.name
|
||||
|
@ -37,6 +37,12 @@ class Command {
|
|||
_colors.secondary = settings.colors.secondary
|
||||
}
|
||||
this.colors = _colors
|
||||
|
||||
this.rewriteCommand = newCmd => {
|
||||
this.command = newCmd
|
||||
this.args = newCmd.split(' ').slice(1)
|
||||
this.cmdName = newCmd.split(' ')[0]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue