Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default to an empty string in Emoji#fromData #2172

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ static EmojiUnion fromData(@Nonnull DataObject emoji)
if (emoji.isNull("id"))
return (EmojiUnion) fromUnicode(emoji.getString("name"));
sebm253 marked this conversation as resolved.
Show resolved Hide resolved
else
return (EmojiUnion) fromCustom(emoji.getString("name"), emoji.getUnsignedLong("id"), emoji.getBoolean("animated"));
return (EmojiUnion) fromCustom(emoji.getString("name", ""), emoji.getUnsignedLong("id"), emoji.getBoolean("animated"));
Copy link
Contributor

@Mitmocc Mitmocc Jul 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to suggest changing this from "" to "null". Discord can at times send a message object containing a reaction with a null name (occurs every now and then when the bot is adding multiple reactions to a message and more often when users are clicking the reactions while the bot is still applying new ones).

So normally an exception is thrown but the exception is pretty useless as there is nothing the JDA user can do to prevent it and there is no reason to not still build the message object with the proper reactions, even if one of the reactions will have the name "null". Your suggested fix would still throw an exception as the empty name would be checked in the fromCustom method.
Setting the name to "null" however removes the unnecessary exception and builds the message object more accurately (doesn't skip over the reaction with the null name, just builds the reaction with the name "null".

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ protected Long handleInternally(DataObject content)

long messageId = content.getUnsignedLong("message_id");
DataObject emoji = content.getObject("emoji");
if (emoji.isNull("name"))
emoji.put("name", "");
EmojiUnion reactionEmoji = Emoji.fromData(emoji);

MessageReaction reaction = new MessageReaction(channel, reactionEmoji, messageId, false, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,7 @@ protected Long handleInternally(DataObject content)
);
}

// reaction remove has null name sometimes
if (emoji.isNull("name"))
emoji.put("name", "");
EmojiUnion rEmoji = Emoji.fromData(emoji);

Copy link
Contributor

@DManstrator DManstrator Jul 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: For consistency reason I would add that newline back or remove it too from the MessageReactionClearEmojiHandler and have the same variable name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think anything mentioned matters at all. in MessageReactionClearEmojiHandler, I think the variables passed into new MessageReaction(...) were just meant to be separated, same with MessageReactionHandler and the check.

MessageReaction reaction = new MessageReaction(channel, rEmoji, messageId, userId == api.getSelfUser().getIdLong(), -1);

if (channel.getType() == ChannelType.PRIVATE)
Expand Down