Added support functions for guild role fetching and management, closes #21

This commit is contained in:
Bruce Marriner 2015-12-23 20:09:16 -06:00
parent ff03e10888
commit dfb0b891fd
2 changed files with 52 additions and 0 deletions

View file

@ -61,6 +61,7 @@ var (
GUILD_BAN = func(gID, uID string) string { return GUILDS + gID + "/bans/" + uID } GUILD_BAN = func(gID, uID string) string { return GUILDS + gID + "/bans/" + uID }
GUILD_INTEGRATIONS = func(gID string) string { return GUILDS + gID + "/integrations" } GUILD_INTEGRATIONS = func(gID string) string { return GUILDS + gID + "/integrations" }
GUILD_ROLES = func(gID string) string { return GUILDS + gID + "/roles" } GUILD_ROLES = func(gID string) string { return GUILDS + gID + "/roles" }
GUILD_ROLE = func(gID, rID string) string { return GUILDS + gID + "/roles/" + rID }
GUILD_INVITES = func(gID string) string { return GUILDS + gID + "/invites" } GUILD_INVITES = func(gID string) string { return GUILDS + gID + "/invites" }
GUILD_EMBED = func(gID string) string { return GUILDS + gID + "/embed" } GUILD_EMBED = func(gID string) string { return GUILDS + gID + "/embed" }
GUILD_PRUNE = func(gID string) string { return GUILDS + gID + "/prune" } GUILD_PRUNE = func(gID string) string { return GUILDS + gID + "/prune" }

View file

@ -356,6 +356,57 @@ func (s *Session) GuildInviteCreate(guildID string, i Invite) (st Invite, err er
return return
} }
// GuildRoles returns all roles for a given guild.
func (s *Session) GuildRoles(guildID string) (st []Role, err error) {
body, err := s.Request("GET", GUILD_ROLES(guildID), nil)
err = json.Unmarshal(body, &st)
return // TODO return pointer
}
// GuildRoleCreate returns a new Guild Role
func (s *Session) GuildRoleCreate(guildID string) (st Role, err error) {
body, err := s.Request("POST", GUILD_ROLES(guildID), nil)
err = json.Unmarshal(body, &st)
return
}
// GuildRoleEdit updates an existing Guild Role with new values
func (s *Session) GuildRoleEdit(guildID, roleID, name string, color int, hoist bool, perm int) (st Role, err error) {
data := struct {
Name string `json:"name"` // The color the role should have (as a decimal, not hex)
Color int `json:"color"` // Whether to display the role's users separately
Hoist bool `json:"hoist"` // The role's name (overwrites existing)
Permissions int `json:"permissions"` // The overall permissions number of the role (overwrites existing)
}{name, color, hoist, perm}
body, err := s.Request("PATCH", GUILD_ROLE(guildID, roleID), data)
err = json.Unmarshal(body, &st)
return
}
// GuildRoleReorder reoders guild roles
func (s *Session) GuildRoleReorder(guildID string, roles []Role) (st []Role, err error) {
body, err := s.Request("PATCH", GUILD_ROLES(guildID), roles)
err = json.Unmarshal(body, &st)
return
}
// GuildRoleDelete deletes an existing role.
func (s *Session) GuildRoleDelete(guildID, roleID string) (err error) {
_, err = s.Request("DELETE", GUILD_ROLE(guildID, roleID), nil)
return
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Functions specific to Discord Channels // Functions specific to Discord Channels
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------