public async Task <QuestionResult> Pass(ChatRoom chat, UserWordModel word, UserWordModel[] examList) { var translations = word.TextTranslations.ToArray(); var minCount = translations.Min(t => t.Count(c => c == ' ')); if (minCount > 0 && word.AbsoluteScore < minCount * WordLeaningGlobalSettings.FamiliarWordMinScore) { return(QuestionResult.Impossible); } await chat.SendMarkdownMessageAsync(QuestionMarkups.TranslateTemplate(word.Word, chat.Texts.WriteTheTranslationMarkdown)); var entry = await chat.WaitUserTextInputAsync(); if (string.IsNullOrEmpty(entry)) { return(QuestionResult.RetryThisQuestion); } if (!entry.IsRussian()) { await chat.SendMessageAsync(chat.Texts.RussianInputExpected); return(QuestionResult.RetryThisQuestion); } var(text, comparation) = translations.GetClosestTo(entry.Trim()); switch (comparation) { case StringsCompareResult.Equal: return(QuestionResult.Passed(chat.Texts)); case StringsCompareResult.SmallMistakes: await chat.SendMarkdownMessageAsync(chat.Texts.YouHaveATypoLetsTryAgainMarkdown(text)); return(QuestionResult.RetryThisQuestion); case StringsCompareResult.BigMistakes: return(QuestionResult.Failed(chat.Texts.FailedMistakenMarkdown(text), chat.Texts)); } var allMeaningsOfWord = await _localDictionaryService.GetAllTranslationWords(word.Word); var(otherMeaning, otherComparation) = allMeaningsOfWord.GetClosestTo(entry); if (otherComparation == StringsCompareResult.Equal) { await chat.SendMarkdownMessageAsync( $"{chat.Texts.OutOfScopeTranslationMarkdown}: " + $"*{word.AllTranslationsAsSingleString}*"); return(QuestionResult.RetryThisQuestion); } if (otherComparation == StringsCompareResult.SmallMistakes) { await chat.SendMarkdownMessageAsync( chat.Texts.OutOfScopeWithCandidateMarkdown(otherMeaning) + ": " + "*\"" + word.AllTranslationsAsSingleString + "\"*"); return(QuestionResult.RetryThisQuestion); } return(QuestionResult.Failed( chat.Texts.FailedTranslationWasMarkdown + $"\r\n*\"{word.AllTranslationsAsSingleString}\"*", chat.Texts)); }
public static async Task <QuestionResult> PassRuWriteQuestion( ChatRoom chat, UserWordModel word, string ruTranslationCaption, LocalDictionaryService localDictionaryService) { var wordsInPhraseCount = word.Word.Count(c => c == ' '); if (wordsInPhraseCount > 0 && word.AbsoluteScore < wordsInPhraseCount * WordLeaningGlobalSettings.FamiliarWordMinScore) { return(QuestionResult.Impossible); } await chat.SendMarkdownMessageAsync( QuestionMarkups.TranslateTemplate(ruTranslationCaption, chat.Texts.WriteTheTranslationMarkdown)); var enUserEntry = await chat.WaitUserTextInputAsync(); if (string.IsNullOrEmpty(enUserEntry)) { return(QuestionResult.RetryThisQuestion); } if (enUserEntry.IsRussian()) { await chat.SendMessageAsync(chat.Texts.EnglishInputExpected); return(QuestionResult.RetryThisQuestion); } var comparation = word.Word.CheckCloseness(enUserEntry); if (comparation == StringsCompareResult.Equal) { return(QuestionResult.Passed(chat.Texts)); } if (comparation == StringsCompareResult.SmallMistakes) { await chat.SendMarkdownMessageAsync(chat.Texts.YouHaveATypoLetsTryAgainMarkdown(word.Word)); return(QuestionResult.RetryThisQuestion); } if (comparation == StringsCompareResult.BigMistakes) { return(QuestionResult.Failed(chat.Texts.FailedMistakenMarkdown(word.Word), chat.Texts.Mistaken)); } // ## Other translation case ## // example: // Coefficient - коэффициент // Rate - коэффициент // Question is about 'коэффициент' (Coefficient) // User answers 'Rate' // Search for 'Rate' translations var otherRuTranslationsOfUserInput = await localDictionaryService.GetAllTranslationWords(enUserEntry.ToLower()); // if otherRuTranslationsOfUserInput contains 'коэффициент' or something like it // then retry question var russianTranslations = word.TextTranslations; if (russianTranslations.Any( t1 => otherRuTranslationsOfUserInput.Any(t1.AreEqualIgnoreSmallMistakes))) { //translation is correct, but for other word await chat.SendMessageAsync( $"{chat.Texts.CorrectTranslationButQuestionWasAbout} \"{word.Word}\" - *{word.AllTranslationsAsSingleString}*'\r\n" + chat.Texts.LetsTryAgain); return(QuestionResult.RetryThisQuestion); } var translates = string.Join(",", otherRuTranslationsOfUserInput); string failedMessage = ""; if (!string.IsNullOrWhiteSpace(translates)) { failedMessage = $"{enUserEntry} {chat.Texts.translatesAs} {translates}\r\n"; } failedMessage += $"{chat.Texts.RightTranslationWas}: *\"{word.Word}\"*"; return(QuestionResult.Failed( failedMessage, chat.Texts)); }