Skip to content
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
10 changes: 10 additions & 0 deletions src/commands/handlers/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ const handlers = {
} else if (option[0] === 'CLIENTTAGDENY') {
// https://ircv3.net/specs/extensions/message-tags#rpl_isupport-tokens
handler.network.options.CLIENTTAGDENY = option[1].split(',').filter((f) => !!f);
} else if (option[0] === 'EXTBAN') {
// https://ircv3.net/specs/extensions/account-extban
const parts = option[1].split(',');
handler.network.options.EXTBAN = {
prefix: parts[0] || '',
types: parts.slice(1).join('').split(''),
};
} else if (option[0] === 'ACCOUNTEXTBAN') {
// https://ircv3.net/specs/extensions/account-extban
handler.network.options.ACCOUNTEXTBAN = option[1].split(',').filter((f) => !!f);
} else if (option[0] === 'NETWORK') {
handler.network.name = option[1];
} else if (option[0] === 'NAMESX' && !handler.network.cap.isEnabled('multi-prefix')) {
Expand Down
9 changes: 9 additions & 0 deletions src/networkinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ function NetworkInfo() {
return this.options.CLIENTTAGDENY.some((tag) => tag === `-${tag_name}`);
};

this.accountBanMask = function accountBanMask(account) {
if (!this.options.EXTBAN || !this.options.ACCOUNTEXTBAN || !this.options.ACCOUNTEXTBAN.length) {
return null;
}

const type = this.options.ACCOUNTEXTBAN[0];
return this.options.EXTBAN.prefix + type + ':' + account;
};

this.isChannelName = function isChannelName(channel_name) {
if (typeof channel_name !== 'string' || channel_name === '') {
return false;
Expand Down
88 changes: 88 additions & 0 deletions test/networkinfo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,92 @@ describe('src/networkinfo.js', function() {
assert.isFalse(client.network.supportsTag('b'));
});
});

describe('EXTBAN and ACCOUNTEXTBAN support', function() {
it('should parse EXTBAN into prefix and types', function() {
const client = newMockClient();
client.dispatch({
command: '005',
params: ['nick', 'EXTBAN=$,ARar'],
tags: []
});
assert.deepEqual(client.network.options.EXTBAN, {
prefix: '$',
types: ['A', 'R', 'a', 'r'],
});
});

it('should parse EXTBAN with tilde prefix', function() {
const client = newMockClient();
client.dispatch({
command: '005',
params: ['nick', 'EXTBAN=~,a'],
tags: []
});
assert.deepEqual(client.network.options.EXTBAN, {
prefix: '~',
types: ['a'],
});
});

it('should parse ACCOUNTEXTBAN as a list', function() {
const client = newMockClient();
client.dispatch({
command: '005',
params: ['nick', 'ACCOUNTEXTBAN=a,account'],
tags: []
});
assert.deepEqual(client.network.options.ACCOUNTEXTBAN, ['a', 'account']);
});

it('should parse single ACCOUNTEXTBAN value', function() {
const client = newMockClient();
client.dispatch({
command: '005',
params: ['nick', 'ACCOUNTEXTBAN=R'],
tags: []
});
assert.deepEqual(client.network.options.ACCOUNTEXTBAN, ['R']);
});

it('should construct account ban mask with $ prefix', function() {
const client = newMockClient();
client.dispatch({
command: '005',
params: ['nick', 'EXTBAN=$,ARar', 'ACCOUNTEXTBAN=R'],
tags: []
});
assert.equal(client.network.accountBanMask('bob'), '$R:bob');
});

it('should construct account ban mask with ~ prefix', function() {
const client = newMockClient();
client.dispatch({
command: '005',
params: ['nick', 'EXTBAN=~,a', 'ACCOUNTEXTBAN=a,account'],
tags: []
});
assert.equal(client.network.accountBanMask('bob'), '~a:bob');
});

it('should return null when EXTBAN is not available', function() {
const client = newMockClient();
client.dispatch({
command: '005',
params: ['nick', 'ACCOUNTEXTBAN=R'],
tags: []
});
assert.isNull(client.network.accountBanMask('bob'));
});

it('should return null when ACCOUNTEXTBAN is not available', function() {
const client = newMockClient();
client.dispatch({
command: '005',
params: ['nick', 'EXTBAN=$,ARar'],
tags: []
});
assert.isNull(client.network.accountBanMask('bob'));
});
});
});
Loading