StartGameQuery.cs 996 B

1234567891011121314151617181920212223242526
  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. var owner = await UserDao.GetPlayerById(UserId);
  15. var roomKey = RoomEncrypter.GetCode(owner.GetRoomName());
  16. var room = RoomController.GetRoom(roomKey);
  17. var result = await Bot.SendWithMarkdown2(owner.ChatId, strings.game_process_started);
  18. var resultCode = await room.Prepare();
  19. if (resultCode != ResultCode.CodeOk) return await Utilities.GetResultCodeMessage(resultCode, ChatId);
  20. await room.SendRolesToUsers();
  21. room.Start();
  22. return result;
  23. }
  24. }
  25. }