From 22490f7ec1d79f567a856c40cfd9ab09dbff88f6 Mon Sep 17 00:00:00 2001 From: jay Date: Tue, 23 Mar 2021 23:10:58 +0500 Subject: [PATCH] fix(command): :bug: fix bot address regex returning undefined Waits till spawn to make sure `bot.username` is definitely initialized --- lib/index.js | 2 +- lib/plugins/command.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/index.js b/lib/index.js index b95ecae..1f0f261 100644 --- a/lib/index.js +++ b/lib/index.js @@ -88,7 +88,6 @@ fs.watch('./lib/plugins', reloadplugin) cfg.bot = bot // TODO better name, or switch to array cfg.botAddressPrefix = '!' -cfg.botAddressRegex = new RegExp(`^${bot.username} (${cfg.botAddressPrefix}.+)`) cfg.quiet = true @@ -110,6 +109,7 @@ bot.once("spawn", () => { } cfg.plugins = plugins + cfg.botAddressRegex = new RegExp(`^${bot.username} (${cfg.botAddressPrefix}.+)`) for (const plugin of Object.values(plugins)) { try { diff --git a/lib/plugins/command.js b/lib/plugins/command.js index bd4b3a0..2e275d1 100644 --- a/lib/plugins/command.js +++ b/lib/plugins/command.js @@ -30,11 +30,10 @@ const events = { whisper: function command_whisper(username, message) { if ([bot.username, "me"].includes(username)) return if (/^gossip/.test(message)) return - // if (/^!/.test(message) && username === cfg.admin){ if (username === cfg.admin) { message = message.replace("\\", "@") console.info("whispered command", message) - if (/^!/.test(message)) { + if (message.startsWith(cfg.botAddressPrefix)) { command(username, message) } else { bot.chat(message)