Add /voice, /devoice

This also generalizes the logic for these commands along with /op and
/deop.
This commit is contained in:
Drew DeVault 2021-05-28 11:57:18 -04:00 committed by Simon Ser
parent b4367eb13c
commit 0473b9ced7

View file

@ -71,6 +71,21 @@ const kick = {
}, },
}; };
function givemode(app, args, mode) {
// TODO: Handle several users at once
var nick = args[0];
if (!nick) {
throw new Error("Missing nick");
}
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, mode, nick,
]});
}
export default { export default {
"ban": ban, "ban": ban,
"buffer": { "buffer": {
@ -100,19 +115,12 @@ export default {
"deop": { "deop": {
usage: "<nick>", usage: "<nick>",
description: "Removes operator status for a user on this channel", description: "Removes operator status for a user on this channel",
execute: (app, args) => { execute: (app, args) => givemode(app, args, "-o"),
var nick = args[0]; },
if (!nick) { "devoice": {
throw new Error("Missing nick"); usage: "<nick>",
} description: "Removes voiced status for a user on this channel",
var activeBuffer = app.state.buffers.get(app.state.activeBuffer); execute: (app, args) => givemode(app, args, "-v"),
if (!activeBuffer || !app.isChannel(activeBuffer.name)) {
throw new Error("Not in a channel");
}
getActiveClient(app).send({ command: "MODE", params: [
activeBuffer.name, "-o", user,
]});
},
}, },
"disconnect": { "disconnect": {
description: "Disconnect from the server", description: "Disconnect from the server",
@ -201,19 +209,7 @@ export default {
"op": { "op": {
usage: "<nick>", usage: "<nick>",
description: "Gives a user operator status on this channel", description: "Gives a user operator status on this channel",
execute: (app, args) => { execute: (app, args) => givemode(app, args, "+o"),
var nick = args[0];
if (!nick) {
throw new Error("Missing nick");
}
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, "+o", nick,
]});
},
}, },
"part": { "part": {
usage: "[reason]", usage: "[reason]",
@ -309,6 +305,11 @@ export default {
getActiveClient(app).send({ command: "TOPIC", params }); getActiveClient(app).send({ command: "TOPIC", params });
}, },
}, },
"voice": {
usage: "<nick>",
description: "Gives a user voiced status on this channel",
execute: (app, args) => givemode(app, args, "+v"),
},
"whois": { "whois": {
usage: "<nick>", usage: "<nick>",
description: "Retrieve information about a user", description: "Retrieve information about a user",