|
|
|
@ -62,6 +62,9 @@ const events = { |
|
|
|
|
const events_registered = [] |
|
|
|
|
|
|
|
|
|
function command(username, message) { |
|
|
|
|
// TODO better name, maybe an array?
|
|
|
|
|
cfg.botAddressPrefix = cfg.botAddressPrefix || "!" |
|
|
|
|
|
|
|
|
|
function fuzzyRespond(responses, probability = 1, timeout = 1) { |
|
|
|
|
if (Math.random() < probability) { |
|
|
|
|
const response = responses[Math.floor(Math.random() * responses.length)] |
|
|
|
@ -76,7 +79,7 @@ function command(username, message) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (username === bot.username && !message.startsWith("!")) return |
|
|
|
|
if (username === bot.username && !message.startsWith(cfg.botAddressPrefix)) return |
|
|
|
|
|
|
|
|
|
const player = bot.players[username] ? bot.players[username].entity : null |
|
|
|
|
|
|
|
|
@ -88,11 +91,12 @@ function command(username, message) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (message.startsWith("!") || cfg.botAddress.test(message)) { |
|
|
|
|
message = cfg.botAddress.test(message) ? cfg.botAddress.exec(message)[1] : message |
|
|
|
|
|
|
|
|
|
if (message.startsWith(cfg.botAddressPrefix) || cfg.botAddressRegex.test(message)) { |
|
|
|
|
message = cfg.botAddressRegex.test(message) ? cfg.botAddressRegex.exec(message)[1] : message |
|
|
|
|
console.log(message) |
|
|
|
|
message = message.slice(1) // remove `!`
|
|
|
|
|
// remove `!`
|
|
|
|
|
message = message.startsWith(cfg.botAddressPrefix) ? message.slice(cfg.botAddressPrefix.length) : message |
|
|
|
|
|
|
|
|
|
// TODO command dispatchEvent, for aliases
|
|
|
|
|
function subcommand(message) { |
|
|
|
|
const message_parts = message.split(/\s+/) |
|
|
|
|