2024-07-28 02:37:31 -04:00
|
|
|
const Command = require('../util/Command.js')
|
|
|
|
const settings = require('../settings.json')
|
2024-08-12 05:13:32 -04:00
|
|
|
const { getMessage } = require('../util/lang.js')
|
|
|
|
const cmds = require('../util/commands.js')
|
2024-08-22 07:34:39 -04:00
|
|
|
const fs = require('fs')
|
2024-08-12 05:13:32 -04:00
|
|
|
|
2024-08-25 21:53:03 -04:00
|
|
|
if (!fs.readdirSync('.').includes('userPref') && !settings.userSettingsDisabled) fs.mkdirSync('userPref')
|
2024-08-12 05:13:32 -04:00
|
|
|
|
2024-08-22 07:34:39 -04:00
|
|
|
const loadSettings = function (uuid) {
|
2024-08-12 05:13:32 -04:00
|
|
|
try {
|
2024-08-25 22:29:39 -04:00
|
|
|
if (settings.userSettingsDisabled) {
|
2024-08-25 21:53:03 -04:00
|
|
|
return {}
|
|
|
|
} else {
|
|
|
|
return require(`../userPref/${uuid}.json`)
|
|
|
|
}
|
2024-08-12 05:13:32 -04:00
|
|
|
} catch (e) {
|
|
|
|
return {}
|
|
|
|
}
|
2024-07-27 02:39:18 -04:00
|
|
|
}
|
2024-07-28 02:37:31 -04:00
|
|
|
module.exports = {
|
2024-08-12 05:13:32 -04:00
|
|
|
load: (b) => {
|
2024-07-28 02:37:31 -04:00
|
|
|
b.prefix = settings.prefix
|
|
|
|
b.lastCmd = 0
|
2024-08-25 22:29:39 -04:00
|
|
|
b.on('chat', (data) => {
|
2024-08-25 22:13:46 -04:00
|
|
|
const fullCommand = data.message
|
|
|
|
for (const prefix of b.prefix) {
|
|
|
|
if (fullCommand.startsWith(prefix)) {
|
|
|
|
const command = fullCommand.slice(prefix.length)
|
|
|
|
b.runCommand(data.username, data.nickname, data.uuid, command, data.type, prefix)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2024-08-22 07:34:39 -04:00
|
|
|
b.runCommand = (name, nickname, uuid, text, msgType, prefix) => {
|
2024-07-28 02:37:31 -04:00
|
|
|
if (uuid === '00000000-0000-0000-0000-000000000000') return
|
|
|
|
if (Date.now() - b.lastCmd <= 1000) return
|
2024-08-22 07:34:39 -04:00
|
|
|
const userSettings = loadSettings(uuid)
|
2024-07-28 02:37:31 -04:00
|
|
|
b.lastCmd = Date.now()
|
|
|
|
const lang = settings.defaultLang
|
2024-09-11 01:35:15 -04:00
|
|
|
|
2024-09-11 02:02:29 -04:00
|
|
|
const commandClass = new Command(uuid, name, nickname, text, msgType, prefix, b, userSettings);
|
2024-09-11 01:35:15 -04:00
|
|
|
b.emit("command",commandClass)
|
|
|
|
if(commandClass.cancel === true) return
|
|
|
|
|
2024-09-11 02:02:29 -04:00
|
|
|
if (cmds[commandClass.cmdName.toLowerCase()]) {
|
2024-07-28 02:37:31 -04:00
|
|
|
try {
|
2024-09-11 02:02:29 -04:00
|
|
|
cmds[commandClass.cmdName.toLowerCase()].execute(commandClass)
|
2024-07-28 02:37:31 -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
|
|
|
|
}
|
2024-07-27 02:39:18 -04:00
|
|
|
}
|
2024-07-28 02:37:31 -04:00
|
|
|
})
|
2024-07-27 02:39:18 -04:00
|
|
|
}
|
2024-07-28 02:37:31 -04:00
|
|
|
}
|
|
|
|
}
|
2024-08-12 05:13:32 -04:00
|
|
|
}
|
2024-07-27 02:39:18 -04:00
|
|
|
}
|