1234567891011121314151617181920212223242526272829303132 |
- using System.Linq;
- using System.Threading.Tasks;
- using MafiaTelegramBot.Resources;
- using Telegram.Bot;
- using Telegram.Bot.Types;
- namespace MafiaTelegramBot.Models.Commands
- {
- public abstract class Command
- {
- protected abstract string Name { get; }
- protected abstract Task Execute(long chatId, TelegramBotClient client);
- private bool Contains(string command)
- {
- return command.Contains(Name) && command.Contains(AppSettings.Name);
- }
-
- public static Task Update(Update update)
- {
- var commands = Bot.Commands;
- var message = update.Message.Text;
- var chatId = update.Message.Chat.Id;
- var client = Bot.Get();
- return (from command in commands
- where command.Contains(message)
- select command.Execute(chatId, client)).FirstOrDefault();
- }
- }
- }
|