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 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(); } }