Skip to content

Commit

Permalink
Add ButtonStyle.premium and deprecate `InteractionCallbackType.prem…
Browse files Browse the repository at this point in the history
…iumRequired` (#660)
  • Loading branch information
MCausc78 authored and abitofevrything committed Jul 7, 2024
1 parent 4a4126e commit e013a42
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/src/builders/interaction_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class InteractionResponseBuilder extends CreateBuilder<InteractionResponseBuilde

factory InteractionResponseBuilder.modal(ModalBuilder modal) => InteractionResponseBuilder(type: InteractionCallbackType.modal, data: modal);

@Deprecated('Respond with ButtonStyle.premium button instead')
factory InteractionResponseBuilder.premiumRequired() => InteractionResponseBuilder(type: InteractionCallbackType.premiumRequired, data: null);

@override
Expand Down Expand Up @@ -111,6 +112,7 @@ enum InteractionCallbackType {
updateMessage._(7),
applicationCommandAutocompleteResult._(8),
modal._(9),
@Deprecated('Respond with ButtonStyle.premium button instead')
premiumRequired._(10);

final int value;
Expand Down
12 changes: 12 additions & 0 deletions lib/src/builders/message/component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class ButtonBuilder extends MessageComponentBuilder {

String? customId;

Snowflake? skuId;

Uri? url;

bool? isDisabled;
Expand All @@ -47,6 +49,7 @@ class ButtonBuilder extends MessageComponentBuilder {
this.label,
this.emoji,
this.customId,
this.skuId,
this.url,
this.isDisabled,
}) : super(type: MessageComponentType.button);
Expand Down Expand Up @@ -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<String, Object?> build() => {
...super.build(),
Expand All @@ -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,
};
Expand Down
1 change: 1 addition & 0 deletions lib/src/http/managers/message_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ class MessageManager extends Manager<Message> {
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?,
),
Expand Down
7 changes: 6 additions & 1 deletion lib/src/models/message/component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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,
});
Expand All @@ -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;
Expand Down

0 comments on commit e013a42

Please sign in to comment.