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..."); } }
public async Task charac(string shipName) { p.doAction(Context.User, Context.Guild.Id, Program.Module.Kancolle); IGuildUser me = await Context.Guild.GetUserAsync(329664361016721408); // Sanara if (!me.GuildPermissions.AttachFiles) { await ReplyAsync("Sorry but I need to permission to attach files to do this here."); } else { string url = "https://kancolle.wikia.com/api/v1/Search/List?query=" + shipName + "&limit=1"; try { using (WebClient w = new WebClient()) { w.Encoding = Encoding.UTF8; List <string> finalStr = new List <string>(); finalStr.Add(""); ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; string json = w.DownloadString(url); string code = BooruModule.getElementXml("\"id\":", "", json, ','); url = "http://kancolle.wikia.com/api/v1/Articles/Details?ids=" + code; json = w.DownloadString(url); string image = BooruModule.getElementXml("\"thumbnail\":\"", "", json, '"'); url = "http://kancolle.wikia.com/wiki/" + BooruModule.getElementXml("\"title\":\"", "", json, '"') + "?action=raw"; json = w.DownloadString(url); if (BooruModule.getElementXml("{{", "", json, '}') != "ShipPageHeader") { await ReplyAsync("I didn't find any shipgirl with this name."); return; } image = image.Split(new string[] { ".jpg" }, StringSplitOptions.None)[0] + ".jpg"; image = image.Replace("\\", ""); int currentTime = Convert.ToInt32(DateTime.Now.ToString("HHmmss")); w.DownloadFile(image, "shipgirl" + currentTime + ".jpg"); url = "http://kancolle.wikia.com/api/v1/Articles/AsSimpleJson?id=" + code; json = w.DownloadString(url); string[] jsonInside = json.Split(new string[] { "\"title\"" }, StringSplitOptions.None); int currI = 0; foreach (string s in jsonInside) { if (s.Contains("Personality")) { finalStr[0] += "**Personality**" + Environment.NewLine; string[] allExplanations = s.Split(new string[] { "\"te" }, StringSplitOptions.None); foreach (string str in allExplanations) { string per = BooruModule.getElementXml("xt\":\"", "", str, '"'); if (per != "") { finalStr[0] += per + Environment.NewLine; } } break; } } foreach (string s in jsonInside) { if (s.Contains("Appearance")) { finalStr[0] += Environment.NewLine + "**Appearance**" + Environment.NewLine; string[] allExplanations = s.Split(new string[] { "\"te" }, StringSplitOptions.None); foreach (string str in allExplanations) { string per = BooruModule.getElementXml("xt\":\"", "", str, '"'); if (per != "") { if (finalStr[currI].Length > 1500) { currI++; finalStr.Add(""); } finalStr[currI] += per + Environment.NewLine; } } break; } } foreach (string s in jsonInside) { if (s.Contains("Second Remodel")) { finalStr[0] += "**Second Remodel**" + Environment.NewLine; string[] allExplanations = s.Split(new string[] { "\"te" }, StringSplitOptions.None); foreach (string str in allExplanations) { string per = BooruModule.getElementXml("xt\":\"", "", str, '"'); if (per != "") { if (finalStr[currI].Length > 1500) { currI++; finalStr.Add(""); } finalStr[currI] += per + Environment.NewLine; } } break; } } foreach (string s in jsonInside) { if (s.Contains("Trivia")) { finalStr[currI] += Environment.NewLine + "**Trivia**" + Environment.NewLine; string[] allExplanations = s.Split(new string[] { "\"te" }, StringSplitOptions.None); foreach (string str in allExplanations) { string per = BooruModule.getElementXml("xt\":\"", "", str, '"'); if (per != "") { if (finalStr[currI].Length > 1500) { currI++; finalStr.Add(""); } finalStr[currI] += per + Environment.NewLine; } } break; } } await Context.Channel.SendFileAsync("shipgirl" + currentTime + ".jpg"); foreach (string s in finalStr) { await ReplyAsync(Regex.Replace( s, @"\\[Uu]([0-9A-Fa-f]{4})", m => char.ToString( (char)ushort.Parse(m.Groups[1].Value, NumberStyles.AllowHexSpecifier)))); // Replace \\u1313 by \u1313 } File.Delete("shipgirl" + currentTime + ".jpg"); } } catch (WebException ex) { HttpWebResponse code = ex.Response as HttpWebResponse; if (code.StatusCode == HttpStatusCode.NotFound) { await ReplyAsync("I didn't find any shipgirl with this name."); } } } }
private void learnShiritori() { int nbCharacs = rand.Next(2, 11); string finalStr = ""; for (int i = 0; i < nbCharacs; i++) { finalStr += (char)(rand.Next(0x3041, 0x3095)); } string json; using (WebClient wc = new WebClient()) { wc.Encoding = Encoding.UTF8; json = wc.DownloadString("http://www.jisho.org/api/v1/search/words?keyword=" + finalStr); } string code = BooruModule.getElementXml("status\":", "", json, '}'); string word = BooruModule.getElementXml("english_definitions\":[", "", json, ']'); string type = BooruModule.getElementXml("parts_of_speech\":[\"", "", json, '"'); if (word == "") { notWord++; } else if (type != "Noun") { notNoun++; } else { string hiragana = BooruModule.getElementXml("\"reading\":\"", "", json, '"'); word = hiragana + "$" + word; if (hiragana.Length == 1) { tooShort++; } else if (hiragana[hiragana.Length - 1] == 'ん') { invalidWord++; } else { bool alreadyKnowed = false; foreach (string s in knowedWords) { if (hiragana == s.Split('$')[0]) { alreadyKnowed = true; break; } } if (alreadyKnowed) { alreadyKnow++; } else { knowedWords.Add(word); newWords++; } } } }
public async Task debugInfos() { p.doAction(Context.User, Context.Guild.Id, Program.Module.Debug); await ReplyAsync("Here are the debug informations for each modules:" + Environment.NewLine); string infosDebug; // GENERAL infosDebug = "**General**:" + Environment.NewLine; string dateCrea = File.ReadAllLines("Saves/sanaraDatas.dat")[0]; string serverJoined = File.ReadAllLines("Saves/Servers/" + Context.Guild.Id + "/serverDatas.dat")[0]; string dateCreafull = dateCrea.Substring(0, 2) + "/" + dateCrea.Substring(2, 2) + "/" + dateCrea.Substring(4, 2) + " at " + dateCrea.Substring(6, 2) + ":" + dateCrea.Substring(8, 2) + ":" + dateCrea.Substring(10, 2); string serverJoinedFull = serverJoined.Substring(0, 2) + "/" + serverJoined.Substring(2, 2) + "/" + serverJoined.Substring(4, 2) + " at " + serverJoined.Substring(6, 2) + ":" + serverJoined.Substring(8, 2) + ":" + serverJoined.Substring(10, 2); int userMet = 0; int userKnow = 0; string mostSpeakUser = "******"; int nbMessages = 0; int totalMessages = 0; foreach (string s in Directory.GetFiles("Saves/Users/")) { userMet++; string[] details = File.ReadAllLines(s); if (details[2] != "No") { userKnow++; totalMessages += Convert.ToInt32(details[3]); if (mostSpeakUser == "0" || Convert.ToInt32(details[3]) > nbMessages) { mostSpeakUser = details[0]; nbMessages = Convert.ToInt32(details[3]); } } } int[] percentageModules = new int[(int)Program.Module.Youtube + 1]; int total = 0; for (int i = 0; i < (int)Program.Module.Youtube + 1; i++) { percentageModules[i] = Convert.ToInt32(File.ReadAllText("Saves/Servers/" + Context.Guild.Id + "/ModuleCount/" + DateTime.UtcNow.ToString("yyyyMM") + "/" + ((Program.Module)i).ToString()[0] + ((Program.Module)i).ToString().ToLower().Substring(1, ((Program.Module)i).ToString().Length - 1) + ".dat")); total += percentageModules[i]; } string lastVersion = Directory.GetFiles("Logs/")[Directory.GetFiles("Logs/").Length - 1]; infosDebug += "Creator: Zirk#1001." + Environment.NewLine + "Creation date: 28/06/17 UTC+0 (My first memories are from the " + dateCreafull + " UTC+0)." + Environment.NewLine + "Server joined: " + ((dateCrea == serverJoined) ? ("I don't remember, sorry...") : (serverJoinedFull + " UTC+0")) + "." + Environment.NewLine + "Messages received: " + totalMessages + "." + Environment.NewLine + "(The user who sent me more messages is " + mostSpeakUser + " with " + nbMessages + " messages)." + Environment.NewLine + "Users know: " + userMet + " (I already spoked with " + userKnow + " of them)." + Environment.NewLine + "Servers know: " + Directory.GetDirectories("Saves/Servers/").Length + " (" + p.client.Guilds.Count + " of them are available)." + Environment.NewLine + "Here's the percentage of utilisation for each module for this month on this server:" + Environment.NewLine; for (int i = 0; i < (int)Program.Module.Youtube + 1; i++) { infosDebug += ((Program.Module)i).ToString()[0] + ((Program.Module)i).ToString().ToLower().Substring(1, ((Program.Module)i).ToString().Length - 1) + ": " + (percentageModules[i] * 100 / total) + "%" + Environment.NewLine; } infosDebug += "Version: " + lastVersion.Split('/')[lastVersion.Split('/').Length - 1].Substring(0, lastVersion.Split('/')[lastVersion.Split('/').Length - 1].Length - 4) + "." + Environment.NewLine + "Last changes: " + Environment.NewLine + File.ReadAllText(lastVersion) + Environment.NewLine; // ARENA /*string nbSeason = File.ReadAllLines("Saves/Arena/currSeason.dat")[0]; * string[] stats = File.ReadAllLines("Saves/Arena/Season" + nbSeason + "/scores.dat"); * string first; * if (Context.Guild.Id != 146701031227654144) * first = "Arena isn't available on this server."; * else * { * string bestPlayer = ""; * int ratio = -1; * foreach (string str in stats) * { * string[] s = str.Split(' '); * int currRatio = Convert.ToInt32(s[1]) * 100 / Convert.ToInt32(s[2]); * if (currRatio > ratio && Convert.ToInt32(s[2]) >= 10) * { * bestPlayer = (await Context.Guild.GetUserAsync(Convert.ToUInt64(s[0]))).Username; * ratio = currRatio; * } * } * if (ratio == -1) * first = "Not one meet the requirement to be the next arena's champion."; * else * first = "The current best player is " + bestPlayer + " with a winning ratio of " + ratio + "%."; * } * infosDebug += "**Arena**:" + Environment.NewLine + * //"There are currently " + nbWeapons + " weapons and " + nbItems + " items available." + Environment.NewLine + * "There is a total of " + stats.Length + " bots who fought for the season " + nbSeason + "." + Environment.NewLine + * first + Environment.NewLine;*/ //infosDebug += "**Arena**:" + Environment.NewLine + //"The arena isn't available yet but will be back soon (50%)." + Environment.NewLine; // BOORU double latenceKona, latenceGel, latenceLoli, latenceSafe; DateTime now = DateTime.UtcNow; string konaImages = BooruModule.getWebRequest("https://www.konachan.com/post.xml?limit=1"); // KONACHAN latenceKona = DateTime.UtcNow.Subtract(now).TotalMilliseconds; now = DateTime.UtcNow; string gelImages = BooruModule.getWebRequest("https://gelbooru.com/index.php?page=dapi&s=post&q=index&limit=1"); // GELBOORU latenceGel = DateTime.UtcNow.Subtract(now).TotalMilliseconds; now = DateTime.UtcNow; string loliImages = BooruModule.getWebRequest("https://lolibooru.moe/post.xml?limit=1"); // LOLIBOORU latenceLoli = DateTime.UtcNow.Subtract(now).TotalMilliseconds; now = DateTime.UtcNow; string safeImages = BooruModule.getWebRequest("http://safebooru.org/index.php?page=dapi&s=post&q=index&limit=1"); // SAFEBOORU latenceSafe = DateTime.UtcNow.Subtract(now).TotalMilliseconds; int konachanImages = Convert.ToInt32(BooruModule.getElementXml("posts count=\"", "", konaImages, '"')); int gelbooruImages; try { gelbooruImages = Convert.ToInt32(BooruModule.getElementXml("posts count=\"", "", gelImages, '"')); } catch (FormatException) { gelbooruImages = -1; } int lolibooruImages = Convert.ToInt32(BooruModule.getElementXml("posts count=\"", "", loliImages, '"')); int safebooruImages = Convert.ToInt32(BooruModule.getElementXml("posts count=\"", "", safeImages, '"')); string[] booruTimeSpent = File.ReadAllLines("Saves/booruAnalysis/stats.dat"); double seconds = Convert.ToDouble(booruTimeSpent[0]); int hour = (int)(seconds / 3600); int minutes = (int)(seconds % 3600) / 60; int second = (int)(seconds % 3600) % 60; string finalTime = ""; if (hour > 0) { finalTime += hour + " hours, "; } if (minutes > 0 || hour > 0) { finalTime += minutes + " minutes and "; } finalTime += second + " seconds."; string[] progBooru = File.ReadAllLines("Saves/booruAnalysis/stats.dat"); infosDebug += "**Booru**:" + Environment.NewLine + "Konachan's latence: " + Math.Round(latenceKona) + "ms (" + konachanImages.ToString("N0", System.Globalization.CultureInfo.GetCultureInfo("fr")) + " images available)." + Environment.NewLine; if (gelbooruImages == -1) { infosDebug += "Gelbooru's latence: The API was disabled." + Environment.NewLine; } else { infosDebug += "Gelbooru's latence: " + Math.Round(latenceGel) + "ms (" + gelbooruImages.ToString("N0", System.Globalization.CultureInfo.GetCultureInfo("fr")) + " images available)." + Environment.NewLine; } infosDebug += "Lolibooru's latence: " + Math.Round(latenceLoli) + "ms (" + lolibooruImages.ToString("N0", System.Globalization.CultureInfo.GetCultureInfo("fr")) + " images available)." + Environment.NewLine + "Safebooru's latence: " + Math.Round(latenceSafe) + "ms (" + safebooruImages.ToString("N0", System.Globalization.CultureInfo.GetCultureInfo("fr")) + " images available)." + Environment.NewLine + "Time spent on learning tags: " + finalTime + Environment.NewLine + "Konachan completion rate: " + (Convert.ToSingle(progBooru[1]) * 100 / konachanImages).ToString("0.0", System.Globalization.CultureInfo.InvariantCulture) + "%." + Environment.NewLine; if (gelbooruImages == -1) { infosDebug += "Gelbooru completion rate: Unknowed." + Environment.NewLine; } else { infosDebug += "Gelbooru completion rate: " + (Convert.ToSingle(progBooru[2]) * 100 / gelbooruImages).ToString("0.0", System.Globalization.CultureInfo.InvariantCulture) + "%." + Environment.NewLine; } infosDebug += "Lolibooru completion rate: " + (Convert.ToSingle(progBooru[3]) * 100 / lolibooruImages).ToString("0.0", System.Globalization.CultureInfo.InvariantCulture) + "%." + Environment.NewLine + "Safebooru completion rate: " + (Convert.ToSingle(progBooru[4]) * 100 / safebooruImages).ToString("0.0", System.Globalization.CultureInfo.InvariantCulture) + "%." + Environment.NewLine; // CONSOLE infosDebug += "**Code**:" + Environment.NewLine; infosDebug += "This module isn't finish yet..." + Environment.NewLine; // COMMUNICATION infosDebug += "**Communication**:" + Environment.NewLine; infosDebug += "No information available." + Environment.NewLine; // CONSOLE infosDebug += "**Console**:" + Environment.NewLine; infosDebug += "No information available." + Environment.NewLine; // DEBUG PerformanceCounter cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total"); PerformanceCounter ramCounter = new PerformanceCounter("Memory", "Available MBytes"); infosDebug += "**Debug**:" + Environment.NewLine + "CPU usage: " + cpuCounter.NextValue() + "%." + Environment.NewLine + "RAM usage: " + ramCounter.NextValue() + " MB." + Environment.NewLine; EmbedBuilder embed = new EmbedBuilder() { Description = infosDebug, Color = Color.Purple, }; await ReplyAsync("", false, embed); infosDebug = ""; // GAME // KANCOLLE int totalGames = 0; int hightestScore = 0; string[] myDatas = File.ReadAllLines("Saves/Servers/" + Context.Guild.Id + "/kancolle.dat"); int scoreHere = Convert.ToInt32(myDatas[3]); int totalGamesHere = Convert.ToInt32(myDatas[0]); string bestIdKancolle = myDatas[4]; foreach (string s in Directory.GetDirectories("Saves/Servers/")) { string[] infos = File.ReadAllLines(s + "/kancolle.dat"); totalGames += Convert.ToInt32(infos[0]); if (Convert.ToInt32(infos[3]) > hightestScore) { hightestScore = Convert.ToInt32(infos[3]); bestIdKancolle = infos[4]; } } List <string> finalBestIdKancolle = new List <string>(); // BOORU int totalGamesBooruAll = 0; int hightestScoreBooruAll = 0; myDatas = File.ReadAllLines("Saves/Servers/" + Context.Guild.Id + "/quizzTagAll.dat"); int scoreHereBooruAll = Convert.ToInt32(myDatas[3]); int totalGamesHereBooruAll = Convert.ToInt32(myDatas[0]); string bestIdBooruAll = myDatas[4]; foreach (string s in Directory.GetDirectories("Saves/Servers/")) { try { string[] infos = File.ReadAllLines(s + "/quizzTagAll.dat"); totalGamesBooruAll += Convert.ToInt32(infos[0]); if (Convert.ToInt32(infos[3]) > hightestScoreBooruAll) { hightestScoreBooruAll = Convert.ToInt32(infos[3]); bestIdBooruAll = infos[4]; } } catch (FileNotFoundException) { } } string[] bestIdBooruAllStr = bestIdBooruAll.Split('|'); List <string> finalBestIdBooruAll = new List <string>(); int totalGamesBooruSafe = 0; int hightestScoreBooruSafe = 0; myDatas = File.ReadAllLines("Saves/Servers/" + Context.Guild.Id + "/quizzTagSafe.dat"); int scoreHereBooruSafe = Convert.ToInt32(myDatas[3]); int totalGamesHereBooruSafe = Convert.ToInt32(myDatas[0]); string bestIdBooruSafe = myDatas[4]; foreach (string s in Directory.GetDirectories("Saves/Servers/")) { try { string[] infos = File.ReadAllLines(s + "/quizzTagSafe.dat"); totalGamesBooruSafe += Convert.ToInt32(infos[0]); if (Convert.ToInt32(infos[3]) > hightestScoreBooruSafe) { hightestScoreBooruSafe = Convert.ToInt32(infos[3]); bestIdBooruSafe = infos[4]; } } catch (FileNotFoundException) { } } string[] bestIdBooruSafeStr = bestIdBooruSafe.Split('|'); List <string> finalBestIdBooruSafe = new List <string>(); int nbGamesShiritori = 0; int bestScore = 0; string whoHaveBestScore = ""; foreach (string s in Directory.GetFiles("Saves/Users/")) { try { string[] datas = File.ReadAllLines(s); nbGamesShiritori += Convert.ToInt32(datas[11]); int score = Convert.ToInt32(datas[14]); if (score > bestScore) { bestScore = score; whoHaveBestScore = datas[0]; } string id = datas[1]; id = id.Substring(0, id.Length - 4); if (bestIdKancolle.Contains(id) && id != "0") { finalBestIdKancolle.Add(datas[0]); } if (bestIdBooruAll.Contains(id) && id != "0") { finalBestIdBooruAll.Add(datas[0]); } if (bestIdBooruSafe.Contains(id) && id != "0") { finalBestIdBooruSafe.Add(datas[0]); } } catch (Exception) // Account with id '0' { } } bestIdKancolle = ""; if (finalBestIdKancolle.Count == 0) { bestIdKancolle = "nobody"; } else if (finalBestIdKancolle.Count < 2) { bestIdKancolle = finalBestIdKancolle[0]; } else { for (int i = 0; i < finalBestIdKancolle.Count - 1; i++) { bestIdKancolle += finalBestIdKancolle[i] + ", "; } bestIdKancolle = bestIdKancolle.Substring(0, bestIdKancolle.Length - 2); bestIdKancolle += " and " + finalBestIdKancolle[finalBestIdKancolle.Count - 1]; } bestIdBooruAll = ""; if (finalBestIdBooruAll.Count == 0) { bestIdBooruAll = "nobody"; } else if (finalBestIdBooruAll.Count < 2) { bestIdBooruAll = finalBestIdBooruAll[0]; } else { for (int i = 0; i < finalBestIdBooruAll.Count - 1; i++) { bestIdBooruAll += finalBestIdBooruAll[i] + ", "; } bestIdBooruAll = bestIdBooruAll.Substring(0, bestIdBooruAll.Length - 2); bestIdBooruAll += " and " + finalBestIdBooruAll[finalBestIdBooruAll.Count - 1]; } bestIdBooruSafe = ""; if (finalBestIdBooruSafe.Count == 0) { bestIdBooruSafe = "nobody"; } else if (finalBestIdBooruSafe.Count < 2) { bestIdBooruSafe = finalBestIdBooruSafe[0]; } else { for (int i = 0; i < finalBestIdBooruSafe.Count - 1; i++) { bestIdBooruSafe += finalBestIdBooruSafe[i] + ", "; } bestIdBooruSafe = bestIdBooruSafe.Substring(0, bestIdBooruSafe.Length - 2); bestIdBooruSafe += " and " + finalBestIdBooruSafe[finalBestIdBooruSafe.Count - 1]; } string[] shiritori = File.ReadAllLines("Saves/shiritoriStats.dat"); seconds = Convert.ToDouble(shiritori[6]); hour = (int)(seconds / 3600); minutes = (int)(seconds % 3600) / 60; second = (int)(seconds % 3600) % 60; finalTime = ""; if (hour > 0) { finalTime += hour + " hours, "; } if (minutes > 0 || hour > 0) { finalTime += minutes + " minutes and "; } finalTime += second + " seconds"; infosDebug += "**Game**:" + Environment.NewLine + "A total of " + (totalGames + nbGamesShiritori + totalGamesBooruAll + totalGamesBooruSafe).ToString() + " games were made, " + totalGames + " games of Kancolle Quizz (" + totalGamesHere + " from this server), " + nbGamesShiritori + " games of shiritori, " + (totalGamesBooruSafe + totalGamesBooruAll) + " games of Booru quizz (" + totalGamesBooruSafe + " safe, " + totalGamesBooruAll + " with all rating)." + Environment.NewLine + "Kancolle Quizz: There are " + p.names.Count + " ships available." + Environment.NewLine + " " + ((scoreHere == hightestScore) ? ("This server currently have the best score with a score of " + scoreHere + " point" + ((Convert.ToInt32(scoreHere) > 1) ? ("s") : ("")) + ".") : ("The best score is " + hightestScore + " point" + ((Convert.ToInt32(hightestScore) > 1) ? ("s") : ("")) + " and is from another server. The best score here is " + scoreHere + "point" + ((Convert.ToInt32(scoreHere) > 1) ? ("s") : ("")) + ".")) + Environment.NewLine + " This score was obtain by " + bestIdKancolle + "." + Environment.NewLine + "Shiritori: The current best score is " + bestScore + " and was obtain by " + whoHaveBestScore + "." + Environment.NewLine + " I actually know " + shiritori[5] + " words." + Environment.NewLine + " I spent " + finalTime + " and " + (Convert.ToInt32(shiritori[0]) + Convert.ToInt32(shiritori[1]) + Convert.ToInt32(shiritori[2]) + Convert.ToInt32(shiritori[3]) + Convert.ToInt32(shiritori[4]) + Convert.ToInt32(shiritori[5])).ToString() + " attempts to learn these words." + Environment.NewLine + " Between all my failed attemps: " + Environment.NewLine + " " + shiritori[0] + " of them were words I already know." + Environment.NewLine + " " + shiritori[1] + " of them weren't real words." + Environment.NewLine + " " + shiritori[2] + " of them weren't nouns." + Environment.NewLine + " " + shiritori[3] + " of them were words finishing by a ん." + Environment.NewLine + " " + shiritori[4] + " of them were words with only 1 character." + Environment.NewLine + "Booru Quizz (safe version):" + Environment.NewLine + " " + ((scoreHereBooruSafe == hightestScoreBooruSafe) ? ("This server currently have the best score with a score of " + scoreHereBooruSafe + " point" + ((Convert.ToInt32(scoreHereBooruSafe) > 1) ? ("s") : ("")) + ".") : ("The best score is " + hightestScoreBooruSafe + " point" + ((Convert.ToInt32(hightestScoreBooruSafe) > 1) ? ("s") : ("")) + " and is from another server. The best score here is " + scoreHereBooruSafe + " point" + ((Convert.ToInt32(scoreHereBooruSafe) > 1) ? ("s") : ("")) + ".")) + Environment.NewLine + " This score was obtain by " + bestIdBooruSafe + "." + Environment.NewLine + "Booru Quizz (all rating version):" + Environment.NewLine + " " + ((scoreHereBooruAll == hightestScoreBooruAll) ? ("This server currently have the best score with a score of " + scoreHereBooruAll + " point" + ((Convert.ToInt32(scoreHereBooruAll) > 1) ? ("s") : ("")) + ".") : ("The best score is " + hightestScoreBooruAll + " point" + ((Convert.ToInt32(hightestScoreBooruAll) > 1) ? ("s") : ("")) + " and is from another server. The best score here is " + scoreHereBooruAll + " point" + ((Convert.ToInt32(scoreHereBooruAll) > 1) ? ("s") : ("")) + ".")) + Environment.NewLine + " This score was obtain by " + bestIdBooruAll + "." + Environment.NewLine; // GOOGLE SHORTENER double latence; bool canSendRequest = true; now = DateTime.UtcNow; UrlshortenerService service = new UrlshortenerService(new BaseClientService.Initializer { ApiKey = File.ReadAllText("Keys/URLShortenerAPIKey.dat"), }); try { using (WebClient wc = new WebClient()) { wc.Encoding = Encoding.UTF8; await service.Url.Get("http://goo.gl/fbsS").ExecuteAsync(); } } catch (GoogleApiException) { canSendRequest = false; } latence = DateTime.UtcNow.Subtract(now).TotalMilliseconds; infosDebug += "**Google Shortener**:" + Environment.NewLine + "Google link shortener's latence: " + Math.Round(latence) + "ms" + ((!canSendRequest) ? (" (exceeded request amount).") : (".")) + Environment.NewLine; // JISHO double latencePaste; now = DateTime.UtcNow; using (WebClient wc = new WebClient()) { wc.Encoding = Encoding.UTF8; wc.DownloadString("http://www.jisho.org/api/v1/search/words"); } latence = DateTime.UtcNow.Subtract(now).TotalMilliseconds; now = DateTime.UtcNow; using (WebClient wc = new WebClient()) { wc.Encoding = Encoding.UTF8; wc.DownloadString("https://pastebin.com/"); } latencePaste = DateTime.UtcNow.Subtract(now).TotalMilliseconds; infosDebug += "**Jisho**:" + Environment.NewLine + "Jisho's latence: " + Math.Round(latence) + "ms." + Environment.NewLine + "Pastebin's latence: " + Math.Round(latencePaste) + "ms." + Environment.NewLine; // KANCOLLE now = DateTime.UtcNow; using (WebClient wc = new WebClient()) { wc.Encoding = Encoding.UTF8; wc.DownloadString("https://kancolle.wikia.com/api/v1/Search/List?query=ryuujou&limit=1"); } latence = DateTime.UtcNow.Subtract(now).TotalMilliseconds; infosDebug += "**Kancolle**:" + Environment.NewLine + "Kancolle wikia's latence: " + Math.Round(latence) + "ms." + Environment.NewLine; // NHENTAI now = DateTime.UtcNow; using (WebClient wc = new WebClient()) { wc.Encoding = Encoding.UTF8; wc.DownloadString("https://nhentai.net/api/galleries/search?query=loli"); } latence = DateTime.UtcNow.Subtract(now).TotalMilliseconds; infosDebug += "**Nhentai**:" + Environment.NewLine + "Nhentai's latence: " + Math.Round(latence) + "ms." + Environment.NewLine; // SETTINGS //DateTime.UtcNow.ToString("yy-MM-dd-HH-mm-ss"); string date = Directory.GetDirectories("Archives/")[Directory.GetDirectories("Archives/").Length - 1]; string fullDate = date.Substring(15, 2) + "/" + date.Substring(12, 2) + "/" + date.Substring(9, 2) + " at " + date.Substring(18, 2) + ":" + date.Substring(21, 2) + ":" + date.Substring(24, 2); infosDebug += "**Settings**:" + Environment.NewLine + "The last archive created is from the " + fullDate + "." + Environment.NewLine; // TASK int nbTasks = 0; int nbCathegories = 0; int nbServers = 0; foreach (string s in Directory.GetDirectories("Saves/Servers/")) { string[] dirs = Directory.GetDirectories(s + "/Tasks/"); if (dirs.Length > 0) { nbServers++; nbCathegories += dirs.Length; } else { continue; } foreach (string s2 in dirs) { nbTasks += Directory.GetFiles(s2).Length; } } infosDebug += "**Task**:" + Environment.NewLine + "There are currently " + nbTasks + " tasks distributed in " + nbCathegories + " categories, and there are " + nbServers + " servers using them." + Environment.NewLine; // YOUTUBE now = DateTime.UtcNow; YouTubeService yt = new YouTubeService(new BaseClientService.Initializer() { ApiKey = File.ReadAllText("Keys/YoutubeAPIKey.dat") }); var searchListRequest = yt.Search.List("snippet"); searchListRequest.ChannelId = "UCYfqOkiuHA1ElyZx7ZvKNMg"; searchListRequest.MaxResults = 50; try { var searchListResult = searchListRequest.Execute(); } catch (Exception) { } latence = DateTime.UtcNow.Subtract(now).TotalMilliseconds; infosDebug += "**Youtube**:" + Environment.NewLine + "Youtube's latence: " + Math.Round(latence) + "ms." + Environment.NewLine; if (Context.User.Id == 144851584478740481) { infosDebug += Environment.NewLine + "I will also send you some additional informations in private message."; } embed = new EmbedBuilder() { Description = infosDebug, Color = Color.Purple, }; await ReplyAsync("", false, embed); if (Context.User.Id == 144851584478740481) { IDMChannel c = await Context.User.GetOrCreateDMChannelAsync(); await c.SendMessageAsync("Here are the debug informations:"); string mpDebug = "Here are all the servers I know: " + Environment.NewLine; foreach (string f in Directory.GetDirectories("Saves/Servers/")) { mpDebug += File.ReadAllLines(f + "/serverDatas.dat")[2] + Environment.NewLine; } mpDebug += Environment.NewLine + "Users (Only if stat > 0):" + Environment.NewLine; int counter = 10; foreach (Character r in p.relations) { if (r.returnInfosValuable() != null) { mpDebug += r.returnInfosValuable() + Environment.NewLine; counter--; if (counter == 0) { counter = 10; await c.SendMessageAsync(mpDebug); mpDebug = ""; } } } await c.SendMessageAsync(mpDebug); } }