Browse Source

Adding Equals() overloads for reactions/emotes (#723)

tags/1.0
Pat Murphy RogueException 8 years ago
parent
commit
224d0403db
3 changed files with 54 additions and 0 deletions
  1. +13
    -0
      src/Discord.Net.Core/Entities/Emotes/Emoji.cs
  2. +19
    -0
      src/Discord.Net.Core/Entities/Emotes/Emote.cs
  3. +22
    -0
      src/Discord.Net.WebSocket/Entities/Messages/SocketReaction.cs

+ 13
- 0
src/Discord.Net.Core/Entities/Emotes/Emoji.cs View File

@@ -21,5 +21,18 @@
public string Name { get; }

public override string ToString() => Name;

public override bool Equals(object other)
{
if (other == null) return false;
if (other == this) return true;

var otherEmoji = other as Emoji;
if (otherEmoji == null) return false;

return string.Equals(Name, otherEmoji.Name);
}

public override int GetHashCode() => Name.GetHashCode();
}
}

+ 19
- 0
src/Discord.Net.Core/Entities/Emotes/Emote.cs View File

@@ -25,6 +25,25 @@ namespace Discord
Name = name;
}

public override bool Equals(object other)
{
if (other == null) return false;
if (other == this) return true;

var otherEmote = other as Emote;
if (otherEmote == null) return false;

return string.Equals(Name, otherEmote.Name) && Id == otherEmote.Id;
}

public override int GetHashCode()
{
unchecked
{
return (Name.GetHashCode() * 397) ^ Id.GetHashCode();
}
}

/// <summary>
/// Parse an Emote from its raw format
/// </summary>


+ 22
- 0
src/Discord.Net.WebSocket/Entities/Messages/SocketReaction.cs View File

@@ -29,5 +29,27 @@ namespace Discord.WebSocket
emote = new Emoji(model.Emoji.Name);
return new SocketReaction(channel, model.MessageId, message, model.UserId, user, emote);
}

public override bool Equals(object other)
{
if (other == null) return false;
if (other == this) return true;

var otherReaction = other as SocketReaction;
if (otherReaction == null) return false;

return UserId == otherReaction.UserId && MessageId == otherReaction.MessageId && Emote.Equals(otherReaction.Emote);
}

public override int GetHashCode()
{
unchecked
{
var hashCode = UserId.GetHashCode();
hashCode = (hashCode * 397) ^ MessageId.GetHashCode();
hashCode = (hashCode * 397) ^ Emote.GetHashCode();
return hashCode;
}
}
}
}

Loading…
Cancel
Save