From 09c304b10d7952bd26f60a2e1dbd148c17501ec4 Mon Sep 17 00:00:00 2001 From: Aleksejs Ivanovs Date: Thu, 2 Jul 2020 13:18:22 +0300 Subject: [PATCH 1/2] Added option to replace command prefix with alternative prefix --- lib/bot.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/bot.js b/lib/bot.js index fa3b1474..52aa1614 100644 --- a/lib/bot.js +++ b/lib/bot.js @@ -290,9 +290,23 @@ class Bot { } isCommandMessage(message) { - return this.commandCharacters.some(prefix => message.startsWith(prefix)); + return this.commandCharacters.some(prefix => message.startsWith(prefix)); return this.commandCharacters.some(prefix => + typeof prefix == 'string' + ? message.startsWith(prefix) + : message.startsWith(prefix[0]) + ); } + getCommandPrefix(message) { + if (this.isCommandMessage(message)) { + let command = this.commandCharacters.filter(x => typeof x == 'object' && message.startsWith(x[0])) + if (command.length > 0) { + return command[0] + } + } + return ['', ''] + } + ignoredIrcUser(user) { return this.ignoreUsers.irc.some(i => i.toLowerCase() === user.toLowerCase()); } @@ -360,7 +374,8 @@ class Bot { const prelude = Bot.substitutePattern(this.formatCommandPrelude, patternMap); this.ircClient.say(ircChannel, prelude); } - this.ircClient.say(ircChannel, text); + let command = this.getCommandPrefix(text) + this.ircClient.say(ircChannel, text.replace(command[0], command[1])); } else { if (text !== '') { // Convert formatting From 412331b38a5ea87fce741e6b8494dba73b2926ed Mon Sep 17 00:00:00 2001 From: Aleksejs Ivanovs Date: Thu, 2 Jul 2020 13:34:28 +0300 Subject: [PATCH 2/2] Fixed error --- lib/bot.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/bot.js b/lib/bot.js index 52aa1614..efea6f64 100644 --- a/lib/bot.js +++ b/lib/bot.js @@ -290,7 +290,7 @@ class Bot { } isCommandMessage(message) { - return this.commandCharacters.some(prefix => message.startsWith(prefix)); return this.commandCharacters.some(prefix => + return this.commandCharacters.some(prefix => typeof prefix == 'string' ? message.startsWith(prefix) : message.startsWith(prefix[0]) @@ -305,7 +305,7 @@ class Bot { } } return ['', ''] - } + } ignoredIrcUser(user) { return this.ignoreUsers.irc.some(i => i.toLowerCase() === user.toLowerCase());