diff --git a/README.md b/README.md index 1791860..1afa8e4 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,7 @@ First you need to create a Discord bot user, which you can do by following the i "webhookAvatarURL": "https://robohash.org/{$nickname}" // Default avatar to use for webhook messages }, "ircNickColor": false, // Gives usernames a color in IRC for better readability (on by default) + "ircPreventMention": true, // Prevents users of both IRC and Discord from being mentioned in IRC when they speak in Discord (off by default) // Makes the bot hide the username prefix for messages that start // with one of these characters (commands): "commandCharacters": ["!", "."], diff --git a/lib/bot.js b/lib/bot.js index 345a5b2..35fc934 100644 --- a/lib/bot.js +++ b/lib/bot.js @@ -37,6 +37,7 @@ class Bot { this.discordToken = options.discordToken; this.commandCharacters = options.commandCharacters || []; this.ircNickColor = options.ircNickColor !== false; // default to true + this.ircPreventMention = options.ircPreventMention === true; // default: false this.channels = _.values(options.channelMapping); this.ircStatusNotices = options.ircStatusNotices; this.announceSelfJoin = options.announceSelfJoin; @@ -325,9 +326,16 @@ class Bot { const nickname = Bot.getDiscordNicknameOnServer(author, fromGuild); let text = this.parseText(message); let displayUsername = nickname; + + if (this.ircPreventMention) { + // Prevent users of both IRC and Discord from + // being mentioned in IRC when they talk in Discord. + displayUsername = `${displayUsername.slice(0, 1)}\u200B${displayUsername.slice(1)}`; + } + if (this.ircNickColor) { const colorIndex = (nickname.charCodeAt(0) + nickname.length) % NICK_COLORS.length; - displayUsername = irc.colors.wrap(NICK_COLORS[colorIndex], nickname); + displayUsername = irc.colors.wrap(NICK_COLORS[colorIndex], displayUsername); } const patternMap = { diff --git a/test/bot.test.js b/test/bot.test.js index 7981a27..b98bf64 100644 --- a/test/bot.test.js +++ b/test/bot.test.js @@ -336,6 +336,33 @@ describe('Bot', function () { } ); + it('should break mentions when ircPreventMention is enabled', function () { + const newConfig = { ...config, ircPreventMention: true }; + this.bot = new Bot(newConfig); + this.bot.connect(); + + const text = 'testmessage'; + const username = 'otherauthor'; + const brokenNickname = 'o\u200Btherauthor'; + const message = { + content: text, + mentions: { users: [] }, + channel: { + name: 'discord' + }, + author: { + username, + id: 'not bot id' + }, + guild: this.guild + }; + + this.bot.sendToIRC(message); + // Wrap in colors: + const expected = `<\u000304${brokenNickname}\u000f> ${text}`; + ClientStub.prototype.say.should.have.been.calledWith('#irc', expected); + }); + it('should parse text from discord when sending messages', function () { const text = '<#1234>'; const message = {