EnterGemsPriceMessage.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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.TextMessage
  10. {
  11. public class EnterGemsPriceMessage : Message
  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. await MessageController.EditMessage(User, Queue[User.Id],
  21. $"{Messages.current_price} {module.SellPrice}{Text.gem}\n{Messages.please_enter_price}",
  22. Keyboard.AuctionPutCancelKeyboard);
  23. else
  24. {
  25. module.SellPrice = price;
  26. await MessageController.EditMessage(User, Queue[User.Id],
  27. $"{Messages.confirm_selling} {module.SellPrice}{Text.gem}:", Keyboard.AuctionPutCancelKeyboard);
  28. Queue.Remove(User.Id);
  29. }
  30. }
  31. //Добавляем пользователя в очередь #1#
  32. public static void AddToQueue(long userId, int messageId)
  33. {
  34. Queue.TryAdd(userId, messageId);
  35. }
  36. //Удаляем пользователя из очереди #1#
  37. public static void RemoveFromQueue(long userId)
  38. {
  39. Queue.Remove(userId);
  40. }
  41. // Переопределяем метод, так как команда удовлетворяет условию, если пользователь находится в очереди #1#
  42. protected internal override bool IsMatches(UserEntity user, Update update)
  43. {
  44. return Queue.ContainsKey(user.Id) && update.Message!.Type == MessageType.Text;
  45. }
  46. public EnterGemsPriceMessage() { }
  47. public EnterGemsPriceMessage(UserEntity user, Update update) : base(user, update) { }
  48. }
  49. }