public KancollePreload() { var cache = StaticObjects.Db.GetCacheAsync(GetGameNames()[0]).GetAwaiter().GetResult().ToList(); foreach (string name in Kancolle.GetShips()) { if (!cache.Any(x => x.id == name)) { try { // Get URL string shipUrl = "https://kancolle.fandom.com/wiki/" + name + "/Gallery"; string html = StaticObjects.HttpClient.GetStringAsync(shipUrl).GetAwaiter().GetResult(); // TODO: There are some issues for ships like Imuya that are called I-168 by the wikia (even if it's her "real" name we need to accept both) var result = new QuizzPreloadResult(Regex.Match(html, "https:\\/\\/vignette\\.wikia\\.nocookie\\.net\\/kancolle\\/images\\/[0-9a-z]+\\/[0-9a-z]+\\/" + name + "_Full\\.png").Value, new[] { name }); 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 {name}:\n" + e.Message, e)); } Thread.Sleep(250); // We wait a bit to not spam the HTTP requests } } _preload = cache.ToArray(); }
public void Init() { var cache = StaticObjects.Db.GetCacheAsync(Name).GetAwaiter().GetResult().ToList(); // Item1 is name to be used in URL // Item2 is answer name foreach (var tDoll in GirlsFrontline.GetTDolls()) { if (!cache.Any(x => x.id == tDoll.Item2)) { try { // Get URL string shipUrl = "http://iopwiki.com/wiki/File:" + tDoll.Item1 + ".png"; string html = StaticObjects.HttpClient.GetStringAsync(shipUrl).GetAwaiter().GetResult(); Match m = Regex.Match(html, "src=\"(\\/images\\/thumb\\/[^\"]+)\""); var result = new QuizzPreloadResult("http://iopwiki.com" + m.Groups[1].Value, new[] { tDoll.Item2 }); // Not sure if the Replace is necessary but it was here in the V2 StaticObjects.Db.SetCacheAsync(Name, result).GetAwaiter().GetResult(); cache.Add(result); } catch (System.Exception e) { _ = Log.LogErrorAsync(new System.Exception($"Error while preloading {tDoll.Item1}:\n" + e.Message, e), null); } Thread.Sleep(250); // We wait a bit to not spam the HTTP requests } } _preload = cache.ToArray(); }
public void Init() { var cache = StaticObjects.Db.GetCacheAsync(Name).GetAwaiter().GetResult().ToList(); foreach (string name in Kancolle.GetShips()) { if (!cache.Any(x => x.id == name)) { try { // Get URL string shipUrl = "https://kancolle.fandom.com/wiki/" + name; string html = StaticObjects.HttpClient.GetStringAsync(shipUrl).GetAwaiter().GetResult(); var result = new QuizzPreloadResult(Regex.Match(html, "https:\\/\\/vignette\\.wikia\\.nocookie\\.net\\/kancolle\\/images\\/[0-9a-z]+\\/[0-9a-z]+\\/[^-]*-Battle_Start\\.ogg").Value, new[] { name }); StaticObjects.Db.SetCacheAsync(Name, result).GetAwaiter().GetResult(); cache.Add(result); } catch (System.Exception e) { _ = Log.LogErrorAsync(new System.Exception($"Error while preloading {name}:\n" + e.Message, e), null); } Thread.Sleep(250); // We wait a bit to not spam the HTTP requests } } _preload = cache.ToArray(); }
public PokemonPreload() { var cache = StaticObjects.Db.GetCacheAsync(GetGameNames()[0]).GetAwaiter().GetResult().ToList(); foreach (var elem in Pokemon.GetPokemons()) { if (!cache.Any(x => x.id == elem)) { try { string html; html = StaticObjects.HttpClient.GetStringAsync("https://pokemondb.net/pokedex/" + elem).GetAwaiter().GetResult(); string french = Regex.Match(html, "<th>French<\\/th>[^<]*<td>([^<]+)<\\/td>").Groups[1].Value; string japanese = Regex.Match(html, "<th>Japanese<\\/th>[^<]*<td>[^\\(]+\\(([^\\)]+)\\)<\\/td>").Groups[1].Value; string german = Regex.Match(html, "<th>German<\\/th>[^<]*<td>([^<]+)<\\/td>").Groups[1].Value; var result = new QuizzPreloadResult("https://img.pokemondb.net/artwork/" + elem + ".jpg", new[] { elem, french, japanese, german }); 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}:\n" + e.Message, e)); } Thread.Sleep(250); // We wait a bit to not spam the HTTP requests } } _preload = cache.ToArray(); }
public async Task SetCacheAsync(string name, QuizzPreloadResult value) { if (!await _r.Db(_dbName).TableList().Contains("Cache_" + name).RunAsync <bool>(_conn)) { await _r.Db(_dbName).TableCreate("Cache_" + name).RunAsync(_conn); } await _r.Db(_dbName).Table("Cache_" + name).Insert(value).RunAsync(_conn); }
protected override string[] GetPostInternal() { base.GetPostInternal(); var results = _booru.GetRandomPostsAsync(10, _current.ImageUrl).GetAwaiter().GetResult(); results = results.Where(x => _allowedFormats.Contains(Path.GetExtension(x.fileUrl.AbsoluteUri)) && !x.tags.Contains("western") && !x.tags.Contains("web")).ToArray(); if (results.Length == 0) { throw new IndexOutOfRangeException("No result with correct format found"); } var result = results[StaticObjects.Random.Next(results.Length)]; List <string> answers = new List <string>(); foreach (var t in result.tags) { var name = _booru.ToString() + "_" + t; if (StaticObjects.QuizzTagsCache.ContainsKey(name)) { if (StaticObjects.QuizzTagsCache[name] == BooruSharp.Search.Tag.TagType.Copyright) { answers.Add(t); } } else { var info = _booru.GetTagAsync(t).GetAwaiter().GetResult(); lock (StaticObjects.QuizzTagsCache) { StaticObjects.QuizzTagsCache.Add(name, info.type); } if (info.type == BooruSharp.Search.Tag.TagType.Copyright) { answers.Add(t); } } } if (answers.Count == 0) { throw new IndexOutOfRangeException("No answer found for " + result.postUrl.AbsoluteUri); } _current = new QuizzPreloadResult(_current.ImageUrl, answers.ToArray()); return(new[] { result.fileUrl.AbsoluteUri }); }
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(); }
public FateGOPreload() { var cache = StaticObjects.Db.GetCacheAsync(GetGameNames()[0]).GetAwaiter().GetResult().ToList(); foreach (var tmp in FateGO.GetCharacters()) { string elem = tmp; elem = HttpUtility.UrlDecode(elem).Replace("&", "&").Replace("'", "'"); if (!cache.Any(x => x.id == elem)) { try { string html = StaticObjects.HttpClient.GetStringAsync("https://fategrandorder.fandom.com/wiki/" + elem).GetAwaiter().GetResult(); List <string> allAnswer = new List <string>(); allAnswer.Add(elem); string cleanAnswer = Common.RemoveAccents(elem); if (elem != cleanAnswer) { allAnswer.Add(cleanAnswer); } if (html.Contains("AKA:")) // Alternative answers { foreach (string s in Regex.Replace(html.Split(new[] { "AKA:</b></span>" }, StringSplitOptions.None)[1].Split(new[] { "</td>" }, StringSplitOptions.None)[0], "\\([^\\)]+\\)", "") .Split(new[] { ",", "<br />" }, StringSplitOptions.RemoveEmptyEntries)) { string name = s; Match m = Regex.Match(name, "<[^>]+>([^<]+)<\\/[^>]+>"); if (m.Success) { name = m.Groups[1].Value; } name = Regex.Replace(name, "<[^>]+>", ""); name = Regex.Replace(name, "<\\/[^>]+>", ""); foreach (string sName in name.Split(',')) { if (!string.IsNullOrWhiteSpace(sName)) { string akaName = sName.Trim(); allAnswer.Add(akaName); string cleanAka = Common.RemoveAccents(akaName); if (akaName != cleanAka) { allAnswer.Add(cleanAka); } } } } } var result = new QuizzPreloadResult(Regex.Match(html.Split(new[] { "pi-image-collection-tab-content current" }, StringSplitOptions.None)[1], "<a href=\"([^\"]+)\"").Groups[1].Value.Split(new string[] { "/revision" }, StringSplitOptions.None)[0], allAnswer.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}:\n" + e.Message, e)); } Thread.Sleep(250); // We wait a bit to not spam the HTTP requests } } _preload = cache.ToArray(); }