Exemplo n.º 1
0
        public EmoticonData(TwitchEmoticonResponse emotes, string cache)
        {
            m_defaultSet = new EmoticonSet(this, -1);
            Cache        = cache;

            foreach (var emote in emotes.emoticons)
            {
                foreach (var img in emote.images)
                {
                    EmoticonSet set = GetOrCreateEmoticonSet(img.emoticon_set);
                    set.Add(new Emoticon(set, emote.regex, img));
                }
            }
        }
Exemplo n.º 2
0
        public static async Task <EmoticonData> GetEmoticonData(string cache)
        {
            string url = @"https://api.twitch.tv/kraken/chat/emoticons";
            TwitchEmoticonResponse emotes = null;

            for (int i = 0; i < 3 && emotes == null; i++)
            {
                try
                {
                    var req = (HttpWebRequest)HttpWebRequest.Create(url);
                    req.UserAgent = "TwitchChat Client";

                    var response = await req.GetResponseAsync();

                    var fromStream = response.GetResponseStream();

                    StreamReader reader = new StreamReader(fromStream);

                    emotes = JsonConvert.DeserializeObject <TwitchEmoticonResponse>(reader.ReadToEnd());
                }
                catch (Exception e)
                {
                    Log.Instance.WebApiError(url, e.ToString());
                }

                if (emotes == null)
                {
                    await Task.Delay(30000);
                }
            }

            var data = new EmoticonData(emotes, cache);

            data.DefaultEmoticons.DownloadAll();

            return(data);
        }