123456789101112131415161718192021222324252627282930 |
- using System.Threading.Tasks;
- using MafiaTelegramBot.Controllers;
- using MafiaTelegramBot.DataBase.EntityDao;
- using MafiaTelegramBot.Game;
- using MafiaTelegramBot.Resources;
- using Telegram.Bot.Types;
- namespace MafiaTelegramBot.Models.Commands
- {
- public class StartGameCommand : Command
- {
- protected override string Name => keyboard.begin_game;
- protected override async Task<Message> Execute(Update update)
- {
- var player = await UserDao.GetPlayerById(UserId);
- var roomKey = RoomEncrypter.GetCode(player.GetRoomName());
- var room = RoomController.GetRoom(roomKey);
- if(room == null)
- return await Bot.SendWithMarkdown2(ChatId, strings.room_does_not_exists);
- if (!player.Equals(room.Owner))
- return await Bot.SendWithMarkdown2(ChatId, $"{strings.command_not_found} _*({update.Message.Text})*_");
- if (room.IsExtended) return await Bot.SendWithMarkdown2(player.ChatId, strings.continue_question, Keyboard.StartExtendedRoomKeyboard(UserId));
- var result = await Bot.SendWithMarkdown2(player.ChatId, strings.game_process_started);
- var resultCode = await room.Prepare();
- if (resultCode != ResultCode.CodeOk) return await Utilities.GetResultCodeMessage(resultCode, ChatId);
- room.Start();
- return result;
- }
- }
- }
|