Add support for GuildEmbed and GuildIntegration endpoints.

This commit is contained in:
Chris Rhodes 2016-04-22 11:34:04 -07:00
parent b141b68b1f
commit 24e7f04e0e
4 changed files with 148 additions and 30 deletions

View file

@ -55,21 +55,23 @@ var (
USER_DEVICES = func(uID string) string { return USERS + uID + "/devices" }
USER_CONNECTIONS = func(uID string) string { return USERS + uID + "/connections" }
GUILD = func(gID string) string { return GUILDS + gID }
GUILD_INIVTES = func(gID string) string { return GUILDS + gID + "/invites" }
GUILD_CHANNELS = func(gID string) string { return GUILDS + gID + "/channels" }
GUILD_MEMBERS = func(gID string) string { return GUILDS + gID + "/members" }
GUILD_MEMBER = func(gID, uID string) string { return GUILDS + gID + "/members/" + uID }
GUILD_BANS = func(gID string) string { return GUILDS + gID + "/bans" }
GUILD_BAN = func(gID, uID string) string { return GUILDS + gID + "/bans/" + uID }
GUILD_INTEGRATIONS = func(gID string) string { return GUILDS + gID + "/integrations" }
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_EMBED = func(gID string) string { return GUILDS + gID + "/embed" }
GUILD_PRUNE = func(gID string) string { return GUILDS + gID + "/prune" }
GUILD_ICON = func(gID, hash string) string { return GUILDS + gID + "/icons/" + hash + ".jpg" }
GUILD_SPLASH = func(gID, hash string) string { return GUILDS + gID + "/splashes/" + hash + ".jpg" }
GUILD = func(gID string) string { return GUILDS + gID }
GUILD_INIVTES = func(gID string) string { return GUILDS + gID + "/invites" }
GUILD_CHANNELS = func(gID string) string { return GUILDS + gID + "/channels" }
GUILD_MEMBERS = func(gID string) string { return GUILDS + gID + "/members" }
GUILD_MEMBER = func(gID, uID string) string { return GUILDS + gID + "/members/" + uID }
GUILD_BANS = func(gID string) string { return GUILDS + gID + "/bans" }
GUILD_BAN = func(gID, uID string) string { return GUILDS + gID + "/bans/" + uID }
GUILD_INTEGRATIONS = func(gID string) string { return GUILDS + gID + "/integrations" }
GUILD_INTEGRATION = func(gID, iID string) string { return GUILDS + gID + "/integrations/" + iID }
GUILD_INTEGRATION_SYNC = func(gID, iID string) string { return GUILDS + gID + "/integrations/" + iID + "/sync" }
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_EMBED = func(gID string) string { return GUILDS + gID + "/embed" }
GUILD_PRUNE = func(gID string) string { return GUILDS + gID + "/prune" }
GUILD_ICON = func(gID, hash string) string { return GUILDS + gID + "/icons/" + hash + ".jpg" }
GUILD_SPLASH = func(gID, hash string) string { return GUILDS + gID + "/splashes/" + hash + ".jpg" }
CHANNEL = func(cID string) string { return CHANNELS + cID }
CHANNEL_PERMISSIONS = func(cID string) string { return CHANNELS + cID + "/permissions" }

View file

@ -16,21 +16,21 @@ import (
// A Message stores all data related to a specific Discord message.
type Message struct {
ID string `json:"id"`
ChannelID string `json:"channel_id"`
Content string `json:"content"`
Timestamp string `json:"timestamp"`
EditedTimestamp string `json:"edited_timestamp"`
Tts bool `json:"tts"`
MentionEveryone bool `json:"mention_everyone"`
Author *User `json:"author"`
Attachments []*Attachment `json:"attachments"`
Embeds []*Embed `json:"embeds"`
Mentions []*User `json:"mentions"`
ID string `json:"id"`
ChannelID string `json:"channel_id"`
Content string `json:"content"`
Timestamp string `json:"timestamp"`
EditedTimestamp string `json:"edited_timestamp"`
Tts bool `json:"tts"`
MentionEveryone bool `json:"mention_everyone"`
Author *User `json:"author"`
Attachments []*MessageAttachment `json:"attachments"`
Embeds []*MessageEmbed `json:"embeds"`
Mentions []*User `json:"mentions"`
}
// An Attachment stores data for message attachments.
type Attachment struct {
// A MessageAttachment stores data for message attachments.
type MessageAttachment struct {
ID string `json:"id"`
URL string `json:"url"`
ProxyURL string `json:"proxy_url"`
@ -40,8 +40,8 @@ type Attachment struct {
Size int `json:"size"`
}
// An Embed stores data for message embeds.
type Embed struct {
// An MessageEmbed stores data for message embeds.
type MessageEmbed struct {
URL string `json:"url"`
Type string `json:"type"`
Title string `json:"title"`

View file

@ -761,6 +761,72 @@ func (s *Session) GuildRoleDelete(guildID, roleID string) (err error) {
return
}
// GuildIntegrations returns an array of Integrations for a guild.
// guildID : The ID of a Guild.
func (s *Session) GuildIntegrations(guildID string) (st []*GuildIntegration, err error) {
body, err := s.Request("GET", GUILD_INTEGRATIONS(guildID), nil)
if err != nil {
return
}
err = unmarshal(body, &st)
return
}
// GuildIntegrationCreate creates a Guild Integration.
// guildID : The ID of a Guild.
// integrationType : The Integration type.
// integrationID : The ID of an integration.
func (s *Session) GuildIntegrationCreate(guildID, integrationType, integrationID string) (err error) {
data := struct {
Type string `json:"type"`
Id string `json:"id"`
}{integrationType, integrationID}
_, err = s.Request("POST", GUILD_INTEGRATIONS(guildID), data)
return
}
// GuildIntegrationEdit edits a Guild Integration.
// guildID : The ID of a Guild.
// integrationType : The Integration type.
// integrationID : The ID of an integration.
// expireBehavior : The behavior when an integration subscription lapses (see the integration object documentation).
// expireGracePeriod : Period (in seconds) where the integration will ignore lapsed subscriptions.
// enableEmoticons : Whether emoticons should be synced for this integration (twitch only currently).
func (s *Session) GuildIntegrationEdit(guildID, integrationID string, expireBehavior, expireGracePeriod int, enableEmoticons bool) (err error) {
data := struct {
ExpireBehavior int `json:"expire_behavior"`
ExpireGracePeriod int `json:"expire_grace_period"`
EnableEmoticons bool `json:"enable_emoticons"`
}{expireBehavior, expireGracePeriod, enableEmoticons}
_, err = s.Request("PATCH", GUILD_INTEGRATION(guildID, integrationID), data)
return
}
// GuildIntegrationDelete removes the given integration from the Guild.
// guildID : The ID of a Guild.
// integrationID : The ID of an integration.
func (s *Session) GuildIntegrationDelete(guildID, integrationID string) (err error) {
_, err = s.Request("DELETE", GUILD_INTEGRATION(guildID, integrationID), nil)
return
}
// GuildIntegrationSync syncs an integration.
// guildID : The ID of a Guild.
// integrationID : The ID of an integration.
func (s *Session) GuildIntegrationSync(guildID, integrationID string) (err error) {
_, err = s.Request("POST", GUILD_INTEGRATION_SYNC(guildID, integrationID), nil)
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) {
@ -805,6 +871,29 @@ func (s *Session) GuildSplash(guildID string) (img image.Image, err error) {
return
}
// GuildEmbed returns the embed for a Guild.
// guildID : The ID of a Guild.
func (s *Session) GuildEmbed(guildID string) (st *GuildEmbed, err error) {
body, err := s.Request("GET", GUILD_EMBED(guildID), nil)
if err != nil {
return
}
err = unmarshal(body, &st)
return
}
// GuildEmbedEdit returns the embed for a Guild.
// guildID : The ID of a Guild.
func (s *Session) GuildEmbedEdit(guildID string, enabled bool, channelID string) (err error) {
data := GuildEmbed{enabled, channelID}
_, err = s.Request("PATCH", GUILD_EMBED(guildID), data)
return
}
// ------------------------------------------------------------------------------------------------
// Functions specific to Discord Channels
// ------------------------------------------------------------------------------------------------

View file

@ -345,6 +345,33 @@ type GuildEmojisUpdate struct {
Emojis []*Emoji `json:"emojis"`
}
// A GuildIntegration stores data for a guild integration.
type GuildIntegration struct {
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Enabled bool `json:"enabled"`
Syncing bool `json:"syncing"`
RoleID string `json:"role_id"`
ExpireBehavior int `json:"expire_behavior"`
ExpireGracePeriod int `json:"expire_grace_period"`
User *User `json:"user"`
Account *GuildIntegrationAccount `json:"account"`
SyncedAt int `json:"synced_at"`
}
// A GuildIntegrationAccount stores data for a guild integration account.
type GuildIntegrationAccount struct {
ID string `json:"id"`
Name string `json:"name"`
}
// A GuildEmbed stores data for a guild embed.
type GuildEmbed struct {
Enabled bool `json:"enabled"`
ChannelID string `json:"channel_id"`
}
// A UserGuildSettingsChannelOverride stores data for a channel override for a users guild settings.
type UserGuildSettingsChannelOverride struct {
Muted bool `json:"muted"`