Add user delete
command
References: https://todo.sr.ht/~emersion/soju/17
This commit is contained in:
parent
6598fcf36e
commit
ccc8768435
27
service.go
27
service.go
@ -204,6 +204,12 @@ func init() {
|
|||||||
handle: handleUserCreate,
|
handle: handleUserCreate,
|
||||||
admin: true,
|
admin: true,
|
||||||
},
|
},
|
||||||
|
"delete": {
|
||||||
|
usage: "<username>",
|
||||||
|
desc: "delete a user",
|
||||||
|
handle: handleUserDelete,
|
||||||
|
admin: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
admin: true,
|
admin: true,
|
||||||
},
|
},
|
||||||
@ -669,3 +675,24 @@ func handleUserCreate(dc *downstreamConn, params []string) error {
|
|||||||
sendServicePRIVMSG(dc, fmt.Sprintf("created user %q", *username))
|
sendServicePRIVMSG(dc, fmt.Sprintf("created user %q", *username))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleUserDelete(dc *downstreamConn, params []string) error {
|
||||||
|
if len(params) != 1 {
|
||||||
|
return fmt.Errorf("expected exactly one argument")
|
||||||
|
}
|
||||||
|
username := params[0]
|
||||||
|
|
||||||
|
u := dc.srv.getUser(username)
|
||||||
|
if u == nil {
|
||||||
|
return fmt.Errorf("unknown username %q", username)
|
||||||
|
}
|
||||||
|
|
||||||
|
u.stop()
|
||||||
|
|
||||||
|
if err := dc.srv.db.DeleteUser(username); err != nil {
|
||||||
|
return fmt.Errorf("failed to delete user: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
sendServicePRIVMSG(dc, fmt.Sprintf("deleted user %q", username))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user