private static async void BotClient_OnCallbackQuery(object sender, CallbackQueryEventArgs e) { var callbackQuery = e.CallbackQuery; Console.WriteLine("The " + e.CallbackQuery.From.Id + " Select: " + e.CallbackQuery.Data); //return; var users = DBUser.Users; foreach (User u in users) { if (u.ChatId == e.CallbackQuery.From.Id && u.Topic == "Topic") { await BotClient.SendTextMessageAsync(callbackQuery.From.Id, "Please, wait a second)"); { u.Topic = callbackQuery.Data; u.TopicWords = SqlModel.GetWords(callbackQuery.Data); } int nt = random.Next(1, u.TopicWords.Count); u.Output = GetStringList(u.TopicWords[nt].English); await BotClient.SendTextMessageAsync(callbackQuery.From.Id, "Please, translate it)\n" + $"{u.TopicWords[nt].Russian}"); u.TopicWords.RemoveAt(nt); } } await DBUser.SaveChangesAsync(); }
private static void InsertFromExcel() { excel = new Excel(path, 1); string[] names = excel.GetNames(); for (int i = 0; i < excel.GetSheet(); i++) { Console.WriteLine($"I am working on {names[i]}"); SqlModel.RecreateTable(names[i]); excel.SelectWorkSheet(i + 1); for (int j = 0; j <= excel.GetColump(); j++) { SqlModel.InsertTable(names[i], excel.ReadExcelString(j, 2), excel.ReadExcelString(j, 0)); } } excel.Close(); }
private static async void BotClient_OnMessage(object sender, MessageEventArgs e) { if (e.Message.Text == null || e.Message.Type != MessageType.Text) { return; } var message = e.Message; Console.WriteLine("The " + e.Message.Chat.FirstName + " Write: " + e.Message.Text); //return; //if (e.Message.Chat.Id == 386219611) { await BotClient.SendTextMessageAsync(message.Chat, $"Not for you, Kristina)"); return; } //if (e.Message.Chat.Id == 425901772) { await BotClient.SendTextMessageAsync(message.Chat, $"Пошел нахууй!"); return; } var users = DBUser.Users; foreach (User u in users) { if (u.ChatId == message.Chat.Id) { here = true; } } if (!here) { if (!SqlModel.Check("Programming")) { InsertFromExcel(); } DBUser.Users.Add(new User { ChatId = message.Chat.Id }); DBUser.SaveChanges(); } users = DBUser.Users; foreach (User u in users) { if (u.ChatId == message.Chat.Id) { switch (message.Text) { case "/start": await BotClient.SendTextMessageAsync(message.Chat, $"Hi, {message.Chat.FirstName}\n" + $"I was created only for Danil Kravchenko))\n" + $"So, if you are not Danil, be happy, you are his friend))\n" + $"Write 3 forms like \"first/second/third\""); u.Topic = "Topic"; await BotClient.SendTextMessageAsync(message.Chat, $"Select the topic:\n", replyMarkup : keyboardTopic); break; case "/insert": await BotClient.SendTextMessageAsync(message.Chat, $"I am working"); InsertFromExcel(); u.Topic = "Topic"; await BotClient.SendTextMessageAsync(message.Chat, $"Select the topic:\n", replyMarkup : keyboardTopic); break; case "/topic": u.Topic = "Topic"; await BotClient.SendTextMessageAsync(message.Chat, $"Select the topic:\n", replyMarkup : keyboardTopic); break; case "/stop": u.Topic = string.Empty; u.TopicWords = new List <Word>(); await BotClient.SendTextMessageAsync(message.Chat, $"Good game\n" + $"Hurry back, I`m waiting for you)*"); break; default: if (u.Topic == string.Empty) { await BotClient.SendTextMessageAsync(message.Chat, $"I don`t understand you\n" + $"Please, write /topic - to select a topic and start a game"); return; } u.Input = GetStringList(message.Text); foreach (string str in u.Input) { if (!u.Output.Contains(str)) { await BotClient.SendTextMessageAsync(message.Chat, $"Oh no, you made mistake\n" + $"The right translate is \"{ToStringList(u.Output)}\""); if (u.TopicWords.Count == 0) { u.Topic = string.Empty; await BotClient.SendTextMessageAsync(message.Chat, "Good job, you translate all word\n" + "write:\n" + "/topic - to reselect a topic\n" + "/stop - to stop a game"); return; } int n = random.Next(0, u.TopicWords.Count); u.Output = GetStringList(u.TopicWords[n].English); await BotClient.SendTextMessageAsync(message.Chat, "Please, translate it)\n" + $"{u.TopicWords[n].Russian}"); u.TopicWords.RemoveAt(n); return; } } await BotClient.SendTextMessageAsync(message.Chat, $"Cool, you are right\n" + $"Translate is \"{ToStringList(u.Output)}\""); if (u.TopicWords.Count == 0) { u.Topic = string.Empty; await BotClient.SendTextMessageAsync(message.Chat, "Good job, you translate all words\n" + "write:\n" + "/topic - to reselect a topic\n" + "/stop - to stop a game"); return; } int nt = random.Next(0, u.TopicWords.Count); u.Output = GetStringList(u.TopicWords[nt].English); await BotClient.SendTextMessageAsync(message.Chat, "Please, translate it)\n" + $"{u.TopicWords[nt].Russian}"); u.TopicWords.RemoveAt(nt); break; } } } await DBUser.SaveChangesAsync(); }