Skip to content

Commit

Permalink
Merge pull request #260 from Throne3d/fix/239-skip-falsy-cmdprelude
Browse files Browse the repository at this point in the history
Skip sending falsy command preludes
  • Loading branch information
ekmartin authored Jul 3, 2017
2 parents 47a5a6c + 1aff7a9 commit 85a55e6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 !== '') {
Expand Down Expand Up @@ -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;
}
Expand Down
31 changes: 31 additions & 0 deletions test/bot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -811,4 +811,35 @@ describe('Bot', function () {
const expected = `<otherauthor> #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]);
});
});

0 comments on commit 85a55e6

Please sign in to comment.