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 ButtonStyle.premium and deprecate InteractionCallbackType.premiumRequired #660

Merged
merged 1 commit into from
Jun 18, 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
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 @@ -254,6 +254,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
Loading