From 4dacaa46f37ac5a0b46076cf68e193e7eb5f2b39 Mon Sep 17 00:00:00 2001 From: JeDaYoshi Date: Sat, 3 Jul 2021 03:50:22 +0000 Subject: [PATCH] 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 ') --- src/plugins/inputs/mode.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/plugins/inputs/mode.js b/src/plugins/inputs/mode.js index 4598a566..a86f3e26 100644 --- a/src/plugins/inputs/mode.js +++ b/src/plugins/inputs/mode.js @@ -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; }