ChangeRolesQuery.cs 1.3 KB

123456789101112131415161718192021222324252627282930
  1. using System.Threading.Tasks;
  2. using MafiaTelegramBot.Controllers;
  3. using MafiaTelegramBot.DataBase.EntityDao;
  4. using MafiaTelegramBot.Game;
  5. using MafiaTelegramBot.Game.GameRooms;
  6. using MafiaTelegramBot.Resources;
  7. using Telegram.Bot.Types;
  8. namespace MafiaTelegramBot.Models.Inlines
  9. {
  10. public class ChangeRolesQuery : Query
  11. {
  12. protected override Callback Name => Callback.ChangeRoles;
  13. protected override async Task<Message> Execute(Update update)
  14. {
  15. var user = await UserDao.GetPlayerById(UserId);
  16. var roomKey = RoomEncrypter.GetCode(user.GetRoomName());
  17. var room = (ExtendedGameRoom) RoomController.GetRoom(roomKey);
  18. if(room.CustomRoomSettings.Count == 0) await room.InitSettings();
  19. var message = $"{strings.current_enabled_roles}";
  20. foreach (var (role, count) in room.CustomRoomSettings)
  21. {
  22. if (role is Roles.Mafia) message += $"\n| {roles.Mafia} \\({count}\\) |";
  23. if (role is Roles.Villager) message += $"\n| {roles.Villager} \\({count}\\) |";
  24. else message += $"\n| {roles.ResourceManager.GetString(role.ToString())} \\({count}\\) |";
  25. }
  26. return await Bot.SendWithMarkdown2(ChatId, message, Keyboard.ChangeRolesKeyboard(UserId, roomKey, room));
  27. }
  28. }
  29. }