From 42f7bef041de3bab6ff432ecc70b63fca21a8621 Mon Sep 17 00:00:00 2001 From: MCausc78 Date: Fri, 15 Mar 2024 22:12:15 +0200 Subject: [PATCH] Add banner to UserUpdateBuilder, and `SkuFlags.available` (#638) * add banner to UserUpdateBuilder, and SkuFlags.available * add UserUpdateBuilder.banner test --- lib/src/builders/user.dart | 12 ++++++++++-- lib/src/models/sku.dart | 6 ++++++ test/unit/builders/user_test.dart | 3 +++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/src/builders/user.dart b/lib/src/builders/user.dart index 30fa322ec..459c7cf25 100644 --- a/lib/src/builders/user.dart +++ b/lib/src/builders/user.dart @@ -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 { + /// 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 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(), }; } diff --git a/lib/src/models/sku.dart b/lib/src/models/sku.dart index eaf2d2c42..d67572ff5 100644 --- a/lib/src/models/sku.dart +++ b/lib/src/models/sku.dart @@ -68,6 +68,9 @@ enum SkuType { /// Flags applied to an [Sku]. class SkuFlags extends Flags { + /// The SKU is available for purchase. + static const available = Flag.fromOffset(0); + /// The SKU is a guild subscription. static const guildSubscription = Flag.fromOffset(7); @@ -77,6 +80,9 @@ class SkuFlags extends Flags { /// 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); diff --git a/test/unit/builders/user_test.dart b/test/unit/builders/user_test.dart index ae2ffa32c..26ae174f5 100644 --- a/test/unit/builders/user_test.dart +++ b/test/unit/builders/user_test.dart @@ -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,'})); }); }); }