EnterGemsPrice.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using CardCollector.Controllers;
  4. using CardCollector.DataBase.Entity;
  5. using CardCollector.Resources;
  6. using CardCollector.Session.Modules;
  7. using Telegram.Bot.Types;
  8. using Telegram.Bot.Types.Enums;
  9. namespace CardCollector.Commands.Message
  10. {
  11. public class EnterGemsPrice : MessageCommand
  12. {
  13. protected override string CommandText => "";
  14. private static readonly List<long> Queue = new ();
  15. public override async Task Execute()
  16. {
  17. /* если пользователь ввел что-то кроме эмодзи */
  18. var module = User.Session.GetModule<CollectionModule>();
  19. if (!int.TryParse(Update.Message!.Text, out var price) || price < 0)
  20. {
  21. await MessageController.EditMessage(User,
  22. $"{Messages.current_price} {module.SellPrice}{Text.gem}\n{Messages.please_enter_integer}",
  23. Keyboard.AuctionPutCancelKeyboard);
  24. }
  25. else
  26. {
  27. module.SellPrice = price;
  28. await MessageController.EditMessage(User, $"{Messages.confirm_selling} {module.SellPrice}{Text.gem}:" +
  29. $"\n{Messages.or_enter_another_sum}", Keyboard.AuctionPutCancelKeyboard);
  30. }
  31. }
  32. /* Добавляем пользователя в очередь */
  33. public static void AddToQueue(long userId)
  34. {
  35. if (!Queue.Contains(userId)) Queue.Add(userId);
  36. }
  37. /* Удаляем пользователя из очереди */
  38. public static void RemoveFromQueue(long userId)
  39. {
  40. Queue.Remove(userId);
  41. }
  42. protected internal override bool IsMatches(UserEntity user, Update update)
  43. {
  44. return Queue.Contains(user.Id) && update.Message!.Type == MessageType.Text;
  45. }
  46. public EnterGemsPrice() { }
  47. public EnterGemsPrice(UserEntity user, Update update) : base(user, update) { }
  48. }
  49. }