SelectStickerInlineResult.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System.Threading.Tasks;
  2. using CardCollector.Controllers;
  3. using CardCollector.DataBase.Entity;
  4. using CardCollector.DataBase.EntityDao;
  5. using CardCollector.Others;
  6. using CardCollector.Resources;
  7. using Telegram.Bot.Types;
  8. namespace CardCollector.Commands.ChosenInlineResult
  9. {
  10. public class SelectStickerInlineResult : ChosenInlineResult
  11. {
  12. protected override string CommandText => Command.select_sticker;
  13. public override async Task Execute()
  14. {
  15. await User.ClearChat();
  16. var hash = InlineResult.Split('=')[1];
  17. var sticker = await StickerDao.GetStickerByHash(hash);
  18. var stickerCount = User.Session.State switch
  19. {
  20. UserState.AuctionMenu => await AuctionController.GetStickerCount(sticker.Id),
  21. UserState.ShopMenu => await ShopController.GetStickerCount(sticker.Id),
  22. _ => User.Stickers[sticker.Md5Hash].Count
  23. };
  24. var stickerInfo = new StickerInfo(sticker) {MaxCount = stickerCount};
  25. User.Session.SelectedSticker = stickerInfo;
  26. var stickerMessage = await MessageController.SendSticker(User, sticker.Id);
  27. var infoMessage = await MessageController.SendMessage(User, stickerInfo.ToString(), Keyboard.GetStickerKeyboard(User.Session));
  28. User.Session.Messages.Add(stickerMessage.MessageId);
  29. User.Session.Messages.Add(infoMessage.MessageId);
  30. }
  31. public SelectStickerInlineResult() { }
  32. public SelectStickerInlineResult(UserEntity user, Update update) : base(user, update) { }
  33. }
  34. }