Skip to content

Commit

Permalink
Add ButtonStylePremium
Browse files Browse the repository at this point in the history
  • Loading branch information
mlnrDev committed May 17, 2024
1 parent d934f63 commit cfe1ea5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
26 changes: 20 additions & 6 deletions discord/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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"`
}
Expand Down Expand Up @@ -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
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 cfe1ea5

Please sign in to comment.