Seperate permissions from command plugin; add command rewriter

This commit is contained in:
7cc5c4f330d47060 2024-09-11 02:02:29 -04:00
parent 316fcd1f86
commit cde624bbcf
Signed by: 7cc5c4f330d47060
SSH key fingerprint: SHA256:e+4tcZut1nBpe10PqjaO+Rvie0Q7W4qIvFzcUw+7riA
3 changed files with 42 additions and 27 deletions

View file

@ -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
View 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;
}
})
}
}

View file

@ -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]
}
}
}