service: add channel delete command
This commit is contained in:
parent
f44e922c42
commit
0edf3a40c2
@ -343,6 +343,9 @@ abbreviated form, for instance *network* can be abbreviated as *net* or just
|
|||||||
*default*
|
*default*
|
||||||
Currently same as *message*. This is the default behaviour.
|
Currently same as *message*. This is the default behaviour.
|
||||||
|
|
||||||
|
*channel delete* <name>
|
||||||
|
Leave and forget a channel.
|
||||||
|
|
||||||
*certfp generate* [options...]
|
*certfp generate* [options...]
|
||||||
Generate self-signed certificate and use it for authentication (via SASL
|
Generate self-signed certificate and use it for authentication (via SASL
|
||||||
EXTERNAL).
|
EXTERNAL).
|
||||||
|
67
service.go
67
service.go
@ -291,6 +291,11 @@ func init() {
|
|||||||
desc: "update a channel",
|
desc: "update a channel",
|
||||||
handle: handleServiceChannelUpdate,
|
handle: handleServiceChannelUpdate,
|
||||||
},
|
},
|
||||||
|
"delete": {
|
||||||
|
usage: "<name>",
|
||||||
|
desc: "delete a channel",
|
||||||
|
handle: handleServiceChannelDelete,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"server": {
|
"server": {
|
||||||
@ -1132,6 +1137,27 @@ func (fs *channelFlagSet) update(channel *database.Channel) error {
|
|||||||
return nil
|
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 {
|
func handleServiceChannelUpdate(ctx context.Context, dc *downstreamConn, params []string) error {
|
||||||
if len(params) < 1 {
|
if len(params) < 1 {
|
||||||
return fmt.Errorf("expected at least one argument")
|
return fmt.Errorf("expected at least one argument")
|
||||||
@ -1143,25 +1169,9 @@ func handleServiceChannelUpdate(ctx context.Context, dc *downstreamConn, params
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
network := dc.network
|
name, network, err := stripNetworkSuffix(dc, name)
|
||||||
if network == nil {
|
if err != nil {
|
||||||
l := strings.SplitN(name, "/", 2)
|
return err
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ch := network.channels.Get(name)
|
ch := network.channels.Get(name)
|
||||||
@ -1193,6 +1203,25 @@ func handleServiceChannelUpdate(ctx context.Context, dc *downstreamConn, params
|
|||||||
return nil
|
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 {
|
func handleServiceServerStatus(ctx context.Context, dc *downstreamConn, params []string) error {
|
||||||
dbStats, err := dc.user.srv.db.Stats(ctx)
|
dbStats, err := dc.user.srv.db.Stats(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user