예제 #1
0
 public SelectLearningSet(LearningSetService learningSetService, LocalDictionaryService localDictionaryService, UserService userService, UsersWordsService usersWordsService, AddWordService addWordService)
 {
     _learningSetService     = learningSetService;
     _localDictionaryService = localDictionaryService;
     _userService            = userService;
     _usersWordsService      = usersWordsService;
     _addWordService         = addWordService;
 }
예제 #2
0
 public AddFromLearningSetFlow(
     ChatRoom chat,
     LocalDictionaryService localDictionaryService,
     LearningSet set,
     UserService userService,
     UsersWordsService usersWordsService,
     AddWordService addWordService)
 {
     Chat = chat;
     _localDictionaryService = localDictionaryService;
     _set               = set;
     _userService       = userService;
     _usersWordsService = usersWordsService;
     _addWordService    = addWordService;
 }
예제 #3
0
 public MainFlow(
     ChatIO chatIo,
     TelegramUserInfo userInfo,
     BotSettings settings,
     AddWordService addWordsService,
     UsersWordsService usersWordsService,
     UserService userService,
     LocalDictionaryService localDictionaryService,
     LearningSetService learningSetService)
 {
     ChatIo                  = chatIo;
     _userInfo               = userInfo;
     _settings               = settings;
     _addWordsService        = addWordsService;
     _usersWordsService      = usersWordsService;
     _userService            = userService;
     _localDictionaryService = localDictionaryService;
     _learningSetService     = learningSetService;
 }
예제 #4
0
 public EngWriteQuestion(LocalDictionaryService localDictionaryService)
 {
     _localDictionaryService = localDictionaryService;
 }
예제 #5
0
 public QuestionSelector(LocalDictionaryService localDictionaryService)
 {
     _simpleExamsList = new[]
     {
         _engChoose,
         _ruChoose,
         _ruPhraseChoose,
         _engPhraseChoose,
         _engChooseWordInPhrase,
         _transcriptionExam,
         _isItRightTranslationExam,
         _engChooseMultipleTranslationExam,
     };
     _intermidiateExamsList = new[]
     {
         _engChoose,
         _ruChoose,
         _ruPhraseChoose,
         _engPhraseChoose,
         _engTrust,
         _ruTrust,
         _hideousRuTrust,
         _ruTrustSingle,
         _ruTrustSingleHideous,
         _hideousEngTrust,
         _ruChooseByTranscriptionExam,
         _transcriptionExam,
         _isItRightTranslationExam,
         _engChooseMultipleTranslationExam,
         _hideousEngChooseMultipleTranslationExam,
     };
     _advancedExamsList = new[]
     {
         _engChoose,
         _ruChoose,
         _engPhraseChoose,
         _ruPhraseChoose,
         _engTrust,
         _ruTrust,
         _ruTrustSingle,
         EngWrite(localDictionaryService),
         RuWrite(localDictionaryService),
         RuWriteSingleTranslationExam(localDictionaryService),
         _hideousRuPhraseChoose,
         _hideousEngPhraseChoose,
         _hideousEngTrust,
         _hideousRuTrust,
         _ruTrustSingleHideous,
         HideousEngWriteExam(localDictionaryService),
         HideousRuWriteExam(localDictionaryService),
         HideousRuWriteSingleTranslationExam(localDictionaryService),
         _clearEngPhraseSubstitute,
         _clearRuPhraseSubstitute,
         _engPhraseSubstitute,
         _ruPhraseSubstitute,
         _engChooseWordInPhrase,
         _clearEngChooseWordInPhrase,
         _assemblePhraseExam,
         _ruChooseByTranscriptionExam,
         _hideousRuChooseByTranscriptionExam,
         _hideousTranscriptionExam,
         _hideousIsItRightTranslationExam,
         _transcriptionExam,
         _isItRightTranslationExam,
         _engChooseMultipleTranslationExam,
         _hideousEngChooseMultipleTranslationExam,
     };
 }
예제 #6
0
 private ExamAndPreferredScore RuWrite(LocalDictionaryService service) => new ExamAndPreferredScore(
     question: new RuWriteQuestion(service),
     expectedScore: 2.6,
     frequency: 14);
예제 #7
0
 private ExamAndPreferredScore HideousRuWriteSingleTranslationExam(LocalDictionaryService service) => new ExamAndPreferredScore(
     question: new RuWriteSingleTarnslationQuestion(service),
     expectedScore: 1.6,
     frequency: 10);
예제 #8
0
 private ExamAndPreferredScore HideousRuWriteExam(LocalDictionaryService service) =>
 new ExamAndPreferredScore(
     question: new ClearScreenQuestionDecorator(new RuWriteQuestion(service)),
     expectedScore: 4,
     frequency: 14);
예제 #9
0
        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));
        }
예제 #10
0
 public RuWriteSingleTarnslationQuestion(LocalDictionaryService localDictionaryService)
 {
     _localDictionaryService = localDictionaryService;
 }
예제 #11
0
        private static void Main()
        {
            TaskScheduler.UnobservedTaskException +=
                (sender, args) => Console.WriteLine($"Unobserved ex {args.Exception}");

            _settings = ReadConfiguration(substitudeDebugConfig: false);
            var yandexDictionaryClient = new YandexDictionaryApiClient(_settings.YadicapiKey, _settings.YadicapiTimeout);
            var client = new MongoClient(_settings.MongoConnectionString);
            var db     = client.GetDatabase(_settings.MongoDbName);
            //StatsMigrator.Do(db).Wait();
            var userWordRepo        = new UserWordsRepo(db);
            var dictionaryRepo      = new LocalDictionaryRepo(db);
            var userRepo            = new UsersRepo(db);
            var examplesRepo        = new ExamplesRepo(db);
            var questionMetricsRepo = new QuestionMetricRepo(db);
            var learningSetsRepo    = new LearningSetsRepo(db);

            userWordRepo.UpdateDb();
            dictionaryRepo.UpdateDb();
            userRepo.UpdateDb();
            examplesRepo.UpdateDb();
            questionMetricsRepo.UpdateDb();
            learningSetsRepo.UpdateDb();

            Botlog.QuestionMetricRepo = questionMetricsRepo;

            _userWordService        = new UsersWordsService(userWordRepo, examplesRepo);
            _localDictionaryService = new LocalDictionaryService(dictionaryRepo, examplesRepo);
            _userService            = new UserService(userRepo);
            _learningSetService     = new LearningSetService(learningSetsRepo);
            _addWordService         = new AddWordService(
                _userWordService,
                yandexDictionaryClient,
                _localDictionaryService,
                _userService);

            QuestionSelector.Singletone = new QuestionSelector(_localDictionaryService);

            _botClient = new TelegramBotClient(_settings.TelegramToken);

            Botlog.CreateTelegramLogger(_settings.BotHelperToken, _settings.ControlPanelChatId);

            var me = _botClient.GetMeAsync().Result;

            Botlog.WriteInfo($"Waking up. I am {me.Id}:{me.Username} ", true);

            _botClient.SetMyCommandsAsync(new[] {
                new BotCommand {
                    Command = BotCommands.Help, Description = "Help and instructions (Помощь и инстркции)"
                },
                new BotCommand {
                    Command = BotCommands.Start, Description = "Main menu (Главное меню)"
                },
                new BotCommand {
                    Command = BotCommands.Translate, Description = "Translator (Переводчик)"
                },
                new BotCommand {
                    Command = BotCommands.Learn, Description = "Learning translated words (Учить слова)"
                },
                new BotCommand {
                    Command = BotCommands.New, Description = "Show learning sets (Показать наборы для изучения)"
                },
                new BotCommand {
                    Command = BotCommands.Stats, Description = "Your stats (Твоя статистика)"
                },
                new BotCommand {
                    Command = BotCommands.Words, Description = "Your learned words (Твои выученные слова)"
                },
                new BotCommand {
                    Command = BotCommands.Chlang, Description = "Change interface language (Сменить язык интерфейса)"
                },
            }).Wait();

            var allUpdates = _botClient.GetUpdatesAsync().Result;

            Botlog.WriteInfo($"{allUpdates.Length} messages were missed");

            foreach (var update in allUpdates)
            {
                OnBotWokeUp(update);
            }
            if (allUpdates.Any())
            {
                _botClient.MessageOffset = allUpdates.Last().Id + 1;
                Botlog.WriteInfo($"{Chats.Count} users were waiting for us");
            }
            _botClient.OnUpdate  += BotClientOnOnUpdate;
            _botClient.OnMessage += Bot_OnMessage;

            _botClient.StartReceiving();
            Botlog.WriteInfo($"... and here i go!", false);
            // workaround for infinity awaiting
            new TaskCompletionSource <bool>().Task.Wait();
            // it will never happens
            _botClient.StopReceiving();
        }