Merge pull request #170 from iopred/develop
Add support for GuildEmbed and GuildIntegration endpoints.
This commit is contained in:
commit
0f3f965d88
4 changed files with 148 additions and 30 deletions
32
endpoints.go
32
endpoints.go
|
@ -55,21 +55,23 @@ var (
|
||||||
USER_DEVICES = func(uID string) string { return USERS + uID + "/devices" }
|
USER_DEVICES = func(uID string) string { return USERS + uID + "/devices" }
|
||||||
USER_CONNECTIONS = func(uID string) string { return USERS + uID + "/connections" }
|
USER_CONNECTIONS = func(uID string) string { return USERS + uID + "/connections" }
|
||||||
|
|
||||||
GUILD = func(gID string) string { return GUILDS + gID }
|
GUILD = func(gID string) string { return GUILDS + gID }
|
||||||
GUILD_INIVTES = func(gID string) string { return GUILDS + gID + "/invites" }
|
GUILD_INIVTES = func(gID string) string { return GUILDS + gID + "/invites" }
|
||||||
GUILD_CHANNELS = func(gID string) string { return GUILDS + gID + "/channels" }
|
GUILD_CHANNELS = func(gID string) string { return GUILDS + gID + "/channels" }
|
||||||
GUILD_MEMBERS = func(gID string) string { return GUILDS + gID + "/members" }
|
GUILD_MEMBERS = func(gID string) string { return GUILDS + gID + "/members" }
|
||||||
GUILD_MEMBER = func(gID, uID string) string { return GUILDS + gID + "/members/" + uID }
|
GUILD_MEMBER = func(gID, uID string) string { return GUILDS + gID + "/members/" + uID }
|
||||||
GUILD_BANS = func(gID string) string { return GUILDS + gID + "/bans" }
|
GUILD_BANS = func(gID string) string { return GUILDS + gID + "/bans" }
|
||||||
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_INTEGRATION = func(gID, iID string) string { return GUILDS + gID + "/integrations/" + iID }
|
||||||
GUILD_ROLE = func(gID, rID string) string { return GUILDS + gID + "/roles/" + rID }
|
GUILD_INTEGRATION_SYNC = func(gID, iID string) string { return GUILDS + gID + "/integrations/" + iID + "/sync" }
|
||||||
GUILD_INVITES = func(gID string) string { return GUILDS + gID + "/invites" }
|
GUILD_ROLES = func(gID string) string { return GUILDS + gID + "/roles" }
|
||||||
GUILD_EMBED = func(gID string) string { return GUILDS + gID + "/embed" }
|
GUILD_ROLE = func(gID, rID string) string { return GUILDS + gID + "/roles/" + rID }
|
||||||
GUILD_PRUNE = func(gID string) string { return GUILDS + gID + "/prune" }
|
GUILD_INVITES = func(gID string) string { return GUILDS + gID + "/invites" }
|
||||||
GUILD_ICON = func(gID, hash string) string { return GUILDS + gID + "/icons/" + hash + ".jpg" }
|
GUILD_EMBED = func(gID string) string { return GUILDS + gID + "/embed" }
|
||||||
GUILD_SPLASH = func(gID, hash string) string { return GUILDS + gID + "/splashes/" + hash + ".jpg" }
|
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 = func(cID string) string { return CHANNELS + cID }
|
||||||
CHANNEL_PERMISSIONS = func(cID string) string { return CHANNELS + cID + "/permissions" }
|
CHANNEL_PERMISSIONS = func(cID string) string { return CHANNELS + cID + "/permissions" }
|
||||||
|
|
30
message.go
30
message.go
|
@ -16,21 +16,21 @@ import (
|
||||||
|
|
||||||
// A Message stores all data related to a specific Discord message.
|
// A Message stores all data related to a specific Discord message.
|
||||||
type Message struct {
|
type Message struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
ChannelID string `json:"channel_id"`
|
ChannelID string `json:"channel_id"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
Timestamp string `json:"timestamp"`
|
Timestamp string `json:"timestamp"`
|
||||||
EditedTimestamp string `json:"edited_timestamp"`
|
EditedTimestamp string `json:"edited_timestamp"`
|
||||||
Tts bool `json:"tts"`
|
Tts bool `json:"tts"`
|
||||||
MentionEveryone bool `json:"mention_everyone"`
|
MentionEveryone bool `json:"mention_everyone"`
|
||||||
Author *User `json:"author"`
|
Author *User `json:"author"`
|
||||||
Attachments []*Attachment `json:"attachments"`
|
Attachments []*MessageAttachment `json:"attachments"`
|
||||||
Embeds []*Embed `json:"embeds"`
|
Embeds []*MessageEmbed `json:"embeds"`
|
||||||
Mentions []*User `json:"mentions"`
|
Mentions []*User `json:"mentions"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// An Attachment stores data for message attachments.
|
// A MessageAttachment stores data for message attachments.
|
||||||
type Attachment struct {
|
type MessageAttachment struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
ProxyURL string `json:"proxy_url"`
|
ProxyURL string `json:"proxy_url"`
|
||||||
|
@ -40,8 +40,8 @@ type Attachment struct {
|
||||||
Size int `json:"size"`
|
Size int `json:"size"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// An Embed stores data for message embeds.
|
// An MessageEmbed stores data for message embeds.
|
||||||
type Embed struct {
|
type MessageEmbed struct {
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
|
|
89
restapi.go
89
restapi.go
|
@ -761,6 +761,72 @@ func (s *Session) GuildRoleDelete(guildID, roleID string) (err error) {
|
||||||
return
|
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.
|
// GuildIcon returns an image.Image of a guild icon.
|
||||||
// guildID : The ID of a Guild.
|
// guildID : The ID of a Guild.
|
||||||
func (s *Session) GuildIcon(guildID string) (img image.Image, err error) {
|
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
|
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
|
// Functions specific to Discord Channels
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
|
27
structs.go
27
structs.go
|
@ -345,6 +345,33 @@ type GuildEmojisUpdate struct {
|
||||||
Emojis []*Emoji `json:"emojis"`
|
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.
|
// A UserGuildSettingsChannelOverride stores data for a channel override for a users guild settings.
|
||||||
type UserGuildSettingsChannelOverride struct {
|
type UserGuildSettingsChannelOverride struct {
|
||||||
Muted bool `json:"muted"`
|
Muted bool `json:"muted"`
|
||||||
|
|
Loading…
Reference in a new issue