Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ButtonStylePremium #359

Merged
merged 3 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading