thelounge/server/plugins/inputs/mode.ts

73 lines
1.5 KiB
TypeScript
Raw Normal View History

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