Advertisement
Abahbob

bleh

Feb 28th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.42 KB | None | 0 0
  1. bool TwitchEmoteResolver(String emote, bool FFZ)
  2.         {
  3.             if (FFZ)
  4.             {
  5.                 XmlDocument xmlDoc = new XmlDocument();
  6.                 string xmlStr;
  7.                 string cssStr;
  8.                 using (var wc = new WebClient())
  9.                 {
  10.                     cssStr = wc.DownloadString("http://frankerfacez.storage.googleapis.com/global.css");
  11.                     xmlStr = wc.DownloadString("http://frankerfacez.storage.googleapis.com/");
  12.                 }
  13.  
  14.                 //Check if Global Emote
  15.                 if (cssStr.Contains("content: \"" + txtBox.Text + "\""))
  16.                 {
  17.  
  18.                     EmoteText = txtBox.Text;
  19.                     EmoteURL = "http://frankerfacez.storage.googleapis.com/global/" + txtBox.Text + ".png";
  20.                     return true;
  21.                 }
  22.                 else //Check all other emotes
  23.                 {
  24.                     xmlDoc.LoadXml(xmlStr);
  25.                     XmlNodeList emotes = xmlDoc.GetElementsByTagName("Contents");
  26.                     foreach (XmlNode node in emotes)
  27.                     {
  28.                         if (node.FirstChild.FirstChild.InnerText.Contains("/" + txtBox.Text + ".png"))
  29.                         {
  30.                             EmoteText = txtBox.Text;
  31.                             EmoteURL = "http://frankerfacez.storage.googleapis.com/" + node.FirstChild.FirstChild.InnerText;
  32.                             return true;
  33.                         }
  34.                     }
  35.                 }
  36.             }
  37.             else //FFZ == False, check Twitch
  38.             {
  39.                 var emotes = JSON.FromUri(new Uri("https://api.twitch.tv/kraken/chat/emoticons"));
  40.  
  41.                 foreach (var emoteSearch in emotes.emoticons)
  42.                 {
  43.                     if (Regex.IsMatch(txtBox.Text, emoteSearch.regex))
  44.                     {
  45.                         EmoteText = emoteSearch.regex;
  46.                         foreach (var image in emoteSearch.images)
  47.                         {
  48.                             if (image.emoticon_set == null)
  49.                             {
  50.                                 EmoteURL = image.url;
  51.                                 break;
  52.                             }
  53.                             EmoteURL = image.url;
  54.                         }
  55.                         return true;
  56.                     }
  57.                 }
  58.             }
  59.             return false;
  60.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement