diff --git a/doc/soju.1.scd b/doc/soju.1.scd index 08c5128..4b699b7 100644 --- a/doc/soju.1.scd +++ b/doc/soju.1.scd @@ -343,6 +343,9 @@ abbreviated form, for instance *network* can be abbreviated as *net* or just *default* Currently same as *message*. This is the default behaviour. +*channel delete* + Leave and forget a channel. + *certfp generate* [options...] Generate self-signed certificate and use it for authentication (via SASL EXTERNAL). diff --git a/service.go b/service.go index 7e6521c..48c5fe3 100644 --- a/service.go +++ b/service.go @@ -291,6 +291,11 @@ func init() { desc: "update a channel", handle: handleServiceChannelUpdate, }, + "delete": { + usage: "", + desc: "delete a channel", + handle: handleServiceChannelDelete, + }, }, }, "server": { @@ -1132,6 +1137,27 @@ func (fs *channelFlagSet) update(channel *database.Channel) error { return nil } +func stripNetworkSuffix(dc *downstreamConn, name string) (string, *network, error) { + if dc.network != nil { + return name, dc.network, nil + } + + l := strings.SplitN(name, "/", 2) + if len(l) != 2 { + return "", nil, fmt.Errorf("missing network name") + } + name = l[0] + netName := l[1] + + for _, network := range dc.user.networks { + if netName == network.GetName() { + return name, network, nil + } + } + + return "", nil, fmt.Errorf("unknown network %q", netName) +} + func handleServiceChannelUpdate(ctx context.Context, dc *downstreamConn, params []string) error { if len(params) < 1 { return fmt.Errorf("expected at least one argument") @@ -1143,25 +1169,9 @@ func handleServiceChannelUpdate(ctx context.Context, dc *downstreamConn, params return err } - network := dc.network - if network == nil { - l := strings.SplitN(name, "/", 2) - if len(l) != 2 { - return fmt.Errorf("missing network name") - } - name = l[0] - netName := l[1] - - for _, n := range dc.user.networks { - if netName == n.GetName() { - network = n - break - } - } - - if network == nil { - return fmt.Errorf("unknown network %q", netName) - } + name, network, err := stripNetworkSuffix(dc, name) + if err != nil { + return err } ch := network.channels.Get(name) @@ -1193,6 +1203,25 @@ func handleServiceChannelUpdate(ctx context.Context, dc *downstreamConn, params return nil } +func handleServiceChannelDelete(ctx context.Context, dc *downstreamConn, params []string) error { + if len(params) < 1 { + return fmt.Errorf("expected at least one argument") + } + name := params[0] + + name, network, err := stripNetworkSuffix(dc, name) + if err != nil { + return err + } + + if err := network.deleteChannel(ctx, name); err != nil { + return fmt.Errorf("failed to delete channel: %v", err) + } + + sendServicePRIVMSG(dc, fmt.Sprintf("deleted channel %q", name)) + return nil +} + func handleServiceServerStatus(ctx context.Context, dc *downstreamConn, params []string) error { dbStats, err := dc.user.srv.db.Stats(ctx) if err != nil {