botv12/plugins/command.js

31 lines
969 B
JavaScript
Raw Normal View History

2024-11-19 20:05:19 -05:00
import cmds from '../util/commands.js'
import settings from '../settings.js'
2024-10-23 23:35:21 -04:00
import Command from '../util/Command.js'
export default function load (b) {
2024-10-23 23:38:08 -04:00
b.on('chat', (data) => {
2024-10-23 23:35:21 -04:00
const fullCommand = data.message
for (const prefix of settings.prefixes) {
if (fullCommand.startsWith(prefix)) {
const command = fullCommand.slice(prefix.length)
b.runCommand(data.username, data.nickname, data.uuid, command, data.type, data.subtype, prefix)
}
}
})
2024-11-19 20:05:19 -05:00
b.runCommand = function (user, nick, uuid, command, type, subtype, prefix) {
const context = new Command(uuid, user, nick, command, 'minecraft', type, subtype, prefix, b, 0)
2024-11-07 01:22:04 -05:00
b.emit('command', context)
2024-11-19 20:05:19 -05:00
if (cmds[context.cmdName.toLowerCase()]) {
2024-10-23 23:35:21 -04:00
try {
cmds[context.cmdName.toLowerCase()].execute(context)
} catch (e) {
console.log(e)
context.reply({
2024-11-19 20:05:19 -05:00
text: 'An error occured (check console)'
2024-10-23 23:35:21 -04:00
})
}
}
}
}