thelounge/src/plugins/inputs/ban.ts

56 lines
1 KiB
TypeScript
Raw Normal View History

2017-04-24 12:40:53 +02:00
"use strict";
2022-05-05 00:41:57 +02:00
import {ChanType} from "../../models/chan";
import Msg, {MessageType} from "../../models/msg";
import {PluginInputHandler} from "./index";
2017-04-24 12:40:53 +02:00
const commands = ["ban", "unban", "banlist", "kickban"];
2017-04-24 12:40:53 +02:00
2022-05-03 03:32:20 +02:00
const input: PluginInputHandler = function ({irc}, chan, cmd, args) {
2022-05-02 07:56:38 +02:00
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.`,
})
);
2017-04-24 12:40:53 +02:00
return;
}
if (cmd !== "banlist" && args.length === 0) {
if (args.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>`,
})
);
2017-04-24 12:40:53 +02:00
return;
}
}
switch (cmd) {
case "kickban":
irc.raw("KICK", chan.name, args[0], args.slice(1).join(" "));
// fall through
2019-07-17 11:33:59 +02:00
case "ban":
irc.ban(chan.name, args[0]);
break;
case "unban":
irc.unban(chan.name, args[0]);
break;
case "banlist":
irc.banlist(chan.name);
break;
2017-04-24 12:40:53 +02:00
}
};
export default {
commands,
input,
};