Skip to content

Commit

Permalink
Merge pull request #285 from nyxx-discord/dev
Browse files Browse the repository at this point in the history
Release 3.2.2
  • Loading branch information
l7ssha authored Jan 8, 2022
2 parents dcef810 + 1d4d1bd commit 131bc1c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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__

Expand Down
2 changes: 1 addition & 1 deletion lib/src/internal/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
18 changes: 11 additions & 7 deletions lib/src/utils/builders/message_builder.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:io';

import 'package:http/http.dart' as http;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/unit/builders_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 131bc1c

Please sign in to comment.