diff --git a/lib/index.js b/lib/index.js index 06d1411..b95ecae 100644 --- a/lib/index.js +++ b/lib/index.js @@ -86,7 +86,9 @@ reloadplugin = (event, filename, pluginpath) => { fs.watch('./lib/plugins', reloadplugin) cfg.bot = bot -cfg.botAddress = new RegExp(`^${bot.username} (!.+)`) +// TODO better name, or switch to array +cfg.botAddressPrefix = '!' +cfg.botAddressRegex = new RegExp(`^${bot.username} (${cfg.botAddressPrefix}.+)`) cfg.quiet = true diff --git a/lib/plugins/command.js b/lib/plugins/command.js index b492e5e..47cd4a1 100644 --- a/lib/plugins/command.js +++ b/lib/plugins/command.js @@ -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+/)