From 0473b9ced7b3f4b181e63a91f29e7ef209c5c460 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 28 May 2021 11:57:18 -0400 Subject: [PATCH] Add /voice, /devoice This also generalizes the logic for these commands along with /op and /deop. --- commands.js | 53 +++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/commands.js b/commands.js index abf46df..f112816 100644 --- a/commands.js +++ b/commands.js @@ -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 { "ban": ban, "buffer": { @@ -100,19 +115,12 @@ export default { "deop": { usage: "", description: "Removes operator status for a user on this channel", - execute: (app, args) => { - 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", user, - ]}); - }, + execute: (app, args) => givemode(app, args, "-o"), + }, + "devoice": { + usage: "", + description: "Removes voiced status for a user on this channel", + execute: (app, args) => givemode(app, args, "-v"), }, "disconnect": { description: "Disconnect from the server", @@ -201,19 +209,7 @@ export default { "op": { usage: "", description: "Gives a user operator status on this channel", - execute: (app, args) => { - 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, - ]}); - }, + execute: (app, args) => givemode(app, args, "+o"), }, "part": { usage: "[reason]", @@ -309,6 +305,11 @@ export default { getActiveClient(app).send({ command: "TOPIC", params }); }, }, + "voice": { + usage: "", + description: "Gives a user voiced status on this channel", + execute: (app, args) => givemode(app, args, "+v"), + }, "whois": { usage: "", description: "Retrieve information about a user",