diff --git a/lib/bot.js b/lib/bot.js index fa3b1474..7a70865f 100644 --- a/lib/bot.js +++ b/lib/bot.js @@ -42,6 +42,8 @@ class Bot { this.ircStatusNotices = options.ircStatusNotices; this.announceSelfJoin = options.announceSelfJoin; this.webhookOptions = options.webhooks; + this.allowDiscordStyleNotifyFromIRC = options.allowDiscordStyleNotifyFromIRC !== false; + this.allowIRCStyleNotifyFromIRC = options.allowIRCStyleNotifyFromIRC !== false; // Nicks to ignore this.ignoreUsers = options.ignoreUsers || {}; @@ -505,7 +507,12 @@ class Bot { return match; }).replace(/^([^@\s:,]+)[:,]|@([^\s]+)/g, (match, startRef, atRef) => { - const reference = startRef || atRef; + // override the detection via settings + const filteredStartRef = this.allowIRCStyleNotifyFromIRC ? startRef : null; + const filteredAtRef = this.allowDiscordStyleNotifyFromIRC ? atRef : null; + + const reference = filteredStartRef || filteredAtRef; + if (!reference) return match; // this preliminary stuff is ultimately unnecessary // but might save time over later more complicated calculations diff --git a/test/bot.test.js b/test/bot.test.js index bcf38e93..baaf256f 100644 --- a/test/bot.test.js +++ b/test/bot.test.js @@ -558,6 +558,34 @@ describe('Bot', function () { this.sendStub.should.have.been.calledWith(expected); }); + it('should not convert user at-mentions from IRC if setting is disabled', function () { + const newConfig = { ...config, allowDiscordStyleNotifyFromIRC: false }; + this.setCustomBot(newConfig); + + const testUser = this.addUser({ username: 'testuser', id: '123' }); + + const username = 'ircuser'; + const text = `Not mentioning @${testUser.username}`; + const expected = `**<${username}>** Not mentioning @${testUser.username}`; + + this.bot.sendToDiscord(username, '#irc', text); + this.sendStub.should.have.been.calledWith(expected); + }); + + it('should not convert user initial mentions from IRC if setting is disabled', function () { + const newConfig = { ...config, allowIRCStyleNotifyFromIRC: false }; + this.setCustomBot(newConfig); + + const testUser = this.addUser({ username: 'testuser', id: '123' }); + + const username = 'ircuser'; + const text = `${testUser.username}: not mentioning you!`; + const expected = `**<${username}>** ${testUser.username}: not mentioning you!`; + + this.bot.sendToDiscord(username, '#irc', text); + this.sendStub.should.have.been.calledWith(expected); + }); + it('should convert newlines from discord', function () { const message = { mentions: { users: [] },