forked from pothtonswer/discordmuffin
Merge pull request #132 from nstafie/develop
BREAKING -- Add support for setting guild region and verification level
This commit is contained in:
commit
226df093f6
2 changed files with 61 additions and 23 deletions
40
restapi.go
40
restapi.go
|
@ -371,14 +371,44 @@ 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)
|
// g : A GuildParams struct with the values Name, Region and VerificationLevel defined.
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
44
structs.go
44
structs.go
|
@ -148,24 +148,32 @@ type Emoji struct {
|
||||||
// A Guild holds all data related to a specific Discord Guild. Guilds are also
|
// A Guild holds all data related to a specific Discord Guild. Guilds are also
|
||||||
// sometimes referred to as Servers in the Discord client.
|
// sometimes referred to as Servers in the Discord client.
|
||||||
type Guild struct {
|
type Guild struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Icon string `json:"icon"`
|
Icon string `json:"icon"`
|
||||||
Region string `json:"region"`
|
Region string `json:"region"`
|
||||||
AfkChannelID string `json:"afk_channel_id"`
|
AfkChannelID string `json:"afk_channel_id"`
|
||||||
EmbedChannelID string `json:"embed_channel_id"`
|
EmbedChannelID string `json:"embed_channel_id"`
|
||||||
OwnerID string `json:"owner_id"`
|
OwnerID string `json:"owner_id"`
|
||||||
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"`
|
||||||
EmbedEnabled bool `json:"embed_enabled"`
|
VerificationLevel int `json:"verification_level"`
|
||||||
Large bool `json:"large"` // ??
|
EmbedEnabled bool `json:"embed_enabled"`
|
||||||
Roles []*Role `json:"roles"`
|
Large bool `json:"large"` // ??
|
||||||
Emojis []*Emoji `json:"emojis"`
|
Roles []*Role `json:"roles"`
|
||||||
Members []*Member `json:"members"`
|
Emojis []*Emoji `json:"emojis"`
|
||||||
Presences []*Presence `json:"presences"`
|
Members []*Member `json:"members"`
|
||||||
Channels []*Channel `json:"channels"`
|
Presences []*Presence `json:"presences"`
|
||||||
VoiceStates []*VoiceState `json:"voice_states"`
|
Channels []*Channel `json:"channels"`
|
||||||
|
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.
|
||||||
|
|
Loading…
Reference in a new issue