LeaveCommand.cs 874 B

123456789101112131415161718192021222324
  1. using System.Threading.Tasks;
  2. using MafiaTelegramBot.Controllers;
  3. using MafiaTelegramBot.DataBase;
  4. using MafiaTelegramBot.DataBase.EntityDao;
  5. using MafiaTelegramBot.Resources;
  6. using Telegram.Bot.Types;
  7. namespace MafiaTelegramBot.Models.Commands
  8. {
  9. public class LeaveCommand : Command
  10. {
  11. protected override string Name => keyboard.leave;
  12. protected override async Task<Message> Execute(Update update)
  13. {
  14. var user = await UserDao.GetPlayerById(UserId);
  15. var roomName = user.GetRoomName();
  16. var resultCode = await RoomController.LeaveFromGame(user);
  17. return resultCode == ResultCode.CodeOk
  18. ? await Bot.SendWithMarkdown2(ChatId, $"{strings.leave_from_game} _*{roomName}*_", Keyboards.MainMenu)
  19. : await Utilities.GetResultCodeMessage(resultCode, ChatId);
  20. }
  21. }
  22. }