EnterCodeMessageHandler.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using MafiaTelegramBot.Controllers;
  4. using MafiaTelegramBot.CustomCollections.Extensions;
  5. using MafiaTelegramBot.Game;
  6. using MafiaTelegramBot.Resources;
  7. using Telegram.Bot.Types;
  8. namespace MafiaTelegramBot.Commands.Messages
  9. {
  10. public class EnterCodeHandler : MessageHandler
  11. {
  12. protected override string Command => "";
  13. private static readonly List<long> Queue = new();
  14. public static void AddToQueue(long id)
  15. {
  16. Queue.AddUnique(id);
  17. }
  18. public override bool IsMatches(string command)
  19. {
  20. return User != null ? Queue.Contains(User.Info.Id) : base.IsMatches(command);
  21. }
  22. public override async Task<Message> Execute(Update update)
  23. {
  24. var roomKey = update.Message.Text;
  25. var resultCode = await RoomController.ConnectToGame(User, roomKey);
  26. var result = resultCode == ResultCode.CodeOk
  27. ? MessageController.SendText(User.Info, strings.successful_entry_into_room, Keyboard.PlayerGameMenu)
  28. : MessageController.SendText(User.Info, Utilities.GetResultCodeMessage(resultCode));
  29. return await result;
  30. }
  31. public EnterCodeHandler(Player player) : base(player) { }
  32. }
  33. }