From 321f55e1390ef72f38c47b5d5bfed99e2fc4fdd8 Mon Sep 17 00:00:00 2001 From: Josh Perez Date: Thu, 13 Jun 2024 15:46:01 -0400 Subject: [PATCH] feat: add ButtonStyleTypes.Premium (#55) Co-authored-by: Justin Beckwith --- src/components.ts | 55 +++++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/src/components.ts b/src/components.ts index b526cf7..a45c25a 100644 --- a/src/components.ts +++ b/src/components.ts @@ -15,33 +15,50 @@ export enum MessageComponentTypes { export type MessageComponent = Button | ActionRow | StringSelect | InputText; -/** - * Button component - * @see {@link https://discord.com/developers/docs/interactions/message-components#button-object-button-structure} - */ -export type Button = { - type: MessageComponentTypes.BUTTON; - style: - | ButtonStyleTypes.PRIMARY - | ButtonStyleTypes.SECONDARY - | ButtonStyleTypes.SUCCESS - | ButtonStyleTypes.DANGER - | ButtonStyleTypes.LINK; - label: string; - emoji?: Pick; - custom_id?: string; - url?: string; - disabled?: boolean; -}; - export enum ButtonStyleTypes { PRIMARY = 1, SECONDARY = 2, SUCCESS = 3, DANGER = 4, LINK = 5, + PREMIUM = 6, +} + +interface BaseButton { + disabled?: boolean; + type: MessageComponentTypes.BUTTON; +} + +interface LabeledButton extends BaseButton { + emoji?: Pick; + label: string; +} + +interface PremiumButton extends BaseButton { + sku_id: string; + style: ButtonStyleTypes.PREMIUM; } +interface LinkButton extends LabeledButton { + url: string; + style: ButtonStyleTypes.LINK; +} + +interface CustomButton extends LabeledButton { + custom_id: string; + style: + | ButtonStyleTypes.PRIMARY + | ButtonStyleTypes.SECONDARY + | ButtonStyleTypes.SUCCESS + | ButtonStyleTypes.DANGER; +} + +/** + * Button component + * @see {@link https://discord.com/developers/docs/interactions/message-components#button-object-button-structure} + */ +export type Button = CustomButton | LinkButton | PremiumButton; + /** * Action row component * @see {@link https://discord.com/developers/docs/interactions/message-components#action-rows}