2016-10-09 15:14:02 -04:00
|
|
|
"use strict";
|
|
|
|
|
2018-01-11 06:33:36 -05:00
|
|
|
const Chan = require("../../models/chan");
|
|
|
|
const Msg = require("../../models/msg");
|
2016-10-08 11:11:18 -04:00
|
|
|
|
2019-07-17 05:33:59 -04:00
|
|
|
exports.commands = ["mode", "op", "deop", "hop", "dehop", "voice", "devoice"];
|
2015-09-30 18:39:57 -04:00
|
|
|
|
2020-03-21 16:55:36 -04:00
|
|
|
exports.input = function ({irc, nick}, chan, cmd, args) {
|
2015-09-30 18:39:57 -04:00
|
|
|
if (cmd !== "mode") {
|
2016-10-08 11:11:18 -04:00
|
|
|
if (chan.type !== Chan.Type.CHANNEL) {
|
2019-07-17 05:33:59 -04:00
|
|
|
chan.pushMessage(
|
|
|
|
this,
|
|
|
|
new Msg({
|
|
|
|
type: Msg.Type.ERROR,
|
|
|
|
text: `${cmd} command can only be used in channels.`,
|
|
|
|
})
|
|
|
|
);
|
2016-10-08 11:11:18 -04:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-02 23:50:22 -04:00
|
|
|
const target = args.filter((arg) => arg !== "");
|
|
|
|
|
|
|
|
if (target.length === 0) {
|
2019-07-17 05:33:59 -04:00
|
|
|
chan.pushMessage(
|
|
|
|
this,
|
|
|
|
new Msg({
|
|
|
|
type: Msg.Type.ERROR,
|
|
|
|
text: `Usage: /${cmd} <nick> [...nick]`,
|
|
|
|
})
|
|
|
|
);
|
2016-10-08 11:11:18 -04:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const mode = {
|
2016-10-09 04:54:44 -04:00
|
|
|
op: "+o",
|
2016-10-08 11:11:18 -04:00
|
|
|
hop: "+h",
|
2016-10-09 04:54:44 -04:00
|
|
|
voice: "+v",
|
|
|
|
deop: "-o",
|
2016-10-08 11:11:18 -04:00
|
|
|
dehop: "-h",
|
2017-11-15 01:35:15 -05:00
|
|
|
devoice: "-v",
|
2014-09-13 17:29:45 -04:00
|
|
|
}[cmd];
|
2016-10-08 11:11:18 -04:00
|
|
|
|
2021-07-03 17:20:28 -04:00
|
|
|
const limit = parseInt(irc.network.supports("MODES")) || 1;
|
2021-07-02 23:50:22 -04:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2016-10-08 11:11:18 -04:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.length === 0 || args[0][0] === "+" || args[0][0] === "-") {
|
2019-07-17 05:33:59 -04:00
|
|
|
args.unshift(
|
|
|
|
chan.type === Chan.Type.CHANNEL || chan.type === Chan.Type.QUERY ? chan.name : nick
|
|
|
|
);
|
2014-09-13 17:29:45 -04:00
|
|
|
}
|
2016-03-08 08:36:25 -05:00
|
|
|
|
2017-11-22 01:39:32 -05:00
|
|
|
irc.raw("MODE", ...args);
|
2014-09-13 17:29:45 -04:00
|
|
|
};
|