Skip to content
Merged
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
4 changes: 3 additions & 1 deletion lib/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,9 @@ class Bot {
if (user) return user;

return match;
}).replace(/@([^\s]+)/g, (match, reference) => {
}).replace(/^([^@\s:,]+)[:,]|@([^\s]+)/g, (match, startRef, atRef) => {
const reference = startRef || atRef;

// this preliminary stuff is ultimately unnecessary
// but might save time over later more complicated calculations
// @nickname => mention, case insensitively
Expand Down
46 changes: 44 additions & 2 deletions test/bot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ describe('Bot', function () {
this.bot.parseText(message).should.equal(':in_love:');
});

it('should convert user mentions from IRC', function () {
it('should convert user at-mentions from IRC', function () {
const testUser = this.addUser({ username: 'testuser', id: '123' });

const username = 'ircuser';
Expand All @@ -443,7 +443,40 @@ describe('Bot', function () {
this.sendStub.should.have.been.calledWith(expected);
});

it('should not convert user mentions from IRC if such user does not exist', function () {
it('should convert user colon-initial mentions from IRC', function () {
const testUser = this.addUser({ username: 'testuser', id: '123' });

const username = 'ircuser';
const text = 'testuser: hello!';
const expected = `**<${username}>** <@${testUser.id}> hello!`;

this.bot.sendToDiscord(username, '#irc', text);
this.sendStub.should.have.been.calledWith(expected);
});

it('should convert user comma-initial mentions from IRC', function () {
const testUser = this.addUser({ username: 'testuser', id: '123' });

const username = 'ircuser';
const text = 'testuser, hello!';
const expected = `**<${username}>** <@${testUser.id}> hello!`;

this.bot.sendToDiscord(username, '#irc', text);
this.sendStub.should.have.been.calledWith(expected);
});

it('should not convert user initial mentions from IRC mid-message', function () {
this.addUser({ username: 'testuser', id: '123' });

const username = 'ircuser';
const text = 'Hi there testuser, how goes?';
const expected = `**<${username}>** Hi there testuser, how goes?`;

this.bot.sendToDiscord(username, '#irc', text);
this.sendStub.should.have.been.calledWith(expected);
});

it('should not convert user at-mentions from IRC if such user does not exist', function () {
const username = 'ircuser';
const text = 'See you there @5pm';
const expected = `**<${username}>** See you there @5pm`;
Expand All @@ -452,6 +485,15 @@ describe('Bot', function () {
this.sendStub.should.have.been.calledWith(expected);
});

it('should not convert user initial mentions from IRC if such user does not exist', function () {
const username = 'ircuser';
const text = 'Agreed, see you then.';
const expected = `**<${username}>** Agreed, see you then.`;

this.bot.sendToDiscord(username, '#irc', text);
this.sendStub.should.have.been.calledWith(expected);
});

it('should convert multiple user mentions from IRC', function () {
const testUser = this.addUser({ username: 'testuser', id: '123' });
const anotherUser = this.addUser({ username: 'anotheruser', id: '124' });
Expand Down