From 19efe052e339c10798e9c045005547bf9ca67de4 Mon Sep 17 00:00:00 2001 From: MCausc78 Date: Tue, 18 Jun 2024 23:00:14 +0300 Subject: [PATCH] Add `ButtonStyle.premium` and deprecate `InteractionCallbackType.premiumRequired` (#660) --- lib/src/builders/interaction_response.dart | 2 ++ lib/src/builders/message/component.dart | 12 ++++++++++++ lib/src/http/managers/message_manager.dart | 1 + lib/src/models/message/component.dart | 7 ++++++- 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/src/builders/interaction_response.dart b/lib/src/builders/interaction_response.dart index 7771cf612..f5501380a 100644 --- a/lib/src/builders/interaction_response.dart +++ b/lib/src/builders/interaction_response.dart @@ -54,6 +54,7 @@ class InteractionResponseBuilder extends CreateBuilder InteractionResponseBuilder(type: InteractionCallbackType.modal, data: modal); + @Deprecated('Respond with ButtonStyle.premium button instead') factory InteractionResponseBuilder.premiumRequired() => InteractionResponseBuilder(type: InteractionCallbackType.premiumRequired, data: null); @override @@ -111,6 +112,7 @@ enum InteractionCallbackType { updateMessage._(7), applicationCommandAutocompleteResult._(8), modal._(9), + @Deprecated('Respond with ButtonStyle.premium button instead') premiumRequired._(10); final int value; diff --git a/lib/src/builders/message/component.dart b/lib/src/builders/message/component.dart index 62c2b34c7..6a99723a5 100644 --- a/lib/src/builders/message/component.dart +++ b/lib/src/builders/message/component.dart @@ -38,6 +38,8 @@ class ButtonBuilder extends MessageComponentBuilder { String? customId; + Snowflake? skuId; + Uri? url; bool? isDisabled; @@ -47,6 +49,7 @@ class ButtonBuilder extends MessageComponentBuilder { this.label, this.emoji, this.customId, + this.skuId, this.url, this.isDisabled, }) : super(type: MessageComponentType.button); @@ -91,6 +94,14 @@ class ButtonBuilder extends MessageComponentBuilder { }) : style = ButtonStyle.link, super(type: MessageComponentType.button); + ButtonBuilder.premium({ + this.label, + this.emoji, + required Snowflake this.skuId, + this.isDisabled, + }) : style = ButtonStyle.premium, + super(type: MessageComponentType.button); + @override Map build() => { ...super.build(), @@ -103,6 +114,7 @@ class ButtonBuilder extends MessageComponentBuilder { if (emoji is GuildEmoji) 'animated': (emoji as GuildEmoji).isAnimated == true, }, if (customId != null) 'custom_id': customId, + if (skuId != null) 'sku_id': skuId.toString(), if (url != null) 'url': url!.toString(), if (isDisabled != null) 'disabled': isDisabled, }; diff --git a/lib/src/http/managers/message_manager.dart b/lib/src/http/managers/message_manager.dart index c151f98b6..a86788d37 100644 --- a/lib/src/http/managers/message_manager.dart +++ b/lib/src/http/managers/message_manager.dart @@ -256,6 +256,7 @@ class MessageManager extends Manager { label: raw['label'] as String?, emoji: maybeParse(raw['emoji'], client.guilds[Snowflake.zero].emojis.parse), customId: raw['custom_id'] as String?, + skuId: maybeParse(raw['sku_id'], Snowflake.parse), url: maybeParse(raw['url'], Uri.parse), isDisabled: raw['disabled'] as bool?, ), diff --git a/lib/src/models/message/component.dart b/lib/src/models/message/component.dart index cffeaa29b..2cf556af1 100644 --- a/lib/src/models/message/component.dart +++ b/lib/src/models/message/component.dart @@ -67,6 +67,9 @@ class ButtonComponent extends MessageComponent { /// This component's custom ID. final String? customId; + /// The purchasable SKU ID, if this button has [ButtonStyle.premium] style. + final Snowflake? skuId; + /// The URL this button redirects to, if this button is a URL button. final Uri? url; @@ -80,6 +83,7 @@ class ButtonComponent extends MessageComponent { required this.label, required this.emoji, required this.customId, + required this.skuId, required this.url, required this.isDisabled, }); @@ -91,7 +95,8 @@ enum ButtonStyle { secondary._(2), success._(3), danger._(4), - link._(5); + link._(5), + premium._(6); /// The value of this [ButtonStyle]. final int value;