2022-06-19 00:25:21 +00:00
|
|
|
import {PluginInputHandler} from "./index";
|
2016-10-09 19:14:02 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
import Msg, {MessageType} from "../../models/msg";
|
|
|
|
import {ChanType} from "../../models/chan";
|
2016-10-08 15:11:18 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const commands = ["mode", "umode", "op", "deop", "hop", "dehop", "voice", "devoice"];
|
2015-09-30 22:39:57 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const input: PluginInputHandler = function ({irc, nick}, chan, cmd, args) {
|
2021-07-03 02:28:21 +00:00
|
|
|
if (cmd === "umode") {
|
|
|
|
irc.raw("MODE", nick, ...args);
|
|
|
|
|
|
|
|
return;
|
|
|
|
} else if (cmd !== "mode") {
|
2022-06-19 00:25:21 +00:00
|
|
|
if (chan.type !== ChanType.CHANNEL) {
|
2019-07-17 09:33:59 +00:00
|
|
|
chan.pushMessage(
|
|
|
|
this,
|
|
|
|
new Msg({
|
2022-06-19 00:25:21 +00:00
|
|
|
type: MessageType.ERROR,
|
2019-07-17 09:33:59 +00:00
|
|
|
text: `${cmd} command can only be used in channels.`,
|
|
|
|
})
|
|
|
|
);
|
2016-10-08 15:11:18 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-03 03:50:22 +00:00
|
|
|
const target = args.filter((arg) => arg !== "");
|
|
|
|
|
|
|
|
if (target.length === 0) {
|
2019-07-17 09:33:59 +00:00
|
|
|
chan.pushMessage(
|
|
|
|
this,
|
|
|
|
new Msg({
|
2022-06-19 00:25:21 +00:00
|
|
|
type: MessageType.ERROR,
|
2019-07-17 09:33:59 +00:00
|
|
|
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
|
|
|
|
2021-07-06 15:48:01 +00:00
|
|
|
const limit = parseInt(irc.network.supports("MODES")) || target.length;
|
2021-07-03 03:50:22 +00:00
|
|
|
|
|
|
|
for (let i = 0; i < target.length; i += limit) {
|
|
|
|
const targets = target.slice(i, i + limit);
|
2022-06-19 00:25:21 +00:00
|
|
|
const amode = `${mode![0]}${mode![1].repeat(targets.length)}`;
|
2021-07-03 03:50:22 +00:00
|
|
|
irc.raw("MODE", chan.name, amode, ...targets);
|
|
|
|
}
|
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(
|
2022-06-19 00:25:21 +00:00
|
|
|
chan.type === ChanType.CHANNEL || chan.type === ChanType.QUERY ? chan.name : nick
|
2019-07-17 09:33:59 +00:00
|
|
|
);
|
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
|
|
|
};
|
2022-06-19 00:25:21 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
commands,
|
|
|
|
input,
|
|
|
|
};
|