StartCommand.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. using System.Threading.Tasks;
  3. using MafiaTelegramBot.Controllers;
  4. using MafiaTelegramBot.DataBase.EntityDao;
  5. using MafiaTelegramBot.Resources;
  6. using Telegram.Bot.Types;
  7. namespace MafiaTelegramBot.Models.Commands
  8. {
  9. public class StartCommand : Command
  10. {
  11. protected override string Name => "/start";
  12. protected override async Task<Message> Execute(Update update)
  13. {
  14. var command = update.Message.Text.Split(' ');
  15. var player = await UserDao.GetPlayerById(UserId);
  16. Console.WriteLine(player.isAdmin);
  17. if (player.GetRoomName() != "")
  18. return await Bot.SendWithMarkdown2(ChatId, $"{strings.prefer_leave_from_room} {player.GetRoomName()}");
  19. if (command.Length <= 1)
  20. return await Bot.SendWithMarkdown2(ChatId, strings.start_message, player.IsAdmin ? Keyboard.AdminMainMenu : Keyboard.MainMenu);
  21. var code = await RoomController.ConnectToGame(player, command[1]);
  22. var result = code == ResultCode.CodeOk
  23. ? Bot.SendWithMarkdown2(ChatId, strings.successful_entry_into_room, Keyboard.PlayerGameMenu)
  24. : Utilities.GetResultCodeMessage(code, ChatId);
  25. return await result;
  26. }
  27. protected override bool IsMatches(string command)
  28. {
  29. var commandPart = command.Split(' ')[0];
  30. return base.IsMatches(commandPart);
  31. }
  32. }
  33. }