using System.Collections.Generic; using System.Threading.Tasks; using MafiaTelegramBot.Models.Commands.CustomMessageHandlers; using Telegram.Bot.Types; using Telegram.Bot.Types.Enums; namespace MafiaTelegramBot.Models.Commands { public abstract class Command : UpdateModel { private static Dictionary _customHandlers = new() { {"UsersThatChangesNickname", new ChangeNicknameCommand()}, {"UsersThatCreatesRoom", new CreateRoomCommand()}, {"UserThatEntersPrivateCode", new EnterPrivateRoomCommand()}, }; public static async Task Update(Update update) { var chatId = update.Message.Chat.Id; await Bot.Get().SendChatActionAsync(chatId, ChatAction.Typing); var commands = Bot.Commands; var message = update.Message.Text; var command = FirstOrDefault(commands, message); if (command != null) return await command.Execute(update); var userId = update.Message.From.Id; if (Bot.UsersThatChangesNickname.Remove(userId)) return await _customHandlers["UsersThatChangesNickname"].Execute(update); if (Bot.UsersThatCreatesRoom.ContainsKey(userId)) return await _customHandlers["UsersThatCreatesRoom"].Execute(update); if (Bot.UserThatEntersPrivateCode.Remove(userId)) return await _customHandlers["UserThatEntersPrivateCode"].Execute(update); return await Bot.SendWithMarkdown2(chatId, $"{strings.command_not_found} _*\\({message}\\)*_"); } } }