SendStickerCommand.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. using CardCollector.DataBase.Entity;
  5. using CardCollector.DataBase.EntityDao;
  6. using Telegram.Bot.Types;
  7. namespace CardCollector.Commands.ChosenInlineResult
  8. {
  9. public abstract class SendStickerCommand : ChosenInlineResultCommand
  10. {
  11. private static PeopleSendsSticker info = PeopleSendsSticker.Build().Result;
  12. public override async Task AfterExecute()
  13. {
  14. if (!info.Actual())
  15. {
  16. info.WriteResults();
  17. info = await PeopleSendsSticker.Build();
  18. }
  19. info.Add(User.Id);
  20. }
  21. private class PeopleSendsSticker
  22. {
  23. private DateTime infoDate;
  24. private CountLogs logsEntity;
  25. private HashSet<long> People = new();
  26. public static async Task<PeopleSendsSticker> Build()
  27. {
  28. var result = new PeopleSendsSticker();
  29. result.infoDate = DateTime.Today;
  30. result.logsEntity = await CountLogsDao.Get(result.infoDate);
  31. return result;
  32. }
  33. public bool Actual()
  34. {
  35. return infoDate.Equals(DateTime.Today);
  36. }
  37. public void Add(long userId)
  38. {
  39. People.Add(userId);
  40. }
  41. public void WriteResults()
  42. {
  43. logsEntity.PeopleSendsStickerOneOrMoreTimes += People.Count;
  44. }
  45. }
  46. public static void WriteLogs()
  47. {
  48. info.WriteResults();
  49. }
  50. protected SendStickerCommand() { }
  51. protected SendStickerCommand(UserEntity user, Update update) : base(user, update) { }
  52. }
  53. }