StartGameQuery.cs 1.1 KB

12345678910111213141516171819202122232425262728
  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.Inlines
  8. {
  9. public class StartGameQuery : Query
  10. {
  11. protected override Callback Name => Callback.StartGame;
  12. protected override async Task<Message> Execute(Update update)
  13. {
  14. await DeletePreviousMessage(ChatId, update.CallbackQuery.Message.MessageId);
  15. var owner = await UserDao.GetPlayerById(UserId);
  16. var roomKey = RoomEncrypter.GetCode(owner.GetRoomName());
  17. var room = RoomController.GetRoom(roomKey);
  18. if(room == null)
  19. return await Bot.SendWithMarkdown2(ChatId, strings.room_does_not_exists);
  20. var result = await Bot.SendWithMarkdown2(owner.ChatId, strings.game_process_started);
  21. var resultCode = await room.Prepare();
  22. if (resultCode != ResultCode.CodeOk) return await Utilities.GetResultCodeMessage(resultCode, ChatId);
  23. room.Start();
  24. return result;
  25. }
  26. }
  27. }