Ejemplo n.º 1
0
 public TranslationSelectedUpdateHook(
     AddWordService addWordService,
     ChatRoom chat)
 {
     Chat            = chat;
     _addWordService = addWordService;
 }
Ejemplo n.º 2
0
 public SelectLearningSet(LearningSetService learningSetService, LocalDictionaryService localDictionaryService, UserService userService, UsersWordsService usersWordsService, AddWordService addWordService)
 {
     _learningSetService     = learningSetService;
     _localDictionaryService = localDictionaryService;
     _userService            = userService;
     _usersWordsService      = usersWordsService;
     _addWordService         = addWordService;
 }
Ejemplo n.º 3
0
 public AddingWordsMode(
     ChatIO chatIo,
     AddWordService addWordService
     )
 {
     _chatIo         = chatIo;
     _addWordService = addWordService;
 }
Ejemplo n.º 4
0
 public TranslateWordsFlow(
     ChatRoom chat,
     AddWordService addWordService,
     TranslationSelectedUpdateHook translationUpdateHookHandler
     )
 {
     Chat            = chat;
     _addWordService = addWordService;
     _translationSelectedUpdateHook = translationUpdateHookHandler;
 }
Ejemplo n.º 5
0
 public WordAdditionMode(YandexTranslateApiClient yapiTranslateApiClient,
                         YandexDictionaryApiClient yandexDictionaryApiClient, UsersWordService usersWordService,
                         DictionaryService dictionaryService, AddWordService addWordService)
 {
     _yapiDicClient     = yandexDictionaryApiClient;
     _yapiTransClient   = yapiTranslateApiClient;
     _usersWordService  = usersWordService;
     _dictionaryService = dictionaryService;
     _addWordService    = addWordService;
 }
Ejemplo n.º 6
0
        private static void Main()
        {
            TaskScheduler.UnobservedTaskException +=
                (sender, args) => Console.WriteLine($"Unobserved ex {args.Exception}");

            _settings = ReadConfiguration();

            var yandexDictionaryClient   = new YandexDictionaryApiClient(_settings.YadicapiKey, _settings.YadicapiTimeout);
            var yandexTranslateApiClient = new YandexTranslateApiClient(_settings.YatransapiKey, _settings.YatransapiTimeout);

            var client = new MongoClient(_settings.MongoConnectionString);
            var db     = client.GetDatabase("SayWhatDb");

            var userWordRepo   = new UserWordsRepo(db);
            var dictionaryRepo = new DictionaryRepo(db);
            var userRepo       = new UsersRepo(db);
            var examplesRepo   = new ExamplesRepo(db);

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

            _userWordService   = new UsersWordsService(userWordRepo, examplesRepo);
            _dictionaryService = new DictionaryService(dictionaryRepo, examplesRepo);
            _userService       = new UserService(userRepo);


            _addWordService = new AddWordService(
                _userWordService,
                yandexDictionaryClient,
                yandexTranslateApiClient,
                _dictionaryService,
                _userService);

            QuestionSelector.Singletone = new QuestionSelector(_dictionaryService);

            Console.WriteLine("Dic started");

            _botClient = new TelegramBotClient(_settings.TelegramToken);
            var me = _botClient.GetMeAsync().Result;

            Console.WriteLine(
                $"Hello, World! I am user {me.Id} and my name is {me.FirstName}."
                );

            _botClient.OnUpdate  += BotClientOnOnUpdate;
            _botClient.OnMessage += Bot_OnMessage;

            _botClient.StartReceiving();
            // workaround for infinity awaiting
            new TaskCompletionSource <bool>().Task.Wait();
            // it will never happens
            _botClient.StopReceiving();
        }
Ejemplo n.º 7
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;
 }
Ejemplo n.º 8
0
 public ChatRoomFlow(ChatIO chatIo,
                     TelegramUserInfo userInfo,
                     BotSettings settings,
                     AddWordService addWordsService,
                     UsersWordsService usersWordsService,
                     UserService userService
                     )
 {
     ChatIo             = chatIo;
     _userInfo          = userInfo;
     _settings          = settings;
     _addWordsService   = addWordsService;
     _usersWordsService = usersWordsService;
     _userService       = userService;
 }
Ejemplo n.º 9
0
 public LastTranslationHandler(
     IReadOnlyList <Translation> translations,
     ChatRoom chat,
     AddWordService addWordService)
 {
     Chat           = chat;
     OriginWordText = translations[0].OriginText;
     _translations  = translations;
     _areSelected   = new bool[_translations.Count];
     if (translations.Count > 0)
     {
         _areSelected[0] = true;
     }
     _addWordService = addWordService;
 }
Ejemplo n.º 10
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;
 }
Ejemplo n.º 11
0
 public AddBotCommandHandler(
     AddWordService addWordsService, TranslationSelectedUpdateHook translationSelectedUpdateHook)
 {
     _addWordsService = addWordsService;
     _translationSelectedUpdateHook = translationSelectedUpdateHook;
 }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            var builder = new ConfigurationBuilder()
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: false);
            IConfigurationRoot configuration = builder.Build();

            var dbFileName = configuration.GetSection("wordDb").Value;

            var yadicapiKey     = configuration.GetSection("yadicapi").GetSection("key").Value;
            var yadicapiTimeout = TimeSpan.FromSeconds(5);

            var yatransapiKey     = configuration.GetSection("yatransapi").GetSection("key").Value;
            var yatransapiTimeout = TimeSpan.FromSeconds(5);

            var addWordService = new AddWordService(
                new UsersWordsService(new UserWordsRepo(dbFileName)),
                new YandexDictionaryApiClient(yadicapiKey, yadicapiTimeout),
                new YandexTranslateApiClient(yatransapiKey, yatransapiTimeout),
                new DictionaryService(new DictionaryRepository(dbFileName)));

            var examService = new ExamService(
                new ExamsAndMetricService(new ExamsAndMetricsRepo(dbFileName)),
                new DictionaryService(new DictionaryRepository(dbFileName)),
                new UsersWordsService(new UserWordsRepo(dbFileName))
                );
            var authorizeService = new AuthorizeService(new UserService(new UserRepo(dbFileName)));

            var modes = new IConsoleMode[]
            {
                new ExamMode(addWordService, examService),
                new WordAdditionMode(addWordService),
                //  new GraphsStatsMode(),
                //   new RandomizeMode(),
                //   new AddPhraseToWordsMode(yapiDicClient),
            };

            DoMigration.ApplyMigrations(dbFileName);

            Console.WriteLine("Dic started");

            ConsoleKeyInfo val;
            int            choice;

            //var metrics = repo.GetAllQuestionMetrics();

            //string path = "T:\\Dictionary\\eng_rus_full.json";
            //Console.WriteLine("Loading dictionary");
            //var dictionary = Dic.Logic.Dictionaries.Tools.ReadFromFile(path);

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine(@"
     ____ _  _ ____ ___ _ ____ _  _ ____ ___  ____ _    
     |    |__| |  |  |  | [__  |_/  |__|   /  |__| |    
     |___ |  | |__|  |  | ___] | \_ |  |  /__ |  | |___                                                    
");
            Console.ResetColor();

            //--------begin registration

            User user = null;

            while (user == null)
            {
                Console.WriteLine();
                Console.WriteLine("ESC: Quit");

                Console.WriteLine("1: NewUser");
                Console.WriteLine("2: Login");
                Console.WriteLine();
                Console.Write("Choose action:");
                val = Console.ReadKey();
                Console.WriteLine();
                choice = ((int)val.Key - (int)ConsoleKey.D1) + 1;
                if (choice == 1)
                {
                    Console.Write("Enter your name: ");
                    var name = Console.ReadLine();
                    Console.WriteLine("Enter login: "******"Enter password: "******"Enter email: ");
                    var email = Console.ReadLine();

                    user = authorizeService.CreateUser(name, login, password, email);

                    if (user != null)
                    {
                        Console.WriteLine("New user has been added!");
                        Console.WriteLine($"Hello, {user.Name}. Press any key to continue.");
                    }
                    else
                    {
                        Console.WriteLine("Error in registration. Try again.");
                    }
                }
                if (choice == 2)
                {
                    Console.WriteLine("Enter login: "******"Enter password: "******"Hello, {user.Name}. Press any key to continue.");
                    }
                    else
                    {
                        Console.WriteLine("Wrong Password or Name. Try again. Press any key to continue.");
                    }
                }
                Console.ReadKey();
            }

            Console.Clear();
            //---------end registration-------


            while (true)
            {
                Console.WriteLine();
                Console.WriteLine("ESC: Quit");

                for (int i = 0; i < modes.Length; i++)
                {
                    Console.WriteLine($"{i+1}: {modes[i].Name}");
                }

                Console.WriteLine();
                Console.Write("Choose mode:");

                val = Console.ReadKey();
                Console.WriteLine();

                if (val.Key == ConsoleKey.Escape)
                {
                    return;
                }

                choice = ((int)val.Key - (int)ConsoleKey.D1);
                if (choice > -1 && choice < modes.Length)
                {
                    var selected = modes[choice];
                    Console.Clear();
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("======   " + selected.Name + "    ======");
                    Console.ResetColor();

                    modes[choice].Enter(1);
                }
                Console.WriteLine();

                Console.WriteLine("===========================================");
            }
        }
Ejemplo n.º 13
0
 public ExamMode(AddWordService addWordService, ExamService examService)
 {
     _addWordService = addWordService;
     _examService    = examService;
 }
Ejemplo n.º 14
0
 public WordAdditionMode(AddWordService addWordService)
 {
     _addWordService = addWordService;
 }
Ejemplo n.º 15
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();
        }