Skip to content

Commit

Permalink
Added MessageEmbed#isEmpty and fixed MessageAction not allowing to se…
Browse files Browse the repository at this point in the history
…nd embeds with just an image set
  • Loading branch information
MinnDevelopment committed Dec 22, 2017
1 parent ac5b652 commit 40c760f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
18 changes: 17 additions & 1 deletion src/main/java/net/dv8tion/jda/core/entities/MessageEmbed.java
Expand Up @@ -25,7 +25,9 @@
import java.awt.Color;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
* Represents an embed displayed by Discord.
Expand Down Expand Up @@ -281,6 +283,18 @@ public OffsetDateTime getTimestamp()
return timestamp;
}

/**
* Whether this embed is empty.
*
* @return True, if this embed has no content
*/
public boolean isEmpty()
{
return getLength() == 0
&& getImage() == null
&& getThumbnail() == null;
}

/**
* The total amount of characters that is displayed when this embed is displayed by the Discord client.
*
Expand Down Expand Up @@ -344,6 +358,8 @@ public boolean isSendable(AccountType type)
{
Checks.notNull(type, "AccountType");
final int length = getLength();
if (isEmpty())
return false;

switch (type)
{
Expand Down
Expand Up @@ -103,8 +103,7 @@ public MessageAction(JDA api, Route.CompiledRoute route, MessageChannel channel,
public boolean isEmpty()
{
return Helpers.isBlank(content)
&& (!hasPermission(Permission.MESSAGE_EMBED_LINKS)
|| embed == null || embed.getLength() == 0);
&& (embed == null || embed.isEmpty() || !hasPermission(Permission.MESSAGE_EMBED_LINKS));
}

/**
Expand Down Expand Up @@ -248,7 +247,7 @@ public MessageAction embed(final MessageEmbed embed)
{
final AccountType type = getJDA().getAccountType();
Checks.check(embed.isSendable(type),
"Provided Message contains an embed with a length greater than %d characters, which is the max for %s accounts!",
"Provided Message contains an empty embed or an embed with a length greater than %d characters, which is the max for %s accounts!",
type == AccountType.BOT ? MessageEmbed.EMBED_MAX_LENGTH_BOT : MessageEmbed.EMBED_MAX_LENGTH_CLIENT, type);
}
this.embed = embed;
Expand Down
Expand Up @@ -124,7 +124,7 @@ public WebhookMessageBuilder addEmbeds(MessageEmbed... embeds)
{
Checks.notNull(embed, "Embed");
Checks.check(embed.isSendable(AccountType.BOT),
"One of the provided embeds exceeds the maximum character count of %d!", MessageEmbed.EMBED_MAX_LENGTH_BOT);
"One of the provided embeds is empty or exceeds the maximum character count of %d!", MessageEmbed.EMBED_MAX_LENGTH_BOT);
this.embeds.add(embed);
}
return this;
Expand Down Expand Up @@ -152,7 +152,7 @@ public WebhookMessageBuilder addEmbeds(Collection<MessageEmbed> embeds)
{
Checks.notNull(embed, "Embed");
Checks.check(embed.isSendable(AccountType.BOT),
"One of the provided embeds exceeds the maximum character count of %d!", MessageEmbed.EMBED_MAX_LENGTH_BOT);
"One of the provided embeds is empty or exceeds the maximum character count of %d!", MessageEmbed.EMBED_MAX_LENGTH_BOT);
this.embeds.add(embed);
}
return this;
Expand Down

0 comments on commit 40c760f

Please sign in to comment.