Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ First you need to create a Discord bot user, which you can do by following the i
"ircText": "<{$displayUsername}> {$text}", // When sending a message to IRC
"urlAttachment": "<{$displayUsername}> {$attachmentURL}", // When sending a Discord attachment to IRC
"discord": "**<{$author}>** {$withMentions}" // When sending a message to Discord
"discordMe": "_**{$author}** {$withMentions}_" // When sending a /me action message to Discord
// Other patterns that can be used:
// {$discordChannel} (e.g. #general)
// {$ircChannel} (e.g. #irc)
Expand Down
10 changes: 6 additions & 4 deletions lib/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Bot {
// "{$keyName}" => "variableValue"
// withMentions: text with appropriate mentions reformatted
this.formatDiscord = this.format.discord || '**<{$author}>** {$withMentions}';
this.formatDiscordMe = this.format.discordMe || '**<{$author}>** _{$withMentions}_';

// Keep track of { channel => [list, of, usernames] } for ircStatusNotices
this.channelUsers = {};
Expand Down Expand Up @@ -196,7 +197,7 @@ class Bot {
});

this.ircClient.on('action', (author, to, text) => {
this.sendToDiscord(author, to, `_${text}_`);
this.sendToDiscord(author, to, text, true);
});

this.ircClient.on('invite', (channel, from) => {
Expand Down Expand Up @@ -335,7 +336,7 @@ class Bot {
return null;
}

sendToDiscord(author, channel, text) {
sendToDiscord(author, channel, text, isAction = false) {
const discordChannel = this.findDiscordChannel(channel);
if (!discordChannel) return;

Expand Down Expand Up @@ -392,9 +393,10 @@ class Bot {

patternMap.withMentions = withMentions;

// Add bold formatting:
// Add formatting:
// Use custom formatting from config / default formatting with bold author
const withAuthor = Bot.substitutePattern(this.formatDiscord, patternMap);
const format = isAction ? this.formatDiscordMe : this.formatDiscord;
const withAuthor = Bot.substitutePattern(format, patternMap);
logger.debug('Sending message to Discord', withAuthor, channel, '->', `#${discordChannel.name}`);
discordChannel.send(withAuthor);
}
Expand Down
4 changes: 2 additions & 2 deletions test/bot-events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ describe('Bot Events', function () {
const channel = '#channel';
const author = 'user';
const text = 'hi';
const formattedText = '_hi_';
const formattedText = 'hi';
const message = {};
this.bot.ircClient.emit('action', author, channel, text, message);
this.bot.sendToDiscord.should.have.been.calledWithExactly(author, channel, formattedText);
this.bot.sendToDiscord.should.have.been.calledWithExactly(author, channel, formattedText, true);
});

it('should keep track of users through names event when irc status notices enabled', function () {
Expand Down