private static async void GetVote(Message message, TelegramBotClient bot) { try { var votes = VoteSystem.GetVotesNames(); if (!votes.Any()) { await bot.SendTextMessageAsync(message.Chat.Id, $"*Нет открытых голосований*", ParseMode.Markdown, false, false, 0, CommandsCenter.GetMenu("StartMenu").Keyboard); return; } KeyboardButton[][] keyboard = new KeyboardButton[votes.Count() + 1][]; int i = 0; keyboard[i++] = new KeyboardButton[] { new KeyboardButton("[Назад в меню]") }; foreach (var vote in votes) { keyboard[i++] = new KeyboardButton[] { CommandsCenter.GetReplyButton(vote).Button }; } await bot.SendTextMessageAsync(message.Chat.Id, $"*Список открытых голосований:*", ParseMode.Markdown, false, false, 0, new ReplyMenu("", true, keyboard).Keyboard); } catch { } }
private void Bot_OnUpdate(object sender, UpdateEventArgs e) { string info = "Неизвестная ошибка."; try { if (e.Update.CallbackQuery != null || e.Update.InlineQuery != null) { return; } var update = e.Update; var message = update.Message; if (message == null) { return; } var user = UserDatabase.GetUser(message.Chat.Id); if (user == null) { CommandsCenter.GetReplyButton("/start").Callback.Execute(message, Bot, null); return; } if (message.Text.StartsWith("/send")) { CommandsCenter.GetReplyButton("/send").Callback.Execute(message, Bot, null); return; } else if (message.Text.StartsWith("/vote")) { CommandsCenter.GetReplyButton("/vote").Callback.Execute(message, Bot, null); return; } if (user.CommandRegex.regex.Match(message.Text).Value == message.Text) { user.CommandRegex.done.Execute(message, Bot); } else { user.CommandRegex.failed.Execute(message, Bot); } } catch (Exception ex) { BotConsole.Write($"Ошибка в {info}:\n" + ex.Message + "\nStackStrace:\n" + ex.StackTrace, MessageType.Error); } }