added edit, delete role functions.

This commit is contained in:
5elenay 2021-08-26 19:12:42 +03:00
parent a0ca9b2cd2
commit 6554800a09
2 changed files with 34 additions and 6 deletions

View File

@ -227,11 +227,11 @@ func (em *EditMember) RemoveItem(item string) *EditMember {
// Edit role struct.
type EditRole struct {
Name string `json:"name"`
Colour string `json:"colour"`
Hoist bool `json:"hoist"`
Rank int `json:"rank"`
Remove string `json:"remove"`
Name string `json:"name,omitempty"`
Colour string `json:"colour,omitempty"`
Hoist bool `json:"hoist,omitempty"`
Rank int `json:"rank,omitempty"`
Remove string `json:"remove,omitempty"`
}
// Set name for struct.
@ -250,7 +250,7 @@ func (er *EditRole) SetColour(color string) *EditRole {
return er
}
er.Name = color
er.Colour = color
return er
}

View File

@ -309,6 +309,34 @@ func (s Server) CreateRole(name string) (string, uint, uint, error) {
return role.Id, role.Permissions[0], role.Permissions[1], nil
}
// Edit a server role.
func (s Server) EditRole(id string, er *EditRole) error {
data, err := json.Marshal(er)
if err != nil {
return err
}
_, err = s.Client.Request("PATCH", "/servers/"+s.Id+"/roles/"+id, data)
if err != nil {
return err
}
return nil
}
// Delete a server role.
func (s Server) DeleteRole(id string) error {
_, err := s.Client.Request("DELETE", "/servers/"+s.Id+"/roles/"+id, []byte{})
if err != nil {
return err
}
return nil
}
// // Fetch all server invites.
// func (s Server) FetchInvites() {
// data, _ := s.Client.Request("GET", "/servers/"+s.Id+"/invites", []byte{})