Skip to content

Commit

Permalink
Add banner to UserUpdateBuilder, and SkuFlags.available (#638)
Browse files Browse the repository at this point in the history
* add banner to UserUpdateBuilder, and SkuFlags.available

* add UserUpdateBuilder.banner test
  • Loading branch information
MCausc78 authored Mar 15, 2024
1 parent 02ee8a6 commit 42f7bef
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/src/builders/user.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import 'package:nyxx/src/builders/builder.dart';
import 'package:nyxx/src/builders/image.dart';
import 'package:nyxx/src/builders/sentinels.dart';
import 'package:nyxx/src/models/user/user.dart';

class UserUpdateBuilder extends UpdateBuilder<User> {
/// New user's username.
String? username;

/// New user's avatar.
ImageBuilder? avatar;

UserUpdateBuilder({this.username, this.avatar});
/// New user's banner.
ImageBuilder? banner;

UserUpdateBuilder({this.username, this.avatar = sentinelImageBuilder, this.banner = sentinelImageBuilder});

@override
Map<String, Object?> build() => {
if (username != null) 'username': username!,
if (avatar != null) 'avatar': avatar!.buildDataString(),
if (!identical(avatar, sentinelImageBuilder)) 'avatar': avatar?.buildDataString(),
if (!identical(banner, sentinelImageBuilder)) 'banner': banner?.buildDataString(),
};
}
6 changes: 6 additions & 0 deletions lib/src/models/sku.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ enum SkuType {

/// Flags applied to an [Sku].
class SkuFlags extends Flags<SkuFlags> {
/// The SKU is available for purchase.
static const available = Flag<SkuFlags>.fromOffset(0);

/// The SKU is a guild subscription.
static const guildSubscription = Flag<SkuFlags>.fromOffset(7);

Expand All @@ -77,6 +80,9 @@ class SkuFlags extends Flags<SkuFlags> {
/// Create a new [SkuFlags].
SkuFlags(super.value);

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

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

Expand Down
3 changes: 3 additions & 0 deletions test/unit/builders/user_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ void main() {

final builder4 = UserUpdateBuilder();
expect(builder4.build(), equals({}));

final builder5 = UserUpdateBuilder(banner: ImageBuilder.png([]));
expect(builder5.build(), equals({'banner': 'data:image/png;base64,'}));
});
});
}

0 comments on commit 42f7bef

Please sign in to comment.