~emersion/soju-dev

Add detach command to service handler v1 PROPOSED

gildarts: 1
 Add detach command to service handler

 1 files changed, 31 insertions(+), 0 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/soju-dev/patches/23724/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] Add detach command to service handler Export this patch

This adds the option of detaching a channel by messaging the bouncerserv
service. Format of the command is `channel detach <name>`.

Partially resolves ~emersion/soju#37
---
 service.go | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/service.go b/service.go
index b95f551..7816c30 100644
--- a/service.go
+++ b/service.go
@@ -290,6 +290,11 @@ func init() {
					desc:   "update a channel",
					handle: handleServiceChannelUpdate,
				},
				"detach": {
					usage:  "<name>",
					desc:   "detach a channel",
					handle: handleServiceChannelDetach,
				},
			},
		},
	}
@@ -1007,3 +1012,29 @@ func handleServiceChannelUpdate(dc *downstreamConn, params []string) error {
	sendServicePRIVMSG(dc, fmt.Sprintf("updated channel %q", name))
	return nil
}

func handleServiceChannelDetach(dc *downstreamConn, params []string) error {
	if len(params) < 1 {
		return fmt.Errorf("expected at least one argument")
	}
	name := params[0]

	uc, upstreamName, err := dc.unmarshalEntity(name)
	if err != nil {
		return fmt.Errorf("unknown channel %q", name)
	}

	ch := uc.network.channels.Value(upstreamName)
	if ch == nil {
		return fmt.Errorf("unknown channel %q", name)
	}

	uc.network.detach(ch)

	if err := dc.srv.db.StoreChannel(uc.network.ID, ch); err != nil {
		return fmt.Errorf("failed to update channel: %v", err)
	}

	sendServicePRIVMSG(dc, fmt.Sprintf("detached channel %q", name))
	return nil
}
-- 
2.25.1