DiscordEmoji operator == shoulnd't compare names
Created by: ikegami
In https://github.com/DSharpPlus/DSharpPlus/blob/master/DSharpPlus/Entities/Emoji/DiscordEmoji.cs, we have
public static bool operator ==(DiscordEmoji e1, DiscordEmoji e2)
{
var o1 = e1 as object;
var o2 = e2 as object;
if ((o1 == null && o2 != null) || (o1 != null && o2 == null))
return false;
return o1 == null && o2 == null ? true : e1.Id == e2.Id && e1.Name == e2.Name;
}
Note the && e1.Name == e2.Name
.
This means that <:foo:1234>
is not equivalent to <:bar:1234>
, even though it's a reference to the same emoji. Discord doesn't even care what you put between the colons. Is that intentional?
The following, used in a reaction add/remove event handler, started failing after renaming the emoji in the guild.
args.Emoji == guild.Emojis[1234]
-
args.Emoji
has whatever name was provided when the reaction was created. -
guild.Emojis[1234]
has the new name (at least after a restart)
ok, fine, that can be solved using
args.Emoji.Id == guild.Emojis[1234]?.Id
But it also prevents putting the emojis in a HashSet, deduplicating a set of emojis, and whatever else uses the standard compare function.
I posit operator ==
should ignore differences in names.