From 1b990cd58de57ef4d8863a96d7c17121b79a3232 Mon Sep 17 00:00:00 2001 From: mavolin <48887425+mavolin@users.noreply.github.com> Date: Mon, 11 May 2020 01:45:44 +0200 Subject: [PATCH 1/2] Discord: add dedicated type for ExpireBehavior --- discord/guild.go | 4 ++-- discord/guild_const.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/discord/guild.go b/discord/guild.go index 63a8da8..bc7718a 100644 --- a/discord/guild.go +++ b/discord/guild.go @@ -167,8 +167,8 @@ type Integration struct { // used for subscribers RoleID Snowflake `json:"role_id"` - ExpireBehavior int `json:"expire_behavior"` - ExpireGracePeriod int `json:"expire_grace_period"` + ExpireBehavior ExpireBehavior `json:"expire_behavior"` + ExpireGracePeriod int `json:"expire_grace_period"` User User `json:"user"` Account struct { diff --git a/discord/guild_const.go b/discord/guild_const.go index c62537a..0eb8d0c 100644 --- a/discord/guild_const.go +++ b/discord/guild_const.go @@ -88,3 +88,13 @@ const ( Twitch Service = "twitch" YouTube Service = "youtube" ) + +// ExpireBehavior is the integration expire behavior that regulates what happens, if a subscriber expires. +type ExpireBehavior uint8 + +var ( + // RemoveRole removes the role of the subscriber. + RemoveRole ExpireBehavior = 0 + // Kick kicks the subscriber from the guild. + Kick ExpireBehavior = 1 +) From 984c8f0239d79ff1d56a04c3e83f9f61e039fc24 Mon Sep 17 00:00:00 2001 From: mavolin <48887425+mavolin@users.noreply.github.com> Date: Mon, 11 May 2020 01:48:26 +0200 Subject: [PATCH 2/2] API: fix #35 --- api/guild.go | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/api/guild.go b/api/guild.go index 1bee6fc..aea165b 100644 --- a/api/guild.go +++ b/api/guild.go @@ -233,25 +233,18 @@ func (c *Client) AttachIntegration( ) } +// https://discord.com/developers/docs/resources/guild#modify-guild-integration-json-params +type ModifyIntegrationData struct { + ExpireBehavior *discord.ExpireBehavior `json:"expire_behavior"` + ExpireGracePeriod json.OptionInt `json:"expire_grace_period"` + EnableEmoticons json.OptionBool `json:"enable_emoticons"` // limited to twitch +} + // ModifyIntegration requires MANAGE_GUILD. -func (c *Client) ModifyIntegration( - guildID, integrationID discord.Snowflake, - expireBehavior, expireGracePeriod int, emoticons bool) error { - - var param struct { - ExpireBehavior int `json:"expire_behavior"` - ExpireGracePeriod int `json:"expire_grace_period"` - EnableEmoticons bool `json:"enable_emoticons"` - } - - param.ExpireBehavior = expireBehavior - param.ExpireGracePeriod = expireGracePeriod - param.EnableEmoticons = emoticons - +func (c *Client) ModifyIntegration(guildID, integrationID discord.Snowflake, data ModifyIntegrationData) error { return c.FastRequest( - "PATCH", - EndpointGuilds+guildID.String()+"/integrations/"+integrationID.String(), - httputil.WithSchema(c, param), + "PATCH", EndpointGuilds+guildID.String()+"/integrations/"+integrationID.String(), + httputil.WithJSONBody(data), ) }