diff --git a/lib/bot.js b/lib/bot.js index 2a08f6d..340c601 100644 --- a/lib/bot.js +++ b/lib/bot.js @@ -51,7 +51,11 @@ class Bot { this.formatURLAttachment = this.format.urlAttachment || '<{$displayUsername}> {$attachmentURL}'; // "{$keyName}" => "variableValue" // side: "Discord" or "IRC" - this.formatCommandPrelude = this.format.commandPrelude || 'Command sent from {$side} by {$nickname}:'; + if ('commandPrelude' in this.format) { + this.formatCommandPrelude = this.format.commandPrelude; + } else { + this.formatCommandPrelude = 'Command sent from {$side} by {$nickname}:'; + } // "{$keyName}" => "variableValue" // withMentions: text with appropriate mentions reformatted @@ -282,9 +286,12 @@ class Bot { if (this.isCommandMessage(text)) { patternMap.side = 'Discord'; - const prelude = Bot.substitutePattern(this.formatCommandPrelude, patternMap); logger.debug('Sending command message to IRC', ircChannel, text); - this.ircClient.say(ircChannel, prelude); + // if (prelude) this.ircClient.say(ircChannel, prelude); + if (this.formatCommandPrelude) { + const prelude = Bot.substitutePattern(this.formatCommandPrelude, patternMap); + this.ircClient.say(ircChannel, prelude); + } this.ircClient.say(ircChannel, text); } else { if (text !== '') { @@ -345,9 +352,11 @@ class Bot { if (this.isCommandMessage(text)) { patternMap.side = 'IRC'; - const prelude = Bot.substitutePattern(this.formatCommandPrelude, patternMap); logger.debug('Sending command message to Discord', `#${discordChannel.name}`, text); - discordChannel.sendMessage(prelude); + if (this.formatCommandPrelude) { + const prelude = Bot.substitutePattern(this.formatCommandPrelude, patternMap); + discordChannel.sendMessage(prelude); + } discordChannel.sendMessage(text); return; } diff --git a/test/bot.test.js b/test/bot.test.js index e05b262..1415e49 100644 --- a/test/bot.test.js +++ b/test/bot.test.js @@ -811,4 +811,35 @@ describe('Bot', function () { const expected = ` #discord => #irc, attachment: ${attachmentUrl}`; ClientStub.prototype.say.should.have.been.calledWith('#irc', expected); }); + + it('should not bother with command prelude if falsy', function () { + const format = { commandPrelude: null }; + this.bot = new Bot({ ...configMsgFormatDefault, format }); + this.bot.connect(); + + const text = '!testcmd'; + const guild = createGuildStub(); + const message = { + content: text, + mentions: { users: [] }, + channel: { + name: 'discord' + }, + author: { + username: 'testauthor', + id: 'not bot id' + }, + guild + }; + + this.bot.sendToIRC(message); + ClientStub.prototype.say.should.have.been.calledOnce; + ClientStub.prototype.say.getCall(0).args.should.deep.equal(['#irc', text]); + + const username = 'test'; + const msg = '!testcmd'; + this.bot.sendToDiscord(username, '#irc', msg); + this.sendMessageStub.should.have.been.calledOnce; + this.sendMessageStub.getCall(0).args.should.deep.equal([msg]); + }); });