public KancolleAudioPreload() { var cache = StaticObjects.Db.GetCacheAsync(GetGameNames()[0] + "_" + GetNameArg()).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(GetGameNames()[0] + "_" + GetNameArg(), 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 async Task playShiritori(params string[] gameName) { p.doAction(Context.User, Context.Guild.Id, Program.Module.Game); if (p.games.Any(x => x.m_chan == Context.Channel)) { await ReplyAsync(Sentences.gameAlreadyRunning(Context.Guild.Id)); } else { string finalGameName = Program.addArgs(gameName); if (finalGameName == null || (finalGameName.ToLower() != "shiritori" && finalGameName.ToLower() != "kancolle" && finalGameName.ToLower() != "booru")) { await ReplyAsync(Sentences.invalidGameName(Context.Guild.Id)); } else { if (!p.gameThread.IsAlive) { p.gameThread.Start(); } Game g = null; if (finalGameName.ToLower() == "shiritori") { await ReplyAsync(Sentences.rulesShiritori(Context.Guild.Id)); g = new Shiritori(Context.Channel, Context.Guild, Context.User); } else if (finalGameName.ToLower() == "kancolle") { await ReplyAsync(Sentences.rulesKancolle(Context.Guild.Id)); g = new Kancolle(Context.Channel, Context.Guild, Context.User); } else if (finalGameName.ToLower() == "booru") { if (!(Context.Channel as ITextChannel).IsNsfw) { await ReplyAsync(Sentences.chanIsNotNsfw(Context.Guild.Id)); return; } await ReplyAsync(Sentences.rulesBooru(Context.Guild.Id)); g = new BooruGame(Context.Channel, Context.Guild, Context.User); } p.games.Add(g); g.Post(); } } }