public override async void Post() { if (m_currWord == null) { m_currWord = "しりとり"; await m_chan.SendMessageAsync("しりとり (shiritori)"); } else { string[] corrWords = m_words.Where(x => x[0] == m_currWord[m_currWord.Length - 1]).ToArray(); if (corrWords.Length == 0) { await m_chan.SendMessageAsync("I don't know any other word..."); } else { string word = corrWords[Program.p.rand.Next(0, corrWords.Length)]; string[] insideWord = word.Split('$'); await m_chan.SendMessageAsync(insideWord[0] + " (" + LinguistModule.fromHiragana(insideWord[0]) + ") - Meaning: " + insideWord[1]); m_words.Remove(word); m_alreadySaid.Add(insideWord[0]); m_currWord = insideWord[0]; } } m_time = DateTime.Now; }
public async Task debugInfos() { p.doAction(Context.User, Context.Guild.Id, Program.Module.Debug); string infosDebug; // GENERAL infosDebug = "**General**:" + Environment.NewLine; 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]); } } } infosDebug += "Creator: Zirk#1001." + Environment.NewLine + "Creation date: " + (await Context.Channel.GetUserAsync(Sentences.myId)).CreatedAt.ToString("dd/MM/yy HH:mm:ss") + 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 spoke with " + userKnow + " of them)." + Environment.NewLine + "Guilds available: " + p.client.Guilds.Count + "." + Environment.NewLine; EmbedBuilder embed = new EmbedBuilder() { Description = infosDebug, Color = Color.Purple, }; await ReplyAsync("", false, embed.Build()); infosDebug = "**Linguistic Module:**" + Environment.NewLine + "Translation: "; try { if (LinguistModule.getTranslation("cat", "fr", out _).Contains("chat")) { infosDebug += "OK"; } else { infosDebug += "Error"; } } catch (Exception e) { infosDebug += e.ToString().Split(':')[0]; } infosDebug += Environment.NewLine + "Definition: "; try { if (LinguistModule.getAllKanjis("cat")[0].Contains("猫")) { infosDebug += "OK"; } else { infosDebug += "Error"; } } catch (Exception e) { infosDebug += e.ToString().Split(':')[0]; } infosDebug += Environment.NewLine + Environment.NewLine + "**Booru Module:**" + Environment.NewLine + "Safebooru: "; try { if (BooruModule.getBooruUrl(new BooruModule.Safebooru(), new string[] { "hibiki_(kantai_collection)" }).StartsWith("https://")) { infosDebug += "OK"; } else { infosDebug += "Error"; } } catch (Exception e) { infosDebug += e.ToString().Split(':')[0]; } infosDebug += Environment.NewLine + "Gelbooru: "; try { if (BooruModule.getBooruUrl(new BooruModule.Gelbooru(), new string[] { "hibiki_(kantai_collection)" }).StartsWith("https://")) { infosDebug += "OK"; } else { infosDebug += "Error"; } } catch (Exception e) { infosDebug += e.ToString().Split(':')[0]; } infosDebug += Environment.NewLine + "Konachan: "; try { if (BooruModule.getBooruUrl(new BooruModule.Konachan(), new string[] { "hibiki_(kancolle)" }).StartsWith("https://")) { infosDebug += "OK"; } else { infosDebug += "Error"; } } catch (Exception e) { infosDebug += e.ToString().Split(':')[0]; } infosDebug += Environment.NewLine + "Rule 34: "; try { if (BooruModule.getBooruUrl(new BooruModule.Rule34(), new string[] { "hibiki_(kancolle)" }).StartsWith("https://")) { infosDebug += "OK"; } else { infosDebug += "Error"; } } catch (Exception e) { infosDebug += e.ToString().Split(':')[0]; } infosDebug += Environment.NewLine + Environment.NewLine + "**Vn Module:**" + Environment.NewLine + "Vn: "; try { if ((await VndbModule.getVn("Sunrider: Mask of Arcadius")).Name == "Sunrider: Mask of Arcadius") { infosDebug += "OK"; } else { infosDebug += "Error"; } } catch (Exception e) { infosDebug += e.ToString().Split(':')[0]; } infosDebug += Environment.NewLine + Environment.NewLine + "**Google Shortener Module:**" + Environment.NewLine + "Random URL: "; try { Tuple <string, string> result = await GoogleShortenerModule.getUrl(); if (result == null || result.Item1.StartsWith("https://goo.gl/") || result.Item1.StartsWith("http://goo.gl/")) { infosDebug += "OK"; } else { infosDebug += "Error"; } } catch (Exception e) { infosDebug += e.ToString().Split(':')[0]; } embed = new EmbedBuilder() { Title = "Unit tests:", Description = infosDebug, Color = Color.Purple, }; await ReplyAsync("", false, embed.Build()); }
public override async void Loose() // TODO: Save score { string finalStr = "You lost." + Environment.NewLine; string[] corrWords = m_words.Where(x => x[0] == m_currWord[m_currWord.Length - 1]).ToArray(); if (corrWords.Length == 0) { finalStr += "To be honest, I didn't know a word to answer too." + Environment.NewLine; } else { string word = corrWords[Program.p.rand.Next(0, corrWords.Length)]; string[] insideWord = word.Split('$'); finalStr += "Here's a word you could have said: " + insideWord[0] + " (" + LinguistModule.fromHiragana(insideWord[0]) + ") - Meaning: " + insideWord[1] + Environment.NewLine; } SaveServerScores(null); await m_chan.SendMessageAsync(finalStr); }
//TODO Manage kanjis using Jisho API public override async void CheckCorrect(string userWord, IUser user) { if (m_time == DateTime.MinValue) { await m_chan.SendMessageAsync("Please wait until I'm playing."); } else { m_nbAttempt++; userWord = LinguistModule.fromKatakana(LinguistModule.toHiragana(userWord)); foreach (char c in userWord) { if (c < 0x0031 || (c > 0x005A && c < 0x0061) || (c > 0x007A && c < 0x3041) || (c > 0x3096 && c < 0x30A1) || c > 0x30FA) { await m_chan.SendMessageAsync("Please only use hiragana, katakana or romaji."); return; } } string json; using (WebClient wc = new WebClient()) { wc.Encoding = Encoding.UTF8; json = wc.DownloadString("http://www.jisho.org/api/v1/search/words?keyword=" + userWord); } bool isCorrect = false; foreach (string s in Program.getElementXml("\"japanese\":[", json, '$').Split(new string[] { "\"japanese\":[" }, StringSplitOptions.None)) { string hiragana = Program.getElementXml("\"reading\":\"", s, '"'); if (userWord == hiragana) { isCorrect = true; if (Program.getElementXml("parts_of_speech\":[\"", json, '"') != "Noun") { await m_chan.SendMessageAsync("This word isn't a noun."); return; } break; } } if (!isCorrect) { await m_chan.SendMessageAsync("This word doesn't exist."); return; } if (userWord[0] != m_currWord[m_currWord.Length - 1]) { await m_chan.SendMessageAsync("Your word must begin by a " + m_currWord[m_currWord.Length - 1] + " (" + LinguistModule.fromHiragana(m_currWord[m_currWord.Length - 1].ToString()) + ")."); return; } if (m_alreadySaid.Contains(userWord)) { await m_chan.SendMessageAsync("This word was already said."); m_didLost = true; return; } if (userWord[userWord.Length - 1] == 'ん') { await m_chan.SendMessageAsync("Your word is finishing with a ん."); m_didLost = true; return; } m_time = DateTime.MinValue; m_nbFound++; if (!m_userIds.Contains(user.Id)) { m_userIds.Add(user.Id); } m_words.Remove(m_words.Find(x => x.Split('$')[0] == userWord)); m_alreadySaid.Add(userWord); m_currWord = userWord; Post(); } }