owobot/plugins/command.js

67 lines
2.1 KiB
JavaScript
Raw Normal View History

2024-08-12 04:33:43 -04:00
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')
2024-08-15 05:43:42 -04:00
const fs = require('fs')
2024-08-12 04:33:43 -04:00
2024-08-15 05:43:42 -04:00
if (!fs.readdirSync('.').includes('userPref')) fs.mkdirSync('userPref')
2024-08-12 04:33:43 -04:00
2024-08-15 05:43:42 -04:00
const loadSettings = function (uuid) {
2024-08-12 04:33:43 -04:00
try {
return require(`../userPref/${uuid}.json`)
} catch (e) {
return {}
}
}
module.exports = {
load: (b) => {
b.prefix = settings.prefix
b.lastCmd = 0
b.runCommand = (name, uuid, text, prefix) => {
if (uuid === '00000000-0000-0000-0000-000000000000') return
if (Date.now() - b.lastCmd <= 1000) return
2024-08-15 05:43:42 -04:00
const userSettings = loadSettings(uuid)
2024-08-12 04:33:43 -04:00
b.lastCmd = Date.now()
const cmd = text.split(' ')
const lang = settings.defaultLang
const verify = hashcheck(cmd)
2024-08-17 06:44:36 -04:00
const nickname = b.findDisplayName(uuid)
2024-08-12 04:33:43 -04:00
if (verify > 0) {
text = cmd.slice(0, cmd.length - 1).join(' ')
}
2024-08-15 05:43:42 -04:00
b.emit('command', name, uuid, text, prefix)
2024-08-12 04:33:43 -04:00
if (cmds[cmd[0].toLowerCase()]) {
const command = cmds[cmd[0].toLowerCase()]
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', [verify + ''])
})
b.tellraw(uuid, {
text: getMessage(lang, 'command.disallowed.perms.cmdLevel', [command.level + ''])
})
return
}
try {
2024-08-17 06:44:36 -04:00
cmds[cmd[0].toLowerCase()].execute(new Command(uuid, name, nickname, text, prefix, b, verify, userSettings))
2024-08-12 04:33:43 -04:00
} catch (e) {
console.log(e)
b.tellraw(uuid, {
text: getMessage(lang, 'command.error'),
color: 'red',
hoverEvent: {
action: 'show_text',
value: {
text: e.stack
}
}
})
}
}
}
}
}