From 22a6994c506e629e385ea7ffc1ae8a2a57a79408 Mon Sep 17 00:00:00 2001 From: mavolin <48887425+mavolin@users.noreply.github.com> Date: Sat, 16 May 2020 17:57:25 +0200 Subject: [PATCH] Discord: implement #74 --- api/guild.go | 30 ++++++++++++++++++------------ discord/guild.go | 7 +++++-- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/api/guild.go b/api/guild.go index 302e838..cf98753 100644 --- a/api/guild.go +++ b/api/guild.go @@ -376,28 +376,34 @@ func (c *Client) SyncIntegration(guildID, integrationID discord.Snowflake) error ) } -// GuildEmbed returns the guild embed object. +// GuildWidget returns the guild widget object. // // Requires the MANAGE_GUILD permission. -func (c *Client) GuildEmbed(guildID discord.Snowflake) (*discord.GuildEmbed, error) { - var ge *discord.GuildEmbed +func (c *Client) GuildWidget(guildID discord.Snowflake) (*discord.GuildWidget, error) { + var ge *discord.GuildWidget return ge, c.RequestJSON(&ge, "GET", EndpointGuilds+guildID.String()+"/embed") } // https://discord.com/developers/docs/resources/guild#guild-embed-object-guild-embed-structure -type ModifyGuildEmbedData struct { - Enabled option.Bool `json:"enabled,omitempty"` +type ModifyGuildWidgetData struct { + // Enabled specifies whether the widget is enabled. + Enabled option.Bool `json:"enabled,omitempty"` + // ChannelID is the widget channel id. ChannelID discord.Snowflake `json:"channel_id,omitempty"` } -// ModifyGuildEmbed modifies the guild embed and updates the passed in -// GuildEmbed data. +// ModifyGuildWidget modifies a guild widget object for the guild. // -// This method should be used with care: if you still want the embed enabled, -// you need to set the Enabled boolean, even if it's already enabled. If you -// don't, JSON will default it to false. -func (c *Client) ModifyGuildEmbed(guildID discord.Snowflake, data discord.GuildEmbed) error { - return c.RequestJSON(&data, "PATCH", EndpointGuilds+guildID.String()+"/embed") +// Requires the MANAGE_GUILD permission. +func (c *Client) ModifyGuildWidget( + guildID discord.Snowflake, data ModifyGuildWidgetData) (*discord.GuildWidget, error) { + + var w *discord.GuildWidget + return w, c.RequestJSON( + &w, "PATCH", + EndpointGuilds+guildID.String()+"/embed", + httputil.WithJSONBody(data), + ) } // GuildVanityURL returns *Invite for guilds that have that feature enabled, diff --git a/discord/guild.go b/discord/guild.go index ad176f7..1879c35 100644 --- a/discord/guild.go +++ b/discord/guild.go @@ -296,8 +296,11 @@ type Integration struct { SyncedAt Timestamp `json:"synced_at"` } -type GuildEmbed struct { - Enabled bool `json:"enabled"` +// https://discord.com/developers/docs/resources/guild#guild-widget-object +type GuildWidget struct { + // Enabled specifies whether the widget is enabled. + Enabled bool `json:"enabled"` + // ChannelID is the widget channel id. ChannelID Snowflake `json:"channel_id,omitempty"` }