Command.cs 918 B

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