Пример #1
0
 internal static void TriggerEmotesLoaded()
 {
     EmotesLoaded?.Invoke(null, EventArgs.Empty);
 }
Пример #2
0
        public static void LoadGlobalEmotes()
        {
            // bttv emotes
            Task.Run(() =>
            {
                try
                {
                    var parser = new System.Text.Json.JsonParser();

                    // better twitch tv emotes
                    //if (!File.Exists(bttvEmotesGlobalCache))
                    {
                        try
                        {
                            if (Util.IsLinux)
                            {
                                Util.LinuxDownloadFile("https://api.betterttv.net/3/cached/emotes/global", bttvEmotesGlobalCache);
                            }
                            else
                            {
                                using (var webClient = new WebClient()) {
                                    using (var readStream = webClient.OpenRead("https://api.betterttv.net/3/cached/emotes/global")) {
                                        if (File.Exists(bttvEmotesGlobalCache))
                                        {
                                            File.Delete(bttvEmotesGlobalCache);
                                        }
                                        using (var writeStream = File.OpenWrite(bttvEmotesGlobalCache))
                                        {
                                            readStream.CopyTo(writeStream);
                                        }
                                        readStream.Close();
                                    }
                                    webClient.Dispose();
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            e.Message.Log("emotes");
                        }
                    }

                    using (var stream = File.OpenRead(bttvEmotesGlobalCache))
                    {
                        dynamic json = parser.Parse(stream);
                        //var template = "https:" + json["urlTemplate"]; // urlTemplate is outdated, came from bttv v2 api, returned: //cdn.betterttv.net/emote/{{id}}/{{image}}
                        var template = "https://cdn.betterttv.net/emote/{{id}}/{{image}}";

                        foreach (var e in json)
                        {
                            string id        = e["id"];
                            string code      = e["code"];
                            string imageType = e["imageType"];
                            string url       = template.Replace("{{id}}", id);
                            double fake;
                            string tooltipurl = GetBttvEmoteLink(url, true, out fake);

                            double scale;
                            url = GetBttvEmoteLink(url, false, out scale);

                            BttvGlobalEmotes[code] = new LazyLoadedImage {
                                Name = code, Url = url, TooltipImageUrl = tooltipurl, IsHat = IsBttvEmoteAHat(code), Scale = scale, Tooltip = code + "\nBetterTTV Global Emote", IsEmote = true
                            };
                        }
                    }
                    EmotesLoaded?.Invoke(null, EventArgs.Empty);
                }
                catch (Exception exc)
                {
                    Console.WriteLine("error loading emotes: " + exc.Message);
                }
            });

            // ffz emotes
            Task.Run(() =>
            {
                try
                {
                    var parser = new System.Text.Json.JsonParser();

                    //if (!File.Exists(ffzEmotesGlobalCache))
                    {
                        try
                        {
                            if (Util.IsLinux)
                            {
                                Util.LinuxDownloadFile("https://api.frankerfacez.com/v1/set/global", ffzEmotesGlobalCache);
                            }
                            else
                            {
                                using (var webClient = new WebClient()) {
                                    using (var readStream = webClient.OpenRead("https://api.frankerfacez.com/v1/set/global")) {
                                        if (File.Exists(ffzEmotesGlobalCache))
                                        {
                                            File.Delete(ffzEmotesGlobalCache);
                                        }
                                        using (var writeStream = File.OpenWrite(ffzEmotesGlobalCache))
                                        {
                                            readStream.CopyTo(writeStream);
                                        }
                                        readStream.Close();
                                    }
                                    webClient.Dispose();
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            e.Message.Log("emotes");
                        }
                    }

                    using (var stream = File.OpenRead(ffzEmotesGlobalCache))
                    {
                        dynamic json = parser.Parse(stream);

                        foreach (var set in json["sets"])
                        {
                            var val = set.Value;

                            foreach (LazyLoadedImage emote in GetFfzEmoteFromDynamic(val["emoticons"], true))
                            {
                                FfzGlobalEmotes[emote.Name] = emote;
                            }
                        }
                    }
                    EmotesLoaded?.Invoke(null, EventArgs.Empty);
                }
                catch (Exception exc)
                {
                    Console.WriteLine("error loading emotes: " + exc.Message);
                }
            });

            // ffz event emotes
            Task.Run(() =>
            {
                try
                {
                    var set = 0;

                    var parser = new System.Text.Json.JsonParser();
                    using (var webClient = new WebClient()) {
                        using (var readStream = webClient.OpenRead("https://cdn.frankerfacez.com/script/event.json"))
                        {
                            dynamic json = parser.Parse(readStream);

                            string _set = json["set"];

                            int.TryParse(_set, out set);
                            readStream.Close();
                        }
                        webClient.Dispose();
                    }

                    if (set != 0)
                    {
                        using (var webClient = new WebClient()) {
                            using (var readStream = webClient.OpenRead("https://api.frankerfacez.com/v1/set/" + set))
                            {
                                dynamic json = parser.Parse(readStream);
                                dynamic _set = json["set"];

                                dynamic emoticons = _set["emoticons"];

                                foreach (LazyLoadedImage emote in GetFfzEmoteFromDynamic(emoticons, true))
                                {
                                    FfzGlobalEmotes[emote.Name] = emote;
                                }
                                readStream.Close();
                            }
                            webClient.Dispose();
                        }
                    }
                }
                catch (Exception e)
                {
                    e.Message.Log("emotes");
                }
            });

            //7tv global emotes
            Task.Run(() =>
            {
                try
                {
                    var parser = new System.Text.Json.JsonParser();

                    //if (!File.Exists(ffzEmotesGlobalCache))
                    {
                        try
                        {
                            if (Util.IsLinux)
                            {
                                Util.LinuxDownloadFile("https://api.7tv.app/v2/emotes/global", seventvEmotesGlobalCache);
                            }
                            else
                            {
                                using (var webClient = new WebClient()) {
                                    using (var readStream = webClient.OpenRead("https://api.7tv.app/v2/emotes/global")) {
                                        if (File.Exists(seventvEmotesGlobalCache))
                                        {
                                            File.Delete(seventvEmotesGlobalCache);
                                        }
                                        using (var writeStream = File.OpenWrite(seventvEmotesGlobalCache))
                                        {
                                            readStream.CopyTo(writeStream);
                                        }
                                        readStream.Close();
                                    }
                                    webClient.Dispose();
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            e.Message.Log("emotes");
                        }
                    }

                    using (var stream = File.OpenRead(seventvEmotesGlobalCache))
                    {
                        dynamic json = parser.Parse(stream);
                        string emotename;
                        string emoteid;
                        dynamic owner;
                        string ownername;
                        string template = "https://cdn.7tv.app/emote/{{id}}/{{image}}";
                        bool getemote;
                        double fake;
                        double scale;
                        string tooltipurl;
                        string url;
                        int visibilityFlags;
                        string visibility;
                        const int zeroWidthFlag = 0x80;
                        bool zeroWidth          = false;

                        LazyLoadedImage emote;
                        foreach (var e in json)
                        {
                            emotename  = e["name"];
                            emoteid    = e["id"];
                            url        = template.Replace("{{id}}", emoteid);
                            tooltipurl = GetBttvEmoteLink(url, true, out fake);
                            url        = GetBttvEmoteLink(url, false, out scale);
                            owner      = e["owner"];
                            visibility = e["visibility"];
                            if (!string.IsNullOrEmpty(visibility) && int.TryParse(visibility, out visibilityFlags))
                            {
                                zeroWidth = (visibilityFlags & zeroWidthFlag) > 0;
                            }
                            ownername = "";
                            if (owner != null)
                            {
                                ownername = owner["display_name"];
                                if (!string.IsNullOrEmpty(ownername))
                                {
                                    ownername = owner["login"];
                                }
                                else if (string.Compare(ownername.ToUpper(), owner["login"].ToUpper()))
                                {
                                    ownername = ownername + "(" + owner["login"] + ")";
                                }
                            }
                            emote = new LazyLoadedImage
                            {
                                Name            = emotename,
                                Url             = url,
                                Tooltip         = emotename + "\n7TV Channel Emote\nChannel: " + ownername,
                                TooltipImageUrl = tooltipurl,
                                Scale           = scale,
                                IsHat           = zeroWidth,
                                IsEmote         = true
                            };
                            SeventvGlobalEmotes[emote.Name] = emote;
                        }
                    }
                    EmotesLoaded?.Invoke(null, EventArgs.Empty);
                }
                catch (Exception exc)
                {
                    Console.WriteLine("error loading emotes: " + exc.Message);
                }
            });
        }
Пример #3
0
        public static void LoadGlobalEmotes()
        {
            // twitchemotes

            /*
             * Task.Run(() =>
             * {
             *  try
             *  {
             *      Directory.CreateDirectory("./Cache");
             *
             *      System.Text.Json.JsonParser parser = new System.Text.Json.JsonParser();
             *
             *      // twitchemotes api global emotes
             *      if (!File.Exists(twitchemotesGlobalCache) || DateTime.Now - new FileInfo(twitchemotesGlobalCache).LastWriteTime > TimeSpan.FromHours(24))
             *      {
             *          try
             *          {
             *              if (Util.IsLinux)
             *              {
             *                  Util.LinuxDownloadFile("https://twitchemotes.com/api_cache/v2/global.json", twitchemotesGlobalCache);
             *              }
             *              else
             *              {
             *                  using (var webClient = new WebClient())
             *                  using (var readStream = webClient.OpenRead("https://twitchemotes.com/api_cache/v2/global.json"))
             *                  using (var writeStream = File.OpenWrite(twitchemotesGlobalCache))
             *                  {
             *                      readStream.CopyTo(writeStream);
             *                  }
             *              }
             *          }
             *          catch (Exception e)
             *          {
             *              e.Message.Log("emotes");
             *          }
             *      }
             *
             *      using (var stream = File.OpenRead(twitchemotesGlobalCache))
             *      {
             *          dynamic json = parser.Parse(stream);
             *          dynamic templates = json["template"];
             *          string template112 = templates["large"];
             *
             *          foreach (KeyValuePair<string, object> e in json["emotes"])
             *          {
             *              string code = e.Key;
             *
             *              TwitchGlobalEmotes[code.ToUpper()] = code;
             *          }
             *      }
             *      EmotesLoaded?.Invoke(null, EventArgs.Empty);
             *  }
             *  catch { }
             * });
             */

            // bttv emotes
            Task.Run(() =>
            {
                try
                {
                    var parser = new System.Text.Json.JsonParser();

                    // better twitch tv emotes
                    //if (!File.Exists(bttvEmotesGlobalCache))
                    {
                        try
                        {
                            if (Util.IsLinux)
                            {
                                Util.LinuxDownloadFile("https://api.betterttv.net/2/emotes", bttvEmotesGlobalCache);
                            }
                            else
                            {
                                using (var webClient = new WebClient())
                                    using (var readStream = webClient.OpenRead("https://api.betterttv.net/2/emotes"))
                                        using (var writeStream = File.OpenWrite(bttvEmotesGlobalCache))
                                        {
                                            readStream.CopyTo(writeStream);
                                        }
                            }
                        }
                        catch (Exception e)
                        {
                            e.Message.Log("emotes");
                        }
                    }

                    using (var stream = File.OpenRead(bttvEmotesGlobalCache))
                    {
                        dynamic json = parser.Parse(stream);
                        var template = "https:" + json["urlTemplate"]; //{{id}} {{image}}

                        foreach (var e in json["emotes"])
                        {
                            string id        = e["id"];
                            string code      = e["code"];
                            string imageType = e["imageType"];
                            string url       = template.Replace("{{id}}", id);

                            double scale;
                            url = GetBttvEmoteLink(url, out scale);

                            BttvGlobalEmotes[code] = new LazyLoadedImage {
                                Name = code, Url = url, IsHat = IsBttvEmoteAHat(code), Scale = scale, Tooltip = code + "\nBetterTTV Global Emote", IsEmote = true
                            };
                        }
                    }
                    EmotesLoaded?.Invoke(null, EventArgs.Empty);
                }
                catch (Exception exc)
                {
                    Console.WriteLine("error loading emotes: " + exc.Message);
                }
            });

            // ffz emotes
            Task.Run(() =>
            {
                try
                {
                    var parser = new System.Text.Json.JsonParser();

                    //if (!File.Exists(ffzEmotesGlobalCache))
                    {
                        try
                        {
                            if (Util.IsLinux)
                            {
                                Util.LinuxDownloadFile("https://api.frankerfacez.com/v1/set/global", ffzEmotesGlobalCache);
                            }
                            else
                            {
                                using (var webClient = new WebClient())
                                    using (var readStream = webClient.OpenRead("https://api.frankerfacez.com/v1/set/global"))
                                        using (var writeStream = File.OpenWrite(ffzEmotesGlobalCache))
                                        {
                                            readStream.CopyTo(writeStream);
                                        }
                            }
                        }
                        catch (Exception e)
                        {
                            e.Message.Log("emotes");
                        }
                    }

                    using (var stream = File.OpenRead(ffzEmotesGlobalCache))
                    {
                        dynamic json = parser.Parse(stream);

                        foreach (var set in json["sets"])
                        {
                            var val = set.Value;

                            foreach (LazyLoadedImage emote in GetFfzEmoteFromDynamic(val["emoticons"], true))
                            {
                                FfzGlobalEmotes[emote.Name] = emote;
                            }
                        }
                    }
                    EmotesLoaded?.Invoke(null, EventArgs.Empty);
                }
                catch (Exception exc)
                {
                    Console.WriteLine("error loading emotes: " + exc.Message);
                }
            });

            // ffz event emotes
            Task.Run(() =>
            {
                try
                {
                    var set = 0;

                    var parser = new System.Text.Json.JsonParser();
                    using (var webClient = new WebClient())
                        using (var readStream = webClient.OpenRead("https://cdn.frankerfacez.com/script/event.json"))
                        {
                            dynamic json = parser.Parse(readStream);

                            string _set = json["set"];

                            int.TryParse(_set, out set);
                        }

                    if (set != 0)
                    {
                        using (var webClient = new WebClient())
                            using (var readStream = webClient.OpenRead("https://api.frankerfacez.com/v1/set/" + set))
                            {
                                dynamic json = parser.Parse(readStream);
                                dynamic _set = json["set"];

                                dynamic emoticons = _set["emoticons"];

                                foreach (LazyLoadedImage emote in GetFfzEmoteFromDynamic(emoticons, true))
                                {
                                    FfzGlobalEmotes[emote.Name] = emote;
                                }
                            }
                    }
                }
                catch (Exception e)
                {
                    e.Message.Log("emotes");
                }
            });
        }
Пример #4
0
 public static void EmoteAdded()
 {
     EmotesLoaded?.Invoke(null, EventArgs.Empty);
 }