Fix /mode command to correctly assume target

This commit is contained in:
Pavel Djundik 2016-10-08 18:11:18 +03:00
parent 3a0017583b
commit bfeaeee873

View File

@ -2,30 +2,60 @@
exports.commands = ["mode", "op", "voice", "deop", "devoice"]; exports.commands = ["mode", "op", "voice", "deop", "devoice"];
var Chan = require("../../models/chan");
var Msg = require("../../models/msg");
exports.commands = [
"mode",
"op",
"deop",
"hop",
"dehop",
"voice",
"devoice",
];
exports.input = function(network, chan, cmd, args) { exports.input = function(network, chan, cmd, args) {
if (args.length === 0) { if (cmd !== "mode") {
if (chan.type !== Chan.Type.CHANNEL) {
chan.pushMessage(this, new Msg({
type: Msg.Type.ERROR,
text: `${cmd} command can only be used in channels.`
}));
return; return;
} }
var mode; if (args.length === 0) {
var user; chan.pushMessage(this, new Msg({
if (cmd !== "mode") { type: Msg.Type.ERROR,
user = args[0]; text: `Usage: /${cmd} <nick> [...nick]`
mode = { }));
op: "+o",
voice: "+v", return;
deop: "-o",
devoice: "-v"
}[cmd];
} else if (args.length === 1) {
return true;
} else {
mode = args[0];
user = args[1];
} }
var irc = network.irc; const mode = {
irc.raw("MODE", chan.name, mode, user); op: "+o",
hop: "+h",
voice: "+v",
deop: "-o",
dehop: "-h",
devoice: "-v"
}[cmd];
return true; args.forEach(function(target) {
network.irc.raw("MODE", chan.name, mode, target);
});
return;
}
if (args.length === 0 || args[0][0] === "+" || args[0][0] === "-") {
args.unshift(chan.type === Chan.Type.CHANNEL || chan.type === Chan.Type.QUERY ? chan.name : network.nick);
}
args.unshift("MODE");
network.irc.raw.apply(network.irc, args);
}; };