EnterGemsPrice.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 Dictionary<long, int> 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, Queue[User.Id],
  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, Queue[User.Id],
  29. $"{Messages.confirm_selling} {module.SellPrice}{Text.gem}:", Keyboard.AuctionPutCancelKeyboard);
  30. Queue.Remove(User.Id);
  31. }
  32. }
  33. //Добавляем пользователя в очередь #1#
  34. public static void AddToQueue(long userId, int messageId)
  35. {
  36. Queue.TryAdd(userId, messageId);
  37. }
  38. //Удаляем пользователя из очереди #1#
  39. public static void RemoveFromQueue(long userId)
  40. {
  41. Queue.Remove(userId);
  42. }
  43. // Переопределяем метод, так как команда удовлетворяет условию, если пользователь находится в очереди #1#
  44. protected internal override bool IsMatches(UserEntity user, Update update)
  45. {
  46. return Queue.ContainsKey(user.Id) && update.Message!.Type == MessageType.Text;
  47. }
  48. public EnterGemsPrice() { }
  49. public EnterGemsPrice(UserEntity user, Update update) : base(user, update) { }
  50. }
  51. }