hardlounge/server/plugins/inputs/ban.ts

54 lines
1014 B
TypeScript
Raw Normal View History

import {ChanType} from "../../models/chan";
import Msg, {MessageType} from "../../models/msg";
import {PluginInputHandler} from "./index";
2017-04-24 10:40:53 +00:00
const commands = ["ban", "unban", "banlist", "kickban"];
2017-04-24 10:40:53 +00:00
const input: PluginInputHandler = function ({irc}, chan, cmd, args) {
if (chan.type !== ChanType.CHANNEL) {
2019-07-17 09:33:59 +00:00
chan.pushMessage(
this,
new Msg({
type: MessageType.ERROR,
2019-07-17 09:33:59 +00:00
text: `${cmd} command can only be used in channels.`,
})
);
2017-04-24 10:40:53 +00:00
return;
}
if (cmd !== "banlist" && args.length === 0) {
if (args.length === 0) {
2019-07-17 09:33:59 +00:00
chan.pushMessage(
this,
new Msg({
type: MessageType.ERROR,
2019-07-17 09:33:59 +00:00
text: `Usage: /${cmd} <nick>`,
})
);
2017-04-24 10:40:53 +00:00
return;
}
}
switch (cmd) {
case "kickban":
irc.raw("KICK", chan.name, args[0], args.slice(1).join(" "));
// fall through
2019-07-17 09:33:59 +00: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 10:40:53 +00:00
}
};
export default {
commands,
input,
};