Optimise modes based on ISUPPORT

This will see the maximum allowed of modes that are allowed at once as sent in RPL_ISUPPORT
and will send multiple batches while using /op, /voice, etc.

This also fixes a minor issue where it would try sending an empty voice if it had an extra space on arguments
(such as using '/voice  ')
This commit is contained in:
JeDaYoshi 2021-07-03 03:50:22 +00:00
parent 22801a629e
commit 4dacaa46f3
No known key found for this signature in database
GPG key ID: 8060B288C274219D

View file

@ -19,7 +19,9 @@ exports.input = function ({irc, nick}, chan, cmd, args) {
return;
}
if (args.length === 0) {
const target = args.filter((arg) => arg !== "");
if (target.length === 0) {
chan.pushMessage(
this,
new Msg({
@ -40,9 +42,13 @@ exports.input = function ({irc, nick}, chan, cmd, args) {
devoice: "-v",
}[cmd];
args.forEach(function (target) {
irc.raw("MODE", chan.name, mode, target);
});
const limit = parseInt(irc.network.supports("modes")) || 1;
for (let i = 0; i < target.length; i += limit) {
const targets = target.slice(i, i + limit);
const amode = `${mode[0]}${mode[1].repeat(targets.length)}`;
irc.raw("MODE", chan.name, amode, ...targets);
}
return;
}