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