Skip to content

Commit

Permalink
bug: fix message edit behavior (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
l7ssha authored Jan 8, 2022
1 parent bf15bcb commit ded1470
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/src/utils/builders/message_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,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 @@ -77,9 +77,11 @@ class MessageBuilder {
/// Allows to add embed to message.
/// Warning: Completes future synchronously!
FutureOr<void> addEmbed(FutureOr<void> Function(EmbedBuilder embed) builder) async {
embeds ??= [];

final e = EmbedBuilder();
await builder(e);
embeds.add(e);
embeds!.add(e);
}

/// Appends clear character. Can be used to skip first line in message body.
Expand Down Expand Up @@ -150,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

0 comments on commit ded1470

Please sign in to comment.