~emersion/public-inbox

gamja: Add /voice, /devoice v1 APPLIED

Drew DeVault: 1
 Add /voice, /devoice

 1 files changed, 27 insertions(+), 26 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~emersion/public-inbox/patches/23050/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH gamja] Add /voice, /devoice Export this patch

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..40260c3 100644
--- a/commands.js
+++ b/commands.js
@@ -71,6 +71,21 @@ const kick = {
	},
};

const 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: "<nick>",
		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: "<nick>",
		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: "<nick>",
		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: "<nick>",
		description: "Gives a user voiced status on this channel",
		execute: (app, args) => givemode(app, args, "+v"),
	},
	"whois": {
		usage: "<nick>",
		description: "Retrieve information about a user",
-- 
2.31.1
Pushed, thanks!

On Friday, May 28th, 2021 at 5:57 PM, Drew DeVault <sir@cmpwn.com> wrote: