public override async void isCorrect(string name, ulong userId) { if (timeQuestion == DateTime.MinValue) { await chan.SendMessageAsync("Please wait until I posted all the images."); } else { tagAttempt++; Character me = null; foreach (Character c in b.relations) { if (c.getName() == userId) { me = c; break; } } if (toGuess == BooruModule.fixName(name)) { timeQuestion = DateTime.MinValue; if (isRatingAll) { me.increaseGuessBooruAll(true); } else { me.increaseGuessBooruAll(true); } if (!userIds.Contains(userId)) { userIds.Add(userId); } await chan.SendMessageAsync("Congratulation, you found the right answer!" + Environment.NewLine + "I'll download the 3 next images."); post(); tagFound++; } else { if (isRatingAll) { me.increaseGuessBooruAll(false); } else { me.increaseGuessBooruAll(false); } await chan.SendMessageAsync("No, this is not " + name + "."); } } }
public override async void post() { try { int randomNbMax; string randomTag = ""; string xml = ""; int randomP; string li; string directory = "Saves/booruAnalysis/"; if (isRatingAll) { directory += "Gelbooru/"; } else { directory += "Safebooru/"; } string[] allFiles = Directory.GetFiles(directory); while (true) { try { string[] datas = File.ReadAllLines(allFiles[b.rand.Next(0, allFiles.Length)]); if (datas[0] == "0") { randomTag = datas[4]; break; } } catch (IndexOutOfRangeException) { } } List <string> urls = new List <string>(); try { if (isRatingAll) { xml = BooruModule.getWebRequest("https://gelbooru.com/index.php?page=dapi&s=post&q=index&limit=1&tags=" + randomTag); } else { xml = BooruModule.getWebRequest("http://safebooru.org/index.php?page=dapi&s=post&q=index&limit=1&tags=" + randomTag); } randomNbMax = Convert.ToInt32(BooruModule.getElementXml("posts count=\"", "", xml, '"')) - 1; } catch (FormatException) { await chan.SendMessageAsync("The website refused to give me an image, please retry again later."); loose(); return; } for (int y = 0; y < 3; y++) { string url; randomP = b.rand.Next(randomNbMax) + 1; if (isRatingAll) { li = "https://gelbooru.com/index.php?page=dapi&s=post&q=index&pid=" + randomP + "&limit=1&tags=" + randomTag; xml = BooruModule.getWebRequest(li); url = BooruModule.getElementXml("file_url=\"", "", xml, '"'); } else { li = "http://safebooru.org/index.php?page=dapi&s=post&q=index&pid=" + randomP + "&limit=1&tags=" + randomTag; xml = BooruModule.getWebRequest(li); url = BooruModule.getElementXml("file_url=\"//", "https://", xml, '"'); } urls.Add(url); } List <string> toDelete = new List <string>(); int i = 0; foreach (string s in urls) { int currentTime = Convert.ToInt32(DateTime.Now.ToString("HHmmss")); using (var client = new WebClient()) { client.DownloadFile(s, "imageKonachan" + currentTime + i + "." + s.Split('.')[s.Split('.').Length - 1]); } FileInfo file = new FileInfo("imageKonachan" + currentTime + i + "." + s.Split('.')[s.Split('.').Length - 1]); if (file.Length >= 8000000) { await chan.SendMessageAsync("I wasn't able to send one of the images since its size was superior to 8MB."); File.Delete("imageKonachan" + currentTime + i + "." + s.Split('.')[s.Split('.').Length - 1]); } else { toDelete.Add("imageKonachan" + currentTime + i + "." + s.Split('.')[s.Split('.').Length - 1]); } i++; } foreach (string s in toDelete) { await chan.SendFileAsync(s); File.Delete(s); } toGuess = BooruModule.fixName(randomTag); timeQuestion = DateTime.Now; } catch (WebException) { lost = true; await chan.SendMessageAsync("An error occured while trying to request an image, I can't continue this game, sorry..."); } }