Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting to disable IRC- and/or Discord-style mentions #537

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
9 changes: 8 additions & 1 deletion lib/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {};
Expand Down Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions test/bot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [] },
Expand Down