diff --git a/lib/src/http/cdn/cdn_request.dart b/lib/src/http/cdn/cdn_request.dart index 50d9c23ca..7a81ec6a6 100644 --- a/lib/src/http/cdn/cdn_request.dart +++ b/lib/src/http/cdn/cdn_request.dart @@ -10,6 +10,8 @@ class CdnRequest extends HttpRequest { @override BaseRequest prepare(Nyxx client) { + final queryParameters = this.queryParameters.isEmpty ? null : this.queryParameters; + return Request(method, Uri.https(client.apiOptions.cdnHost, route.path, queryParameters)); } } diff --git a/lib/src/http/managers/member_manager.dart b/lib/src/http/managers/member_manager.dart index a083c39b9..7378cc23d 100644 --- a/lib/src/http/managers/member_manager.dart +++ b/lib/src/http/managers/member_manager.dart @@ -29,6 +29,7 @@ class MemberManager extends Manager { user: maybeParse(raw['user'], client.users.parse), nick: raw['nick'] as String?, avatarHash: raw['avatar'] as String?, + bannerHash: raw['banner'] as String?, roleIds: parseMany(raw['roles'] as List, Snowflake.parse), joinedAt: DateTime.parse(raw['joined_at'] as String), premiumSince: maybeParse(raw['premium_since'], DateTime.parse), diff --git a/lib/src/models/guild/member.dart b/lib/src/models/guild/member.dart index 9c709d799..f368e275e 100644 --- a/lib/src/models/guild/member.dart +++ b/lib/src/models/guild/member.dart @@ -61,6 +61,9 @@ class Member extends PartialMember { /// The hash of this member's avatar image. final String? avatarHash; + /// The hash of this member's banner image. + final String? bannerHash; + /// A list of the IDs of the roles this member has. final List roleIds; @@ -96,6 +99,7 @@ class Member extends PartialMember { required this.user, required this.nick, required this.avatarHash, + required this.bannerHash, required this.roleIds, required this.joinedAt, required this.premiumSince, @@ -121,6 +125,15 @@ class Member extends PartialMember { ..avatars(), hash: avatarHash!, ); + + CdnAsset get banner => CdnAsset( + client: manager.client, + base: HttpRoute() + ..guilds(id: manager.guildId.toString()) + ..users(id: id.toString()) + ..banners(), + hash: bannerHash!, + ); } /// Flags that can be applied to a [Member]. diff --git a/test/unit/http/bucket_test.dart b/test/unit/http/bucket_test.dart index 38782bf6c..17f9d6daa 100644 --- a/test/unit/http/bucket_test.dart +++ b/test/unit/http/bucket_test.dart @@ -37,7 +37,7 @@ void main() { final bucket = HttpBucket.fromResponse(handler, response); - expect(bucket, isNot(isNull)); + expect(bucket, isNotNull); expect(bucket?.id, equals('testBucketId')); expect(bucket?.remaining, equals(15)); diff --git a/test/unit/http/cdn_test.dart b/test/unit/http/cdn_test.dart new file mode 100644 index 000000000..174d90adf --- /dev/null +++ b/test/unit/http/cdn_test.dart @@ -0,0 +1,23 @@ +import 'package:mocktail/mocktail.dart'; +import 'package:nyxx/nyxx.dart'; +import 'package:test/test.dart'; + +import '../../mocks/client.dart'; + +void main() { + test('CdnAsset', () { + final client = MockNyxx(); + + when(() => client.apiOptions).thenReturn(RestApiOptions(token: 'TEST_TOKEN')); + + final asset = CdnAsset( + client: client, + base: HttpRoute() + ..add(HttpRoutePart('hello')) + ..add(HttpRoutePart('world')), + hash: 'yup', + ); + + expect(asset.url.toString(), equals('https://cdn.discordapp.com/hello/world/yup.png')); + }); +} diff --git a/test/unit/http/managers/member_manager_test.dart b/test/unit/http/managers/member_manager_test.dart index f1ebbb11e..eeec204d0 100644 --- a/test/unit/http/managers/member_manager_test.dart +++ b/test/unit/http/managers/member_manager_test.dart @@ -12,6 +12,7 @@ final sampleMemberNoUser = { "joined_at": "2015-04-26T06:26:56.936000+00:00", "deaf": false, "mute": false, + "banner": "a_coolHashDude", // These fields are documented as always present but are not in the provided sample "flags": 0, @@ -35,6 +36,7 @@ void checkMemberNoUser(Member member, {Snowflake expectedUserId = const Snowflak expect(member.isPending, isFalse); expect(member.permissions, isNull); expect(member.communicationDisabledUntil, isNull); + expect(member.bannerHash, equals('a_coolHashDude')); } void checkMember(Member member, {Snowflake expectedUserId = const Snowflake(80351110224678912)}) {