Skip to content

Commit 1aff7a9

Browse files
committed
Skip sending falsy command preludes
Fixes #239 by allowing falsy command preludes to override default, and then manually skipping them in the sendToIrc and sendToDiscord methods.
1 parent 47a5a6c commit 1aff7a9

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

lib/bot.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ class Bot {
5151
this.formatURLAttachment = this.format.urlAttachment || '<{$displayUsername}> {$attachmentURL}';
5252
// "{$keyName}" => "variableValue"
5353
// side: "Discord" or "IRC"
54-
this.formatCommandPrelude = this.format.commandPrelude || 'Command sent from {$side} by {$nickname}:';
54+
if ('commandPrelude' in this.format) {
55+
this.formatCommandPrelude = this.format.commandPrelude;
56+
} else {
57+
this.formatCommandPrelude = 'Command sent from {$side} by {$nickname}:';
58+
}
5559

5660
// "{$keyName}" => "variableValue"
5761
// withMentions: text with appropriate mentions reformatted
@@ -282,9 +286,12 @@ class Bot {
282286

283287
if (this.isCommandMessage(text)) {
284288
patternMap.side = 'Discord';
285-
const prelude = Bot.substitutePattern(this.formatCommandPrelude, patternMap);
286289
logger.debug('Sending command message to IRC', ircChannel, text);
287-
this.ircClient.say(ircChannel, prelude);
290+
// if (prelude) this.ircClient.say(ircChannel, prelude);
291+
if (this.formatCommandPrelude) {
292+
const prelude = Bot.substitutePattern(this.formatCommandPrelude, patternMap);
293+
this.ircClient.say(ircChannel, prelude);
294+
}
288295
this.ircClient.say(ircChannel, text);
289296
} else {
290297
if (text !== '') {
@@ -345,9 +352,11 @@ class Bot {
345352

346353
if (this.isCommandMessage(text)) {
347354
patternMap.side = 'IRC';
348-
const prelude = Bot.substitutePattern(this.formatCommandPrelude, patternMap);
349355
logger.debug('Sending command message to Discord', `#${discordChannel.name}`, text);
350-
discordChannel.sendMessage(prelude);
356+
if (this.formatCommandPrelude) {
357+
const prelude = Bot.substitutePattern(this.formatCommandPrelude, patternMap);
358+
discordChannel.sendMessage(prelude);
359+
}
351360
discordChannel.sendMessage(text);
352361
return;
353362
}

test/bot.test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,4 +811,35 @@ describe('Bot', function () {
811811
const expected = `<otherauthor> #discord => #irc, attachment: ${attachmentUrl}`;
812812
ClientStub.prototype.say.should.have.been.calledWith('#irc', expected);
813813
});
814+
815+
it('should not bother with command prelude if falsy', function () {
816+
const format = { commandPrelude: null };
817+
this.bot = new Bot({ ...configMsgFormatDefault, format });
818+
this.bot.connect();
819+
820+
const text = '!testcmd';
821+
const guild = createGuildStub();
822+
const message = {
823+
content: text,
824+
mentions: { users: [] },
825+
channel: {
826+
name: 'discord'
827+
},
828+
author: {
829+
username: 'testauthor',
830+
id: 'not bot id'
831+
},
832+
guild
833+
};
834+
835+
this.bot.sendToIRC(message);
836+
ClientStub.prototype.say.should.have.been.calledOnce;
837+
ClientStub.prototype.say.getCall(0).args.should.deep.equal(['#irc', text]);
838+
839+
const username = 'test';
840+
const msg = '!testcmd';
841+
this.bot.sendToDiscord(username, '#irc', msg);
842+
this.sendMessageStub.should.have.been.calledOnce;
843+
this.sendMessageStub.getCall(0).args.should.deep.equal([msg]);
844+
});
814845
});

0 commit comments

Comments
 (0)