Discordia icon indicating copy to clipboard operation
Discordia copied to clipboard

Reaction hash is not unique to the reaction object

Open SinisterRectus opened this issue 6 years ago • 3 comments

The hashes of two or more reactions from different messages are equal when they represent the same emoji. This results in Container:__eq() returning true for the reaction objects, even if they are on different messages. This behavior may be unintuitive, but fixing the __eq behavior would require changing the reaction hash format.

SinisterRectus avatar Aug 21 '18 23:08 SinisterRectus

This will almost certainly not change until the next major version of Discordia.

SinisterRectus avatar Oct 31 '18 20:10 SinisterRectus

I have not defined __hash methods in 3.0 yet. I'm not sure if I will at this point, but I do have an __eq method for the Reaction class that will resolve this issue:

function Reaction:__eq(other)
  return self.messageId == other.messageId and self.emojiHash == other.emojiHash
end

SinisterRectus avatar Aug 31 '20 16:08 SinisterRectus

Update:

I've added an "unflattened" ReactionEmoji struct class that is accessible at the emoji property AND added a hash property that returns emoji.id for custom emojis or emoji.name for standard unicode emojis. This is NOT the same as emoji.hash, which is the concatenation of emoji.name and emoji.id for HTTP requests with custom emojis.

The __eq method has therefore been changed to:

function Reaction:__eq(other)
	return self.messageId == other.messageId and self.hash == other.hash
end

SinisterRectus avatar Jul 06 '21 14:07 SinisterRectus