thelounge/src/plugins/inputs/mode.js

69 lines
1.3 KiB
JavaScript
Raw Normal View History

"use strict";
var Chan = require("../../models/chan");
var Msg = require("../../models/msg");
exports.commands = [
2017-04-22 14:51:21 +02:00
"banlist",
"mode",
"op",
"deop",
"hop",
"dehop",
"voice",
"devoice",
];
2015-10-01 00:39:57 +02:00
2017-04-22 14:51:21 +02:00
const chanCommands = [
"banlist"
];
exports.input = function(network, chan, cmd, args) {
2015-10-01 00:39:57 +02:00
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;
}
2017-04-22 14:51:21 +02:00
if (args.length === 0 && chanCommands.indexOf(cmd) === -1) {
chan.pushMessage(this, new Msg({
type: Msg.Type.ERROR,
text: `Usage: /${cmd} <nick> [...nick]`
}));
return;
}
const mode = {
2017-04-22 14:51:21 +02:00
banlist: "+b",
2016-10-09 10:54:44 +02:00
op: "+o",
hop: "+h",
2016-10-09 10:54:44 +02:00
voice: "+v",
deop: "-o",
dehop: "-h",
2016-10-09 10:54:44 +02:00
devoice: "-v"
2014-09-13 23:29:45 +02:00
}[cmd];
2017-04-22 14:51:21 +02:00
if (chanCommands.indexOf(cmd) > -1 && args.length === 0) {
network.irc.raw("MODE", chan.name, mode);
}
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);
2014-09-13 23:29:45 +02:00
}
2016-03-08 14:36:25 +01:00
args.unshift("MODE");
2016-03-06 10:24:56 +01:00
network.irc.raw.apply(network.irc, args);
2014-09-13 23:29:45 +02:00
};