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 banner property to member #676

Draft
wants to merge 5 commits into
base: dev
Choose a base branch
from
Draft
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/http/cdn/cdn_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
1 change: 1 addition & 0 deletions lib/src/http/managers/member_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class MemberManager extends Manager<Member> {
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),
Expand Down
13 changes: 13 additions & 0 deletions lib/src/models/guild/member.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Snowflake> roleIds;

Expand Down Expand Up @@ -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,
Expand All @@ -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].
Expand Down
2 changes: 1 addition & 1 deletion test/unit/http/bucket_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
23 changes: 23 additions & 0 deletions test/unit/http/cdn_test.dart
Original file line number Diff line number Diff line change
@@ -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'));
});
}
2 changes: 2 additions & 0 deletions test/unit/http/managers/member_manager_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)}) {
Expand Down
Loading