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 SKU flags field #602

Merged
merged 1 commit into from
Dec 9, 2023
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: 1 addition & 1 deletion lib/nyxx.dart
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ export 'src/models/interaction.dart'
ModalSubmitInteraction,
PingInteraction;
export 'src/models/entitlement.dart' show Entitlement, PartialEntitlement, EntitlementType;
export 'src/models/sku.dart' show Sku, SkuType;
export 'src/models/sku.dart' show Sku, SkuType, SkuFlags;

export 'src/utils/flags.dart' show Flag, Flags;
export 'src/intents.dart' show GatewayIntents;
Expand Down
1 change: 1 addition & 0 deletions lib/src/http/managers/application_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class ApplicationManager {
applicationId: Snowflake.parse(raw['application_id']!),
name: raw['name'] as String,
slug: raw['slug'] as String,
flags: SkuFlags(raw['flags'] as int),
);
}

Expand Down
23 changes: 23 additions & 0 deletions lib/src/models/sku.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:nyxx/src/http/managers/application_manager.dart';
import 'package:nyxx/src/models/application.dart';
import 'package:nyxx/src/models/snowflake.dart';
import 'package:nyxx/src/utils/flags.dart';
import 'package:nyxx/src/utils/to_string_helper/to_string_helper.dart';

/// {@template sku}
Expand All @@ -25,6 +26,9 @@ class Sku with ToStringHelper {
/// The URL slug for this SKU.
final String slug;

/// This SKU's flags.
final SkuFlags flags;

/// {@macro sku}
Sku({
required this.manager,
Expand All @@ -33,6 +37,7 @@ class Sku with ToStringHelper {
required this.applicationId,
required this.name,
required this.slug,
required this.flags,
});

/// The application this SKU belongs to.
Expand All @@ -59,3 +64,21 @@ enum SkuType {
@override
String toString() => 'SkuType($value)';
}

/// Flags applied to an [Sku].
class SkuFlags extends Flags<SkuFlags> {
/// The SKU is a guild subscription.
static const guildSubscription = Flag<SkuFlags>.fromOffset(7);

/// The SKU is a user subscription.
static const userSubscription = Flag<SkuFlags>.fromOffset(8);

/// Create a new [SkuFlags].
SkuFlags(super.value);

/// Whether this set of flags has the [guildSubscription] flag set.
bool get isGuildSubscription => has(guildSubscription);

/// Whether this set of flags has the [userSubscription] flag set.
bool get isUserSubscription => has(userSubscription);
}