Repository: nyxx-discord/nyxx
Pull request #285 (2022-01-08 22:10:03)

Release 3.2.2


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9c745c63..4882de48 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,9 @@
+## 3.2.2
+__08.01.2022__
+
+- Fix message edit behavior (#283)
+- Fix `addEmbed` behavior on message builder (#284)
+
 ## 3.2.1
 __01.01.2022__
 
diff --git a/lib/src/internal/constants.dart b/lib/src/internal/constants.dart
index f62d5312..474132cf 100644
--- a/lib/src/internal/constants.dart
+++ b/lib/src/internal/constants.dart
@@ -33,7 +33,7 @@ class Constants {
   static const int apiVersion = 9;
 
   /// Version of Nyxx
-  static const String version = "3.2.1";
+  static const String version = "3.2.2";
 
   /// Url to Nyxx repo
   static const String repoUrl = "https://github.com/nyxx-discord/nyxx";
diff --git a/lib/src/utils/builders/message_builder.dart b/lib/src/utils/builders/message_builder.dart
index 416d7f1b..95b7ef85 100644
--- a/lib/src/utils/builders/message_builder.dart
+++ b/lib/src/utils/builders/message_builder.dart
@@ -1,3 +1,4 @@
+import 'dart:async';
 import 'dart:io';
 
 import 'package:http/http.dart' as http;
@@ -28,7 +29,7 @@ class MessageBuilder {
   ReplyBuilder? replyBuilder;
 
   /// Embed to include in message
-  List<EmbedBuilder> embeds = [];
+  List<EmbedBuilder>? embeds;
 
   /// [AllowedMentions] object to control mentions in message
   AllowedMentions? allowedMentions;
@@ -73,11 +74,14 @@ class MessageBuilder {
     ..embeds = message.embeds.map((e) => e.toBuilder()).toList()
     ..replyBuilder = message.referencedMessage?.toBuilder();
 
-  /// Allows to add embed to message
-  void addEmbed(void Function(EmbedBuilder embed) builder) {
+  /// Allows to add embed to message.
+  /// Warning: Completes future synchronously!
+  FutureOr<void> addEmbed(FutureOr<void> Function(EmbedBuilder embed) builder) async {
+    embeds ??= [];
+
     final e = EmbedBuilder();
-    builder(e);
-    embeds.add(e);
+    await builder(e);
+    embeds!.add(e);
   }
 
   /// Appends clear character. Can be used to skip first line in message body.
@@ -148,14 +152,14 @@ class MessageBuilder {
   Future<IMessage> send(ISend entity) => entity.sendMessage(this);
 
   /// Returns if this instance of message builder can be used when editing message
-  bool canBeUsedAsNewMessage() => content.isNotEmpty || embeds.isNotEmpty || (files != null && files!.isNotEmpty);
+  bool canBeUsedAsNewMessage() => content.isNotEmpty || embeds != null || (files != null && files!.isNotEmpty);
 
   RawApiMap build([AllowedMentions? defaultAllowedMentions]) {
     allowedMentions ??= defaultAllowedMentions;
 
     return <String, dynamic>{
       if (content.isNotEmpty) "content": content.toString(),
-      if (embeds.isNotEmpty) "embeds": [for (final e in embeds) e.build()],
+      if (embeds != null) "embeds": [for (final e in embeds!) e.build()],
       if (allowedMentions != null) "allowed_mentions": allowedMentions!.build(),
       if (replyBuilder != null) "message_reference": replyBuilder!.build(),
       if (tts != null) "tts": tts,
diff --git a/pubspec.yaml b/pubspec.yaml
index 22455e18..b1175c75 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
 name: nyxx
-version: 3.2.1
+version: 3.2.2
 description: A Discord library for Dart. Simple, robust framework for creating discord bots for Dart language.
 homepage: https://github.com/nyxx-discord/nyxx
 repository: https://github.com/nyxx-discord/nyxx


Test patch:
diff --git a/test/unit/builders_test.dart b/test/unit/builders_test.dart
index a0e71ea9..f08b73d0 100644
--- a/test/unit/builders_test.dart
+++ b/test/unit/builders_test.dart
@@ -140,9 +140,9 @@ main() {
       expect(builder.content, equals(MessageBuilder.clearCharacter));
     });
 
-    test('embeds', () {
+    test('embeds', () async {
       final builder = MessageBuilder.embed(EmbedBuilder()..description = 'test1');
-      builder.addEmbed((embed) => embed.description = 'test2');
+      await builder.addEmbed((embed) => embed.description = 'test2');
 
       final result = builder.build();