From d7d3bd6f67e69b93653b1200cb5aaaf4e9c6f046 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 11 Feb 2019 13:54:26 +0100 Subject: [PATCH 1/2] Match IRC-style mentions at beginning of message --- lib/bot.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/bot.js b/lib/bot.js index f562a728..dc13a70c 100644 --- a/lib/bot.js +++ b/lib/bot.js @@ -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 From ba505edd32f75f42d59d6756fb2238985e4a5462 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 4 Mar 2019 15:47:48 +0100 Subject: [PATCH 2/2] Add unit tests for IRC-style initial mentions (#470) --- test/bot.test.js | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/test/bot.test.js b/test/bot.test.js index a4760083..bd0774c3 100644 --- a/test/bot.test.js +++ b/test/bot.test.js @@ -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'; @@ -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`; @@ -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' });