Skip to content

Commit 816c3db

Browse files
committed
add setting to disable irc- or discord-style mentions
1 parent 41f8444 commit 816c3db

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

lib/bot.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class Bot {
4242
this.ircStatusNotices = options.ircStatusNotices;
4343
this.announceSelfJoin = options.announceSelfJoin;
4444
this.webhookOptions = options.webhooks;
45+
this.allowDiscordStyleNotifyFromIRC = options.allowDiscordStyleNotifyFromIRC !== false;
46+
this.allowIRCStyleNotifyFromIRC = options.allowIRCStyleNotifyFromIRC !== false;
4547

4648
// Nicks to ignore
4749
this.ignoreUsers = options.ignoreUsers || {};
@@ -505,7 +507,12 @@ class Bot {
505507

506508
return match;
507509
}).replace(/^([^@\s:,]+)[:,]|@([^\s]+)/g, (match, startRef, atRef) => {
508-
const reference = startRef || atRef;
510+
// override the detection via settings
511+
const filteredStartRef = this.allowIRCStyleNotifyFromIRC ? startRef : null;
512+
const filteredAtRef = this.allowDiscordStyleNotifyFromIRC ? atRef : null;
513+
514+
const reference = filteredStartRef || filteredAtRef;
515+
if (!reference) return match;
509516

510517
// this preliminary stuff is ultimately unnecessary
511518
// but might save time over later more complicated calculations

test/bot.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,34 @@ describe('Bot', function () {
558558
this.sendStub.should.have.been.calledWith(expected);
559559
});
560560

561+
it('should not convert user at-mentions from IRC if setting is disabled', function () {
562+
const newConfig = { ...config, allowDiscordStyleNotifyFromIRC: false };
563+
this.setCustomBot(newConfig);
564+
565+
const testUser = this.addUser({ username: 'testuser', id: '123' });
566+
567+
const username = 'ircuser';
568+
const text = `Not mentioning @${testUser.username}`;
569+
const expected = `**<${username}>** Not mentioning @${testUser.username}`;
570+
571+
this.bot.sendToDiscord(username, '#irc', text);
572+
this.sendStub.should.have.been.calledWith(expected);
573+
});
574+
575+
it('should not convert user initial mentions from IRC if setting is disabled', function () {
576+
const newConfig = { ...config, allowIRCStyleNotifyFromIRC: false };
577+
this.setCustomBot(newConfig);
578+
579+
const testUser = this.addUser({ username: 'testuser', id: '123' });
580+
581+
const username = 'ircuser';
582+
const text = `${testUser.username}: not mentioning you!`;
583+
const expected = `**<${username}>** ${testUser.username}: not mentioning you!`;
584+
585+
this.bot.sendToDiscord(username, '#irc', text);
586+
this.sendStub.should.have.been.calledWith(expected);
587+
});
588+
561589
it('should convert newlines from discord', function () {
562590
const message = {
563591
mentions: { users: [] },

0 commit comments

Comments
 (0)