From 6f793dec356173757757b8223d65bf1e3af6f17c Mon Sep 17 00:00:00 2001 From: Rapougnac Date: Thu, 25 Apr 2024 08:47:20 +0200 Subject: [PATCH 1/7] bump nyxx --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 224f796..c912747 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,7 +10,7 @@ environment: dependencies: http: ^1.1.0 - nyxx: ^6.0.0 + nyxx: ^6.2.1 dev_dependencies: coverage: ^1.0.3 From 2764ef6aec254b85290ee17eb97d378464b28021 Mon Sep 17 00:00:00 2001 From: Rapougnac Date: Thu, 25 Apr 2024 08:47:36 +0200 Subject: [PATCH 2/7] Add example --- example/example.dart | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/example/example.dart b/example/example.dart index eb12212..298b307 100644 --- a/example/example.dart +++ b/example/example.dart @@ -24,7 +24,7 @@ void main() async { // Sanitizing content makes it safe to send to Discord without triggering any mentions client.onMessageCreate.listen((event) async { if (event.message.content.startsWith('!sanitize')) { - event.message.channel.sendMessage(MessageBuilder( + await event.message.channel.sendMessage(MessageBuilder( content: 'Sanitized content: ${await sanitizeContent(event.message.content, channel: event.message.channel)}', )); } @@ -67,5 +67,15 @@ ullamcorper morbi tincidunt ornare. } }); + client.onMessageCreate.listen((event) async { + if (event.message.content.startsWith('!avatar') && event.message.mentions.isNotEmpty) { + // Display the first mentioned user's avatar with the specified size. + final user = event.message.mentions.first; + await event.message.channel.sendMessage(MessageBuilder( + content: 'Avatar URL: ${user.avatar.get(format: CdnFormat.jpeg, size: 3072)}', + )); + } + }); + // ...and more! } From 7d8707eb359d4633154547c0e0186586ae4d6d6b Mon Sep 17 00:00:00 2001 From: Rapougnac Date: Thu, 25 Apr 2024 08:48:02 +0200 Subject: [PATCH 3/7] Export extension and hide getRequest --- lib/nyxx_extensions.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/nyxx_extensions.dart b/lib/nyxx_extensions.dart index 2d252b0..811e2ff 100644 --- a/lib/nyxx_extensions.dart +++ b/lib/nyxx_extensions.dart @@ -9,6 +9,7 @@ export 'src/utils/pagination.dart'; export 'src/utils/permissions.dart'; export 'src/utils/sanitizer.dart'; +export 'src/extensions/cdn_asset.dart' hide getRequest; export 'src/extensions/channel.dart'; export 'src/extensions/client.dart'; export 'src/extensions/date_time.dart'; From 2a8fe5fb5b9970e91f28db023a6168f56d7071ca Mon Sep 17 00:00:00 2001 From: Rapougnac Date: Thu, 25 Apr 2024 10:19:37 +0200 Subject: [PATCH 4/7] Add extension --- lib/src/extensions/cdn_asset.dart | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 lib/src/extensions/cdn_asset.dart diff --git a/lib/src/extensions/cdn_asset.dart b/lib/src/extensions/cdn_asset.dart new file mode 100644 index 0000000..6c2ddae --- /dev/null +++ b/lib/src/extensions/cdn_asset.dart @@ -0,0 +1,22 @@ +import 'package:nyxx/nyxx.dart'; + +extension CdnAssetExtensions on CdnAsset { + Uri get({CdnFormat? format, int? size}) => getRequest(this, format ?? defaultFormat, size).prepare(client).url; +} + +// Re-implementing the private method from CdnAsset +CdnRequest getRequest(CdnAsset asset, CdnFormat format, int? size) { + final route = HttpRoute(); + + for (final part in asset.base.parts) { + route.add(part); + } + route.add(HttpRoutePart('${asset.hash}.${format.extension}')); + + return CdnRequest( + route, + queryParameters: { + if (size != null) 'size': size.toString(), + }, + ); +} From 72349f3a75a419896b67b12983f5910dcb30aa48 Mon Sep 17 00:00:00 2001 From: Rapougnac Date: Thu, 25 Apr 2024 12:45:30 +0200 Subject: [PATCH 5/7] Add tests and format --- test/integration/member_test.dart | 11 ++++++++ test/unit/timestamp_style_test.dart | 40 ++++++----------------------- 2 files changed, 19 insertions(+), 32 deletions(-) diff --git a/test/integration/member_test.dart b/test/integration/member_test.dart index 7ba5111..14942f7 100644 --- a/test/integration/member_test.dart +++ b/test/integration/member_test.dart @@ -27,4 +27,15 @@ void main() { expect(mutualGuilds, isNotEmpty); }, ); + + test('avatar.get()', skip: testToken == null ? 'No token provided' : false, () async { + final client = await Nyxx.connectRest(testToken!); + + final self = await client.users.fetchCurrentUser(); + + expect( + self.avatar.get(size: 3072, format: CdnFormat.jpeg), + Uri.https('cdn.discordapp.com', 'avatars/${self.id}/${self.avatarHash}.${CdnFormat.jpeg.extension}', {'size': '3072'}), + ); + }); } diff --git a/test/unit/timestamp_style_test.dart b/test/unit/timestamp_style_test.dart index d84bd8d..989634f 100644 --- a/test/unit/timestamp_style_test.dart +++ b/test/unit/timestamp_style_test.dart @@ -6,37 +6,13 @@ final baseDate = Snowflake(846136758470443069).timestamp; void main() { group('Timestamp Test', () { - test( - 'None', - () => expect(baseDate.format(), - equals(''))); - test( - 'Short Time', - () => expect(baseDate.format(TimestampStyle.shortTime), - equals(''))); - test( - 'Long Time', - () => expect(baseDate.format(TimestampStyle.longTime), - equals(''))); - test( - 'Short Date', - () => expect(baseDate.format(TimestampStyle.shortDate), - equals(''))); - test( - 'Long Date', - () => expect(baseDate.format(TimestampStyle.longDate), - equals(''))); - test( - 'Short Date Time', - () => expect(baseDate.format(TimestampStyle.shortDateTime), - equals(''))); - test( - 'Long Date Time', - () => expect(baseDate.format(TimestampStyle.longDateTime), - equals(''))); - test( - 'Relative Time', - () => expect(baseDate.format(TimestampStyle.relativeTime), - equals(''))); + test('None', () => expect(baseDate.format(), equals(''))); + test('Short Time', () => expect(baseDate.format(TimestampStyle.shortTime), equals(''))); + test('Long Time', () => expect(baseDate.format(TimestampStyle.longTime), equals(''))); + test('Short Date', () => expect(baseDate.format(TimestampStyle.shortDate), equals(''))); + test('Long Date', () => expect(baseDate.format(TimestampStyle.longDate), equals(''))); + test('Short Date Time', () => expect(baseDate.format(TimestampStyle.shortDateTime), equals(''))); + test('Long Date Time', () => expect(baseDate.format(TimestampStyle.longDateTime), equals(''))); + test('Relative Time', () => expect(baseDate.format(TimestampStyle.relativeTime), equals(''))); }); } From 3655d01aedba1608ca70aae584c93d5c50cbe61e Mon Sep 17 00:00:00 2001 From: Rapougnac Date: Mon, 8 Jul 2024 23:12:19 +0200 Subject: [PATCH 6/7] bump nyxx --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index c912747..cd5637f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,7 +10,7 @@ environment: dependencies: http: ^1.1.0 - nyxx: ^6.2.1 + nyxx: ^6.3.0 dev_dependencies: coverage: ^1.0.3 From 3e437a9ef084be2ab5fa88bc781f62b7ec87e44c Mon Sep 17 00:00:00 2001 From: Rapougnac Date: Mon, 5 Aug 2024 13:41:06 +0200 Subject: [PATCH 7/7] Bump nyxx --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index cd5637f..c52b617 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,7 +10,7 @@ environment: dependencies: http: ^1.1.0 - nyxx: ^6.3.0 + nyxx: ^6.3.1 dev_dependencies: coverage: ^1.0.3