Add user delete command

References: https://todo.sr.ht/~emersion/soju/17
This commit is contained in:
Simon Ser 2020-08-10 15:03:07 +02:00
parent 6598fcf36e
commit ccc8768435
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

View File

@ -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
}