From e9793e5c357b21237ecbd80fd85b1efd1461dd0e Mon Sep 17 00:00:00 2001 From: Abitofevrything <54505189+abitofevrything@users.noreply.github.com> Date: Sun, 14 Apr 2024 19:45:00 +0200 Subject: [PATCH 1/2] Add endpoint pagination for reactions (#35) --- .../extensions/managers/message_manager.dart | 19 +++++++++++++++++++ lib/src/extensions/message.dart | 13 ++++++++++++- lib/src/utils/formatters.dart | 2 +- pubspec.yaml | 2 +- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/lib/src/extensions/managers/message_manager.dart b/lib/src/extensions/managers/message_manager.dart index 659940b..4e4dda7 100644 --- a/lib/src/extensions/managers/message_manager.dart +++ b/lib/src/extensions/managers/message_manager.dart @@ -34,4 +34,23 @@ extension MessageManagerExtensions on MessageManager { pageSize: pageSize, order: order, ); + + /// Same as [fetchReactions], but has no limit on the number of reactions returned. + /// + /// {@macro paginated_endpoint_streaming_parameters} + Stream streamReactions( + Snowflake id, + ReactionBuilder emoji, { + Snowflake? after, + Snowflake? before, + int? pageSize, + }) => + streamPaginatedEndpoint( + ({before, after, limit}) => fetchReactions(id, emoji, after: after, limit: limit), + extractId: (user) => user.id, + before: before, + after: after, + pageSize: pageSize, + order: StreamOrder.oldestFirst, + ); } diff --git a/lib/src/extensions/message.dart b/lib/src/extensions/message.dart index 295c094..8a95371 100644 --- a/lib/src/extensions/message.dart +++ b/lib/src/extensions/message.dart @@ -1,5 +1,5 @@ import 'package:nyxx/nyxx.dart'; -import 'package:nyxx_extensions/src/extensions/channel.dart'; +import 'package:nyxx_extensions/nyxx_extensions.dart'; /// Extensions on [Message]s. extension MessageExtensions on Message { @@ -25,4 +25,15 @@ extension MessageExtensions on Message { return channel.sendMessage(copiedBuilder); } + + /// Same as [fetchReactions], but has no limit on the number of reactions returned. + /// + /// {@macro paginated_endpoint_streaming_parameters} + Stream streamReactions( + ReactionBuilder emoji, { + Snowflake? after, + Snowflake? before, + int? pageSize, + }) => + manager.streamReactions(id, emoji, after: after, before: before, pageSize: pageSize); } diff --git a/lib/src/utils/formatters.dart b/lib/src/utils/formatters.dart index b3cf3e0..eb23179 100644 --- a/lib/src/utils/formatters.dart +++ b/lib/src/utils/formatters.dart @@ -1,4 +1,4 @@ -import 'package:nyxx/src/models/snowflake.dart'; +import 'package:nyxx/nyxx.dart'; /// Wraps the [code] in a code block with the specified language, if any. String codeBlock(String code, [String language = '']) => '```$language\n$code\n```'; diff --git a/pubspec.yaml b/pubspec.yaml index 224f796..d4b246e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,7 +10,7 @@ environment: dependencies: http: ^1.1.0 - nyxx: ^6.0.0 + nyxx: ^6.2.0 dev_dependencies: coverage: ^1.0.3 From d560a924bc0dd6d9e050dd5dae2f0e359bb1cfdd Mon Sep 17 00:00:00 2001 From: Abitofevrything <54505189+abitofevrything@users.noreply.github.com> Date: Sun, 14 Apr 2024 20:40:06 +0200 Subject: [PATCH 2/2] Add getter for everyone role in a guild (#36) --- lib/src/extensions/managers/role_manager.dart | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 lib/src/extensions/managers/role_manager.dart diff --git a/lib/src/extensions/managers/role_manager.dart b/lib/src/extensions/managers/role_manager.dart new file mode 100644 index 0000000..b38bdeb --- /dev/null +++ b/lib/src/extensions/managers/role_manager.dart @@ -0,0 +1,6 @@ +import 'package:nyxx/nyxx.dart'; + +extension RoleManagerExtensions on RoleManager { + /// The role representing `@everyone` in this guild. + PartialRole get everyone => this[guildId]; +}