Browse Source

Fix bugs in emote parser

pull/913/head
Christopher F 7 years ago
parent
commit
b6a987c946
1 changed files with 5 additions and 3 deletions
  1. +5
    -3
      src/Discord.Net.Core/Entities/Emotes/Emote.cs

+ 5
- 3
src/Discord.Net.Core/Entities/Emotes/Emote.cs View File

@@ -66,15 +66,17 @@ namespace Discord
result = null; result = null;
if (text.Length >= 4 && text[0] == '<' && (text[1] == ':' || (text[1] == 'a' && text[2] == ':')) && text[text.Length - 1] == '>') if (text.Length >= 4 && text[0] == '<' && (text[1] == ':' || (text[1] == 'a' && text[2] == ':')) && text[text.Length - 1] == '>')
{ {
int splitIndex = text.IndexOf(':', 2);
bool animated = text[1] == 'a';
int startIndex = animated ? 3 : 2;

int splitIndex = text.IndexOf(':', startIndex);
if (splitIndex == -1) if (splitIndex == -1)
return false; return false;


if (!ulong.TryParse(text.Substring(splitIndex + 1, text.Length - splitIndex - 2), NumberStyles.None, CultureInfo.InvariantCulture, out ulong id)) if (!ulong.TryParse(text.Substring(splitIndex + 1, text.Length - splitIndex - 2), NumberStyles.None, CultureInfo.InvariantCulture, out ulong id))
return false; return false;


string name = text.Substring(2, splitIndex - 2);
bool animated = text[1] == 'a';
string name = text.Substring(startIndex, splitIndex - startIndex);
result = new Emote(id, name, animated); result = new Emote(id, name, animated);
return true; return true;
} }


Loading…
Cancel
Save