StartGameCommand.cs 1.4 KB

123456789101112131415161718192021222324252627282930
  1. using System.Threading.Tasks;
  2. using MafiaTelegramBot.Controllers;
  3. using MafiaTelegramBot.DataBase.EntityDao;
  4. using MafiaTelegramBot.Game;
  5. using MafiaTelegramBot.Resources;
  6. using Telegram.Bot.Types;
  7. namespace MafiaTelegramBot.Models.Commands
  8. {
  9. public class StartGameCommand : Command
  10. {
  11. protected override string Name => keyboard.begin_game;
  12. protected override async Task<Message> Execute(Update update)
  13. {
  14. var player = await UserDao.GetPlayerById(UserId);
  15. var roomKey = RoomEncrypter.GetCode(player.GetRoomName());
  16. var room = RoomController.GetRoom(roomKey);
  17. if(room == null)
  18. return await Bot.SendWithMarkdown2(ChatId, strings.room_does_not_exists);
  19. if (!player.Equals(room.Owner))
  20. return await Bot.SendWithMarkdown2(ChatId, $"{strings.command_not_found} _*({update.Message.Text})*_");
  21. if (room.IsExtended) return await Bot.SendWithMarkdown2(player.ChatId, strings.continue_question, Keyboard.StartExtendedRoomKeyboard(UserId));
  22. var result = await Bot.SendWithMarkdown2(player.ChatId, strings.game_process_started);
  23. var resultCode = await room.Prepare();
  24. if (resultCode != ResultCode.CodeOk) return await Utilities.GetResultCodeMessage(resultCode, ChatId);
  25. room.Start();
  26. return result;
  27. }
  28. }
  29. }