Discord: implement #74

This commit is contained in:
mavolin 2020-05-16 17:57:25 +02:00
parent 1df6bf61fc
commit 22a6994c50
No known key found for this signature in database
GPG Key ID: D8681218EDF216DF
2 changed files with 23 additions and 14 deletions

View File

@ -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. // Requires the MANAGE_GUILD permission.
func (c *Client) GuildEmbed(guildID discord.Snowflake) (*discord.GuildEmbed, error) { func (c *Client) GuildWidget(guildID discord.Snowflake) (*discord.GuildWidget, error) {
var ge *discord.GuildEmbed var ge *discord.GuildWidget
return ge, c.RequestJSON(&ge, "GET", EndpointGuilds+guildID.String()+"/embed") return ge, c.RequestJSON(&ge, "GET", EndpointGuilds+guildID.String()+"/embed")
} }
// https://discord.com/developers/docs/resources/guild#guild-embed-object-guild-embed-structure // https://discord.com/developers/docs/resources/guild#guild-embed-object-guild-embed-structure
type ModifyGuildEmbedData struct { type ModifyGuildWidgetData struct {
Enabled option.Bool `json:"enabled,omitempty"` // 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"` ChannelID discord.Snowflake `json:"channel_id,omitempty"`
} }
// ModifyGuildEmbed modifies the guild embed and updates the passed in // ModifyGuildWidget modifies a guild widget object for the guild.
// GuildEmbed data.
// //
// This method should be used with care: if you still want the embed enabled, // Requires the MANAGE_GUILD permission.
// you need to set the Enabled boolean, even if it's already enabled. If you func (c *Client) ModifyGuildWidget(
// don't, JSON will default it to false. guildID discord.Snowflake, data ModifyGuildWidgetData) (*discord.GuildWidget, error) {
func (c *Client) ModifyGuildEmbed(guildID discord.Snowflake, data discord.GuildEmbed) error {
return c.RequestJSON(&data, "PATCH", EndpointGuilds+guildID.String()+"/embed") 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, // GuildVanityURL returns *Invite for guilds that have that feature enabled,

View File

@ -296,8 +296,11 @@ type Integration struct {
SyncedAt Timestamp `json:"synced_at"` SyncedAt Timestamp `json:"synced_at"`
} }
type GuildEmbed struct { // https://discord.com/developers/docs/resources/guild#guild-widget-object
Enabled bool `json:"enabled"` 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"` ChannelID Snowflake `json:"channel_id,omitempty"`
} }