private async void BotOnMessageReceived(object sender, MessageEventArgs messageEventArgs) { var message = messageEventArgs.Message; var username = message.Chat.Username; if (!UserLibrary.ContainsUser(username)) { var user = new TelegramBotUser() { ChatId = message.Chat.Id, UserName = username, Lock = true, CurrentState = TelegramBotStateEnum.MainMenu }; State = new MainMenuState(this); UserLibrary.AddUser(user); } else { var userState = UserLibrary.GetTelegramBotUserState(username); SetState(userState); } Console.WriteLine(message.Chat.Id); State.Response(_bot, messageEventArgs); }
private async void BotOnMessageReceivedSwitch(object sender, MessageEventArgs messageEventArgs) { var message = messageEventArgs.Message; var username = message.Chat.Username; var userState = TelegramBotStateEnum.MainMenu; if (username == null) { await _bot.SendTextMessageAsync(message.Chat.Id, $"Ошибка!\n У вас отсутвует имя пользователя!"); return; } if (!UserLibrary.ContainsUser(username)) { var user = new TelegramBotUser() { CurrentState = TelegramBotStateEnum.MainMenu, ChatId = message.Chat.Id, UserName = username, Lock = false }; Console.Write(username); UserLibrary.AddUser(user); } else { userState = UserLibrary.GetTelegramBotUserState(username); } //UserLibrary.Logger += //$"Получено сообщение: от {username}. {message.Date}. State: {userState}. ({message.Text})"; Console.WriteLine($"Получено сообщение: от {username}. {message.Date}. State: {userState}. ({message.Text})"); if (!UserLibrary.GetTelegramBotUser(username).Lock) { var error = @"Error! You are haven't access to this bot. Please, write to creator for access."; await _bot.SendTextMessageAsync(message.Chat.Id, error, replyMarkup : new ReplyKeyboardRemove()); return; } if (message.Text.Split(" ").First().Equals("/access") && message.Chat.Username.Equals("Dukhovnikov")) { try { var commandmessage = message.Text.Split(" "); var userforaccess = commandmessage[1].Substring(1); if (UserLibrary.ContainsUser(userforaccess)) { await _bot.SendTextMessageAsync(message.Chat.Id, $"Пользователю @{userforaccess} разрешён доступ."); UserLibrary.ChangeAccessUser(userforaccess, true); } else { await _bot.SendTextMessageAsync(message.Chat.Id, $"Ошибка!\n Данный пользователь отсутсвует в базе и не просил доступ."); } } catch (Exception e) { await _bot.SendTextMessageAsync(message.Chat.Id, $"Ошибка!\n Неверно задана конадна."); } return; } switch (userState) { case TelegramBotStateEnum.MainMenu: await _bot.SendTextMessageAsync(message.Chat.Id, "Сделайте выбор!", replyMarkup : _inlineKeyboardMainMenu); break; case TelegramBotStateEnum.DivisibilityCriteriaMenu: await _bot.SendTextMessageAsync(message.Chat.Id, "Сделайте выбор!", replyMarkup : _inlineKeyboardDivisibilityMenu); break; case TelegramBotStateEnum.AmericanFindDeterminant: var solveAmericanFindDeterminant = Executor.OnGetDeterminantOfAmericanMethod(message.Text); await _bot.SendTextMessageAsync(message.Chat.Id, solveAmericanFindDeterminant, replyMarkup : _inlineKeyboardGoToMainMenu, parseMode : ParseMode.Html); break; case TelegramBotStateEnum.MultiplicationMatrixShtrassen: var aMatrix = new Matrix(message.Text); if (((INullable)aMatrix).IsNull) { await _bot.SendTextMessageAsync(message.Chat.Id, "Ошибка! Неправильно задана матрица А", replyMarkup : _inlineKeyboardGoToMainMenu, parseMode : ParseMode.Html); } else { AMatrix = aMatrix; await _bot.SendTextMessageAsync(message.Chat.Id, "Введите матрицу В", replyMarkup : _inlineKeyboardGoToMainMenu, parseMode : ParseMode.Html); UserLibrary.UpdateUserState(username, TelegramBotStateEnum.MultiplicationMatrixShtrassenWatingMatrixB); } break; case TelegramBotStateEnum.MultiplicationNubmersKaratsuba: var solveKaratsuba = Executor.OnGetMultiplicationNubmersKaratsubaSolve(message.Text); await _bot.SendTextMessageAsync(message.Chat.Id, "<code>Алгоритм Карацубы</code>\n" + solveKaratsuba, replyMarkup : _inlineKeyboardGoToMainMenu, parseMode : ParseMode.Html); break; case TelegramBotStateEnum.DivisibilityCriteriaPaskal: var solvePaskal = Executor.OnGetPaskaleSolve(message.Text); await _bot.SendTextMessageAsync(message.Chat.Id, solvePaskal, replyMarkup : _inlineKeyboardGoToMainMenu, parseMode : ParseMode.Html); break; case TelegramBotStateEnum.DivisibilityCriteriaRachinskiiFirst: var solveRachinskiiOne = Executor.OnGetRachinskiyOneSolve(message.Text); await _bot.SendTextMessageAsync(message.Chat.Id, solveRachinskiiOne, replyMarkup : _inlineKeyboardGoToMainMenu, parseMode : ParseMode.Html); break; case TelegramBotStateEnum.DivisibilityCriteriaRachinskiiSecond: var solveRachinskiiSecond = Executor.OnGetRachinskiySecondSolve(message.Text); await _bot.SendTextMessageAsync(message.Chat.Id, solveRachinskiiSecond, replyMarkup : _inlineKeyboardGoToMainMenu, parseMode : ParseMode.Html); break; case TelegramBotStateEnum.DivisibilityCriteriaRachinskiiThird: var solveRachinskiiThird = Executor.OnGetRachinskiyThridSolve(message.Text); await _bot.SendTextMessageAsync(message.Chat.Id, solveRachinskiiThird, replyMarkup : _inlineKeyboardGoToMainMenu, parseMode : ParseMode.Html); break; case TelegramBotStateEnum.MultiplicationMatrixShtrassenWatingMatrixB: var bMatrix = new Matrix(message.Text); if (((INullable)bMatrix).IsNull) { await _bot.SendTextMessageAsync(message.Chat.Id, "Ошибка! Неправильно задана матрица B", replyMarkup : _inlineKeyboardGoToMainMenu, parseMode : ParseMode.Html); } else { BMatrix = bMatrix; var solve = Executor.OnGetStrassenAlgorithmSolve(AMatrix, BMatrix); var resultstandart = $"<b>Ответ (обычное умножение)</b>:\n\n {AMatrix * BMatrix}"; await _bot.SendTextMessageAsync(message.Chat.Id, solve + "\n\n" + resultstandart, replyMarkup : _inlineKeyboardGoToMainMenu, parseMode : ParseMode.Html); } break; default: throw new ArgumentOutOfRangeException(); } }