Add support for guild region and verification level
This commit is contained in:
parent
ec5dd888c1
commit
1a844d697d
2 changed files with 60 additions and 22 deletions
38
restapi.go
38
restapi.go
|
@ -372,13 +372,43 @@ func (s *Session) GuildCreate(name string) (st *Guild, err error) {
|
||||||
// GuildEdit edits a new Guild
|
// GuildEdit edits a new Guild
|
||||||
// guildID : The ID of a Guild
|
// guildID : The ID of a Guild
|
||||||
// name : A name for the Guild (2-100 characters)
|
// name : A name for the Guild (2-100 characters)
|
||||||
func (s *Session) GuildEdit(guildID, name string) (st *Guild, err error) {
|
func (s *Session) GuildEdit(guildID string, g GuildParams) (st *Guild, err error) {
|
||||||
|
|
||||||
|
// Bounds checking for VerificationLevel, interval: [0, 3]
|
||||||
|
if g.VerificationLevel != nil {
|
||||||
|
val := *g.VerificationLevel
|
||||||
|
if val < 0 || val > 3 {
|
||||||
|
err = errors.New("VerificationLevel out of bounds, should be between 0 and 3")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Bounds checking for regions
|
||||||
|
if g.Region != "" {
|
||||||
|
isValid := false
|
||||||
|
regions, _ := s.VoiceRegions()
|
||||||
|
for _, r := range regions {
|
||||||
|
if g.Region == r.ID {
|
||||||
|
isValid = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !isValid {
|
||||||
|
var valid []string
|
||||||
|
for _, r := range regions {
|
||||||
|
valid = append(valid, r.ID)
|
||||||
|
}
|
||||||
|
err = errors.New(fmt.Sprintf("Region not a valid region (%q)", valid))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
data := struct {
|
data := struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name,omitempty"`
|
||||||
}{name}
|
Region string `json:"region,omitempty"`
|
||||||
|
VerificationLevel *int `json:"verification_level,omitempty"`
|
||||||
|
}{g.Name, g.Region, g.VerificationLevel}
|
||||||
|
|
||||||
body, err := s.Request("POST", GUILD(guildID), data)
|
body, err := s.Request("PATCH", GUILD(guildID), data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,6 +158,7 @@ type Guild struct {
|
||||||
JoinedAt string `json:"joined_at"` // make this a timestamp
|
JoinedAt string `json:"joined_at"` // make this a timestamp
|
||||||
Splash string `json:"splash"`
|
Splash string `json:"splash"`
|
||||||
AfkTimeout int `json:"afk_timeout"`
|
AfkTimeout int `json:"afk_timeout"`
|
||||||
|
VerificationLevel int `json:"verification_level"`
|
||||||
EmbedEnabled bool `json:"embed_enabled"`
|
EmbedEnabled bool `json:"embed_enabled"`
|
||||||
Large bool `json:"large"` // ??
|
Large bool `json:"large"` // ??
|
||||||
Roles []*Role `json:"roles"`
|
Roles []*Role `json:"roles"`
|
||||||
|
@ -168,6 +169,13 @@ type Guild struct {
|
||||||
VoiceStates []*VoiceState `json:"voice_states"`
|
VoiceStates []*VoiceState `json:"voice_states"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A GuildParams stores all the data needed to update discord guild settings
|
||||||
|
type GuildParams struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Region string `json:"region"`
|
||||||
|
VerificationLevel *int `json:"verification_level"`
|
||||||
|
}
|
||||||
|
|
||||||
// A Role stores information about Discord guild member roles.
|
// A Role stores information about Discord guild member roles.
|
||||||
type Role struct {
|
type Role struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
|
|
Loading…
Reference in a new issue