Exemplo n.º 1
0
        public void Init()
        {
            var cache = StaticObjects.Db.GetCacheAsync(Name).GetAwaiter().GetResult().ToList();

            foreach (var elem in AzurLane.GetShips())
            {
                if (!cache.Any(x => x.id == elem.Item2))
                {
                    try
                    {
                        // Item1: href
                        // Item2: name

                        // Get URL
                        var regexData = elem.Item1[5..].Replace("(", "%28").Replace(")", "%29");
Exemplo n.º 2
0
        public AzurLanePreload()
        {
            var cache = StaticObjects.Db.GetCacheAsync(GetGameNames()[0]).GetAwaiter().GetResult().ToList();

            foreach (var elem in AzurLane.GetShips())
            {
                if (!cache.Any(x => x.id == elem.Item2))
                {
                    try
                    {
                        // Item1: href
                        // Item2: name

                        // Get URL
                        var htmlValue = Regex.Match(StaticObjects.HttpClient.GetStringAsync("https://azurlane.koumakan.jp/" + elem.Item1).GetAwaiter().GetResult(), "src=\"(\\/w\\/images\\/thumb\\/[^\\/]+\\/[^\\/]+\\/[^\\/]+\\/[0-9]+px-" + elem.Item1 + ".png)").Groups[1].Value;

                        // Names
                        List <string> names = new List <string> {
                            elem.Item2
                        };
                        if (elem.Item2 == "HMS_Neptune" || elem.Item2 == "HDN_Neptune")
                        {
                            names.Add("Neptune"); // Both ship are named "Neptune" ingame
                        }
                        var escapeName = Common.RemoveAccents(elem.Item2);
                        if (escapeName != elem.Item2)
                        {
                            names.Add(escapeName);
                        }

                        var result = new QuizzPreloadResult("https://azurlane.koumakan.jp" + htmlValue, names.ToArray());
                        StaticObjects.Db.SetCacheAsync(GetGameNames()[0], result).GetAwaiter().GetResult();
                        cache.Add(result);
                    }
                    catch (System.Exception e)
                    {
                        _ = Log.ErrorAsync(new LogMessage(LogSeverity.Error, e.Source, $"Error while preloading {elem.Item1}:\n" + e.Message, e));
                    }
                    Thread.Sleep(250); // We wait a bit to not spam the HTTP requests
                }
            }
            _preload = cache.ToArray();
        }