Query.cs 848 B

12345678910111213141516171819202122232425262728293031
  1. using System.Linq;
  2. using System.Threading.Tasks;
  3. using Telegram.Bot;
  4. using Telegram.Bot.Types;
  5. namespace MafiaTelegramBot.Models.Inlines
  6. {
  7. public abstract class Query
  8. {
  9. protected abstract string Name { get; }
  10. protected abstract Task Execute(long chatId, TelegramBotClient client);
  11. private bool Contains(string command)
  12. {
  13. return command.Contains(Name);
  14. }
  15. public static Task Update(Update update)
  16. {
  17. var queries = Bot.Queries;
  18. var data = update.CallbackQuery.Data;
  19. var chatId = update.CallbackQuery.Message.Chat.Id;
  20. var client = Bot.Get();
  21. return (from query in queries
  22. where query.Contains(data)
  23. select query.Execute(chatId, client)).FirstOrDefault();
  24. }
  25. }
  26. }