Skip to content

Commit

Permalink
Add ButtonStylePremium (#359)
Browse files Browse the repository at this point in the history
* Add ButtonStylePremium

* remove label
  • Loading branch information
sebm253 authored Jun 17, 2024
1 parent 7380d44 commit 44021d1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
19 changes: 18 additions & 1 deletion discord/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,17 @@ 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,
}
}

Expand Down Expand Up @@ -291,6 +293,14 @@ func NewLinkButton(label string, url string) ButtonComponent {
}
}

// NewPremiumButton creates a new ButtonComponent with ButtonStylePremium & the provided parameters
func NewPremiumButton(skuID snowflake.ID) ButtonComponent {
return ButtonComponent{
Style: ButtonStylePremium,
SkuID: skuID,
}
}

var (
_ Component = (*ButtonComponent)(nil)
_ InteractiveComponent = (*ButtonComponent)(nil)
Expand All @@ -301,6 +311,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"`
}
Expand Down Expand Up @@ -362,6 +373,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
Expand Down
3 changes: 3 additions & 0 deletions events/interaction_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down Expand Up @@ -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...)
Expand Down Expand Up @@ -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...)
Expand Down
1 change: 1 addition & 0 deletions handler/interaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down

0 comments on commit 44021d1

Please sign in to comment.