ShowInfo.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System.Globalization;
  2. using System.Threading.Tasks;
  3. using CardCollector.Controllers;
  4. using CardCollector.DataBase.Entity;
  5. using CardCollector.DataBase.EntityDao;
  6. using CardCollector.Resources;
  7. using CardCollector.Session.Modules;
  8. using Telegram.Bot.Types;
  9. namespace CardCollector.Commands.CallbackQuery
  10. {
  11. public class ShowInfo : CallbackQueryCommand
  12. {
  13. protected override string CommandText => Command.show_offer_info;
  14. public override async Task Execute()
  15. {
  16. var offerInfo = User.Session.GetModule<ShopModule>().SelectedPosition;
  17. var message = $"{offerInfo.Title}";
  18. if (offerInfo.Discount > 0) message += $"\n{Text.discount}: {offerInfo.Discount}%";
  19. if (offerInfo.AdditionalPrize != "")
  20. message += $"\n{Text.prize}: {await PrizeToString(offerInfo.AdditionalPrize)}";
  21. var dateText = offerInfo.TimeLimited
  22. ? offerInfo.TimeLimit.ToString(CultureInfo.CurrentCulture).Split(' ')[0]
  23. : Text.unexpired;
  24. message += $"\n{Text.time_limit} {dateText}";
  25. if (offerInfo.Description != "") message += $"\n{Text.description}: {offerInfo.Description}";
  26. await MessageController.AnswerCallbackQuery(User, CallbackQueryId, message, true);
  27. }
  28. private async Task<string> PrizeToString(string prize)
  29. {
  30. var data = prize.Split('=');
  31. return data[0] switch
  32. {
  33. "tier" => $"{Text.sticker} {data[1]} {Text.tier2}",
  34. "sticker" => $"{Text.sticker} {(await StickerDao.GetStickerByHash(data[1])).Title}",
  35. _ => ""
  36. };
  37. }
  38. public ShowInfo() { }
  39. public ShowInfo(UserEntity user, Update update) : base(user, update) { }
  40. }
  41. }