Add support for /ban without argument

This commit is contained in:
Simon Ser 2021-06-03 10:11:48 +02:00
parent 5004f6c89c
commit a4294975a2
3 changed files with 50 additions and 30 deletions

View File

@ -9,35 +9,31 @@ function getActiveClient(app) {
return app.clients.get(buf.network); return app.clients.get(buf.network);
} }
const ban = { function ban(app, args) {
usage: "<nick>", var nick = args[0];
description: "Bans a user from the channel", if (!nick) {
execute: (app, args) => { throw new Error("Missing nick");
var nick = args[0]; }
if (!nick) { var activeBuffer = app.state.buffers.get(app.state.activeBuffer);
throw new Error("Missing nick"); if (!activeBuffer || !app.isChannel(activeBuffer.name)) {
} throw new Error("Not in a channel");
var activeBuffer = app.state.buffers.get(app.state.activeBuffer); }
if (!activeBuffer || !app.isChannel(activeBuffer.name)) { var params = [activeBuffer.name, nick];
throw new Error("Not in a channel"); if (args.length > 1) {
} params.push(args.slice(1).join(" "));
var params = [activeBuffer.name, nick]; }
if (args.length > 1) { const client = getActiveClient(app);
params.push(args.slice(1).join(" ")); client.whois(nick).then((whois) => {
} const info = whois[irc.RPL_WHOISUSER].params;
const client = getActiveClient(app); const user = info[2];
client.whois(nick).then((whois) => { const host = info[3];
const info = whois[irc.RPL_WHOISUSER].params; client.send({ command: "MODE", params: [
const user = info[2]; activeBuffer.name,
const host = info[3]; "+b",
client.send({ command: "MODE", params: [ `*!${user}@${host}`
activeBuffer.name, ]});
"+b", });
`*!${user}@${host}` }
]});
});
},
};
const join = { const join = {
usage: "<name>", usage: "<name>",
@ -84,7 +80,24 @@ function givemode(app, args, mode) {
} }
export default { export default {
"ban": ban, "ban": {
usage: "[nick]",
description: "Bans a user from the channel, or displays the current ban list",
execute: (app, args) => {
if (args.length == 0) {
var activeBuffer = app.state.buffers.get(app.state.activeBuffer);
if (!activeBuffer || !app.isChannel(activeBuffer.name)) {
throw new Error("Not in a channel");
}
getActiveClient(app).send({
command: "MODE",
params: [activeBuffer.name, "+b"],
});
} else {
return ban(app, args);
}
},
},
"buffer": { "buffer": {
usage: "<name>", usage: "<name>",
description: "Switch to a buffer", description: "Switch to a buffer",

View File

@ -898,6 +898,11 @@ export default class App extends Component {
} }
}); });
break; break;
case irc.RPL_BANLIST:
case irc.RPL_ENDOFBANLIST:
var channel = msg.params[1];
this.addMessage(netID, channel, msg);
break;
case "CAP": case "CAP":
case "AUTHENTICATE": case "AUTHENTICATE":
case "PING": case "PING":

View File

@ -17,6 +17,8 @@ export const RPL_TOPICWHOTIME = "333";
export const RPL_WHOREPLY = "352"; export const RPL_WHOREPLY = "352";
export const RPL_NAMREPLY = "353"; export const RPL_NAMREPLY = "353";
export const RPL_ENDOFNAMES = "366"; export const RPL_ENDOFNAMES = "366";
export const RPL_BANLIST = "367";
export const RPL_ENDOFBANLIST = "368";
export const RPL_MOTD = "372"; export const RPL_MOTD = "372";
export const RPL_MOTDSTART = "375"; export const RPL_MOTDSTART = "375";
export const RPL_ENDOFMOTD = "376"; export const RPL_ENDOFMOTD = "376";