Example #1
0
        public static IEnumerator GetCheermotes()
        {
            Plugin.Log($"Downloading twitch cheermote listing");
            int emotesCached = 0;

            yield return(Utilities.Download($"https://api.twitch.tv/v5/bits/actions?client_id=jg6ij5z8mf8jr8si22i5uq8tobnmde&channel_id={TwitchWebSocketClient.ChannelInfo[TwitchLoginConfig.Instance.TwitchChannelName].roomId}&include_sponsored=1", Utilities.DownloadType.Raw, null,
                                            (web) =>
            {
                JSONNode json = JSON.Parse(web.downloadHandler.text);
                if (json["actions"].IsArray)
                {
                    foreach (JSONNode node in json["actions"].AsArray.Values)
                    {
                        TwitchCheermote cheermote = new TwitchCheermote();
                        string prefix = node["prefix"].Value.ToLower();
                        foreach (JSONNode tier in node["tiers"].Values)
                        {
                            CheermoteTier newTier = new CheermoteTier();
                            newTier.minBits = tier["min_bits"].AsInt;
                            newTier.color = tier["color"].Value;
                            newTier.canCheer = tier["can_cheer"].AsBool;
                            cheermote.tiers.Add(newTier);
                        }
                        cheermote.tiers = cheermote.tiers.OrderBy(t => t.minBits).ToList();
                        TwitchCheermoteIDs.TryAdd(prefix, cheermote);
                        //Plugin.Log($"Cheermote: {prefix}");
                        emotesCached++;
                    }
                }
            }
                                            ));

            Plugin.Log($"Web request completed, {emotesCached.ToString()} twitch cheermotes now cached!");
        }
        public static IEnumerator GetCheermotes()
        {
            Plugin.Log($"Downloading twitch cheermote listing");
            int emotesCached = 0;

            yield return(Utilities.Download("https://api.twitch.tv/kraken/bits/actions", Utilities.DownloadType.Raw,
                                            // BeforeSend
                                            (web) =>
            {
                web.SetRequestHeader("Accept", "application/vnd.twitchtv.v5+json");
                web.SetRequestHeader("Channel-ID", TwitchLoginConfig.Instance.TwitchChannelName);
                web.SetRequestHeader("Client-ID", "jg6ij5z8mf8jr8si22i5uq8tobnmde");
            },
                                            // DownloadCompleted
                                            (web) =>
            {
                JSONNode json = JSON.Parse(web.downloadHandler.text);
                if (json["actions"].IsArray)
                {
                    foreach (JSONNode node in json["actions"].AsArray.Values)
                    {
                        TwitchCheermote cheermote = new TwitchCheermote();
                        string prefix = node["prefix"].ToString().ToLower();
                        foreach (JSONNode tier in node["tiers"].Values)
                        {
                            CheermoteTier newTier = new CheermoteTier();
                            newTier.minBits = tier["min_bits"].AsInt;
                            newTier.color = tier["color"];
                            newTier.canCheer = tier["can_cheer"].AsBool;
                            cheermote.tiers.Add(newTier);
                        }
                        cheermote.tiers = cheermote.tiers.OrderBy(t => t.minBits).ToList();
                        TwitchCheermoteIDs.TryAdd(prefix.Substring(1, prefix.Length - 2), cheermote);
                        //Plugin.Log($"Cheermote: {prefix}");
                        emotesCached++;
                    }
                }
            }
                                            ));

            Plugin.Log($"Web request completed, {emotesCached.ToString()} twitch cheermotes now cached!");
        }