forked from pothtonswer/discordmuffin
Add methods for grabbing guild images. Clean up some docs.
This commit is contained in:
parent
1c00077923
commit
b4dfce0fee
2 changed files with 68 additions and 7 deletions
68
restapi.go
68
restapi.go
|
@ -218,10 +218,9 @@ func (s *Session) User(userID string) (st *User, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// UserAvatar returns an image.Image of a users Avatar
|
// UserAvatar returns an image.Image of a users Avatar.
|
||||||
// userID : A user ID or "@me" which is a shortcut of current user ID
|
// userID : A user ID or "@me" which is a shortcut of current user ID
|
||||||
func (s *Session) UserAvatar(userID string) (img image.Image, err error) {
|
func (s *Session) UserAvatar(userID string) (img image.Image, err error) {
|
||||||
|
|
||||||
u, err := s.User(userID)
|
u, err := s.User(userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -322,6 +321,11 @@ func (s *Session) UserGuilds() (st []*Guild, err error) {
|
||||||
// Guild returns a Guild structure of a specific Guild.
|
// Guild returns a Guild structure of a specific Guild.
|
||||||
// guildID : The ID of a Guild
|
// guildID : The ID of a Guild
|
||||||
func (s *Session) Guild(guildID string) (st *Guild, err error) {
|
func (s *Session) Guild(guildID string) (st *Guild, err error) {
|
||||||
|
// Attempt to grab the guild from State first.
|
||||||
|
st, err = s.State.Guild(guildID)
|
||||||
|
if err == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
body, err := s.Request("GET", GUILD(guildID), nil)
|
body, err := s.Request("GET", GUILD(guildID), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -499,6 +503,7 @@ func (s *Session) GuildInviteCreate(guildID string, i *Invite) (st *Invite, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// GuildRoles returns all roles for a given guild.
|
// GuildRoles returns all roles for a given guild.
|
||||||
|
// guildID : The ID of a Guild.
|
||||||
func (s *Session) GuildRoles(guildID string) (st []*Role, err error) {
|
func (s *Session) GuildRoles(guildID string) (st []*Role, err error) {
|
||||||
|
|
||||||
body, err := s.Request("GET", GUILD_ROLES(guildID), nil)
|
body, err := s.Request("GET", GUILD_ROLES(guildID), nil)
|
||||||
|
@ -511,7 +516,8 @@ func (s *Session) GuildRoles(guildID string) (st []*Role, err error) {
|
||||||
return // TODO return pointer
|
return // TODO return pointer
|
||||||
}
|
}
|
||||||
|
|
||||||
// GuildRoleCreate returns a new Guild Role
|
// GuildRoleCreate returns a new Guild Role.
|
||||||
|
// guildID: The ID of a Guild.
|
||||||
func (s *Session) GuildRoleCreate(guildID string) (st *Role, err error) {
|
func (s *Session) GuildRoleCreate(guildID string) (st *Role, err error) {
|
||||||
|
|
||||||
body, err := s.Request("POST", GUILD_ROLES(guildID), nil)
|
body, err := s.Request("POST", GUILD_ROLES(guildID), nil)
|
||||||
|
@ -525,6 +531,12 @@ func (s *Session) GuildRoleCreate(guildID string) (st *Role, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GuildRoleEdit updates an existing Guild Role with new values
|
// GuildRoleEdit updates an existing Guild Role with new values
|
||||||
|
// guildID : The ID of a Guild.
|
||||||
|
// roleID : The ID of a Role.
|
||||||
|
// name : The name of the Role.
|
||||||
|
// color : The color of the role (decimal, not hex).
|
||||||
|
// hoist : Whether to display the role's users separately.
|
||||||
|
// perm : The permissions for the role.
|
||||||
func (s *Session) GuildRoleEdit(guildID, roleID, name string, color int, hoist bool, perm int) (st *Role, err error) {
|
func (s *Session) GuildRoleEdit(guildID, roleID, name string, color int, hoist bool, perm int) (st *Role, err error) {
|
||||||
|
|
||||||
data := struct {
|
data := struct {
|
||||||
|
@ -545,7 +557,9 @@ func (s *Session) GuildRoleEdit(guildID, roleID, name string, color int, hoist b
|
||||||
}
|
}
|
||||||
|
|
||||||
// GuildRoleReorder reoders guild roles
|
// GuildRoleReorder reoders guild roles
|
||||||
func (s *Session) GuildRoleReorder(guildID string, roles []Role) (st []*Role, err error) {
|
// guildID : The ID of a Guild.
|
||||||
|
// roles : A list of ordered roles.
|
||||||
|
func (s *Session) GuildRoleReorder(guildID string, roles []*Role) (st []*Role, err error) {
|
||||||
|
|
||||||
body, err := s.Request("PATCH", GUILD_ROLES(guildID), roles)
|
body, err := s.Request("PATCH", GUILD_ROLES(guildID), roles)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -558,6 +572,8 @@ func (s *Session) GuildRoleReorder(guildID string, roles []Role) (st []*Role, er
|
||||||
}
|
}
|
||||||
|
|
||||||
// GuildRoleDelete deletes an existing role.
|
// GuildRoleDelete deletes an existing role.
|
||||||
|
// guildID : The ID of a Guild.
|
||||||
|
// roleID : The ID of a Role.
|
||||||
func (s *Session) GuildRoleDelete(guildID, roleID string) (err error) {
|
func (s *Session) GuildRoleDelete(guildID, roleID string) (err error) {
|
||||||
|
|
||||||
_, err = s.Request("DELETE", GUILD_ROLE(guildID, roleID), nil)
|
_, err = s.Request("DELETE", GUILD_ROLE(guildID, roleID), nil)
|
||||||
|
@ -565,6 +581,50 @@ func (s *Session) GuildRoleDelete(guildID, roleID string) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GuildIcon returns an image.Image of a guild icon.
|
||||||
|
// guildID : The ID of a Guild.
|
||||||
|
func (s *Session) GuildIcon(guildID string) (img image.Image, err error) {
|
||||||
|
g, err := s.Guild(guildID)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if g.Icon == "" {
|
||||||
|
err = errors.New("Guild does not have an icon set.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
body, err := s.Request("GET", GUILD_ICON(guildID, g.Icon), nil)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
img, _, err = image.Decode(bytes.NewReader(body))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// GuildSplash returns an image.Image of a guild splash image.
|
||||||
|
// guildID : The ID of a Guild.
|
||||||
|
func (s *Session) GuildSplash(guildID string) (img image.Image, err error) {
|
||||||
|
g, err := s.Guild(guildID)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if g.Splash == "" {
|
||||||
|
err = errors.New("Guild does not have a splash set.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
body, err := s.Request("GET", GUILD_SPLASH(guildID, g.Splash), nil)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
img, _, err = image.Decode(bytes.NewReader(body))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Functions specific to Discord Channels
|
// Functions specific to Discord Channels
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -170,6 +170,7 @@ type Guild struct {
|
||||||
OwnerID string `json:"owner_id"`
|
OwnerID string `json:"owner_id"`
|
||||||
Large bool `json:"large"` // ??
|
Large bool `json:"large"` // ??
|
||||||
JoinedAt string `json:"joined_at"` // make this a timestamp
|
JoinedAt string `json:"joined_at"` // make this a timestamp
|
||||||
|
Splash string `json:"splash"`
|
||||||
Roles []*Role `json:"roles"`
|
Roles []*Role `json:"roles"`
|
||||||
Emojis []*Emoji `json:"emojis"`
|
Emojis []*Emoji `json:"emojis"`
|
||||||
Members []*Member `json:"members"`
|
Members []*Member `json:"members"`
|
||||||
|
@ -269,9 +270,9 @@ type Ready struct {
|
||||||
SessionID string `json:"session_id"`
|
SessionID string `json:"session_id"`
|
||||||
HeartbeatInterval time.Duration `json:"heartbeat_interval"`
|
HeartbeatInterval time.Duration `json:"heartbeat_interval"`
|
||||||
User *User `json:"user"`
|
User *User `json:"user"`
|
||||||
ReadState []*ReadState
|
ReadState []*ReadState `json:"read_state"`
|
||||||
PrivateChannels []*Channel `json:"private_channels"`
|
PrivateChannels []*Channel `json:"private_channels"`
|
||||||
Guilds []*Guild `json:"guilds"`
|
Guilds []*Guild `json:"guilds"`
|
||||||
}
|
}
|
||||||
type RateLimit struct {
|
type RateLimit struct {
|
||||||
Bucket string `json:"bucket"`
|
Bucket string `json:"bucket"`
|
||||||
|
|
Loading…
Reference in a new issue