diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c745c639..4882de487 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 f62d53127..474132cf6 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 416d7f1b2..95b7ef859 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 embeds = []; + List? 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 addEmbed(FutureOr 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 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 { 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 22455e18f..b1175c75c 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 diff --git a/test/unit/builders_test.dart b/test/unit/builders_test.dart index a0e71ea92..f08b73d0c 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();