From cfe1ea5666db50ea84e14938c7331a2724c53ec7 Mon Sep 17 00:00:00 2001 From: mlnrDev Date: Fri, 17 May 2024 12:49:38 +0200 Subject: [PATCH 1/2] Add ButtonStylePremium --- discord/component.go | 26 ++++++++++++++++++++------ events/interaction_events.go | 3 +++ handler/interaction.go | 1 + 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/discord/component.go b/discord/component.go index b8c0dd3e..d93e1536 100644 --- a/discord/component.go +++ b/discord/component.go @@ -234,41 +234,48 @@ const ( ButtonStyleSuccess ButtonStyleDanger ButtonStyleLink + ButtonStylePremium ) // NewButton creates a new ButtonComponent with the provided parameters. Link ButtonComponent(s) need a URL and other ButtonComponent(s) need a customID -func NewButton(style ButtonStyle, label string, customID string, url string) ButtonComponent { +func NewButton(style ButtonStyle, label string, customID string, url string, skuID snowflake.ID) ButtonComponent { return ButtonComponent{ Style: style, CustomID: customID, URL: url, Label: label, + SkuID: skuID, } } // NewPrimaryButton creates a new ButtonComponent with ButtonStylePrimary & the provided parameters func NewPrimaryButton(label string, customID string) ButtonComponent { - return NewButton(ButtonStylePrimary, label, customID, "") + return NewButton(ButtonStylePrimary, label, customID, "", 0) } // NewSecondaryButton creates a new ButtonComponent with ButtonStyleSecondary & the provided parameters func NewSecondaryButton(label string, customID string) ButtonComponent { - return NewButton(ButtonStyleSecondary, label, customID, "") + return NewButton(ButtonStyleSecondary, label, customID, "", 0) } // NewSuccessButton creates a new ButtonComponent with ButtonStyleSuccess & the provided parameters func NewSuccessButton(label string, customID string) ButtonComponent { - return NewButton(ButtonStyleSuccess, label, customID, "") + return NewButton(ButtonStyleSuccess, label, customID, "", 0) } // NewDangerButton creates a new ButtonComponent with ButtonStyleDanger & the provided parameters func NewDangerButton(label string, customID string) ButtonComponent { - return NewButton(ButtonStyleDanger, label, customID, "") + return NewButton(ButtonStyleDanger, label, customID, "", 0) } // NewLinkButton creates a new link ButtonComponent with ButtonStyleLink & the provided parameters func NewLinkButton(label string, url string) ButtonComponent { - return NewButton(ButtonStyleLink, label, "", url) + return NewButton(ButtonStyleLink, label, "", url, 0) +} + +// NewPremiumButton creates a new ButtonComponent with ButtonStylePremium & the provided parameters +func NewPremiumButton(label string, skuID snowflake.ID) ButtonComponent { + return NewButton(ButtonStylePremium, label, "", "", skuID) } var ( @@ -281,6 +288,7 @@ type ButtonComponent struct { Label string `json:"label,omitempty"` Emoji *ComponentEmoji `json:"emoji,omitempty"` CustomID string `json:"custom_id,omitempty"` + SkuID snowflake.ID `json:"sku_id,omitempty"` URL string `json:"url,omitempty"` Disabled bool `json:"disabled,omitempty"` } @@ -342,6 +350,12 @@ func (c ButtonComponent) WithURL(url string) ButtonComponent { return c } +// WithSkuID returns a new ButtonComponent with the provided skuID +func (c ButtonComponent) WithSkuID(skuID snowflake.ID) ButtonComponent { + c.SkuID = skuID + return c +} + // AsEnabled returns a new ButtonComponent but enabled func (c ButtonComponent) AsEnabled() ButtonComponent { c.Disabled = false diff --git a/events/interaction_events.go b/events/interaction_events.go index 2f04e250..a53a6588 100644 --- a/events/interaction_events.go +++ b/events/interaction_events.go @@ -61,6 +61,7 @@ func (e *ApplicationCommandInteractionCreate) Modal(modalCreate discord.ModalCre return e.Respond(discord.InteractionResponseTypeModal, modalCreate, opts...) } +// Deprecated: Respond with a discord.ButtonStylePremium button instead. // PremiumRequired responds to the interaction with an upgrade button if available. func (e *ApplicationCommandInteractionCreate) PremiumRequired(opts ...rest.RequestOpt) error { return e.Respond(discord.InteractionResponseTypePremiumRequired, nil, opts...) @@ -112,6 +113,7 @@ func (e *ComponentInteractionCreate) Modal(modalCreate discord.ModalCreate, opts return e.Respond(discord.InteractionResponseTypeModal, modalCreate, opts...) } +// Deprecated: Respond with a discord.ButtonStylePremium button instead. // PremiumRequired responds to the interaction with an upgrade button if available. func (e *ComponentInteractionCreate) PremiumRequired(opts ...rest.RequestOpt) error { return e.Respond(discord.InteractionResponseTypePremiumRequired, nil, opts...) @@ -180,6 +182,7 @@ func (e *ModalSubmitInteractionCreate) DeferUpdateMessage(opts ...rest.RequestOp return e.Respond(discord.InteractionResponseTypeDeferredUpdateMessage, nil, opts...) } +// Deprecated: Respond with a discord.ButtonStylePremium button instead. // PremiumRequired responds to the interaction with an upgrade button if available. func (e *ModalSubmitInteractionCreate) PremiumRequired(opts ...rest.RequestOpt) error { return e.Respond(discord.InteractionResponseTypePremiumRequired, nil, opts...) diff --git a/handler/interaction.go b/handler/interaction.go index 745c037b..3d2c58f7 100644 --- a/handler/interaction.go +++ b/handler/interaction.go @@ -40,6 +40,7 @@ func (e *InteractionEvent) DeferUpdateMessage(opts ...rest.RequestOpt) error { return e.Respond(discord.InteractionResponseTypeDeferredUpdateMessage, nil, opts...) } +// Deprecated: Respond with a discord.ButtonStylePremium button instead. // PremiumRequired responds to the interaction with an upgrade button if available. func (e *InteractionEvent) PremiumRequired(opts ...rest.RequestOpt) error { return e.Respond(discord.InteractionResponseTypePremiumRequired, nil, opts...) From 0481fa7c137bbd0ea0af8894fdd852f409db6ff0 Mon Sep 17 00:00:00 2001 From: mlnrDev Date: Wed, 29 May 2024 19:04:28 +0200 Subject: [PATCH 2/2] remove label --- discord/component.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/discord/component.go b/discord/component.go index d93e1536..3dbd6551 100644 --- a/discord/component.go +++ b/discord/component.go @@ -274,8 +274,8 @@ func NewLinkButton(label string, url string) ButtonComponent { } // NewPremiumButton creates a new ButtonComponent with ButtonStylePremium & the provided parameters -func NewPremiumButton(label string, skuID snowflake.ID) ButtonComponent { - return NewButton(ButtonStylePremium, label, "", "", skuID) +func NewPremiumButton(skuID snowflake.ID) ButtonComponent { + return NewButton(ButtonStylePremium, "", "", "", skuID) } var (