瀏覽代碼

decrease stickers count when send sticker

Tigran 4 年之前
父節點
當前提交
4c139076cf

+ 1 - 1
CardCollector/Commands/ChosenInlineResult/ChosenInlineResult.cs

@@ -14,7 +14,7 @@ namespace CardCollector.Commands.ChosenInlineResult
         
         private static readonly List<ChosenInlineResult> List = new()
         {
-            //new StickerInlineResult(),
+            new SendStickerResult(),
         };
         
         public static async Task<UpdateModel> Factory(Update update)

+ 24 - 0
CardCollector/Commands/ChosenInlineResult/SendStickerResult.cs

@@ -0,0 +1,24 @@
+using System.Threading.Tasks;
+using CardCollector.DataBase.Entity;
+using CardCollector.DataBase.EntityDao;
+using Telegram.Bot.Types;
+
+namespace CardCollector.Commands.ChosenInlineResult
+{
+    public class SendStickerResult : ChosenInlineResult
+    {
+        protected override string Command => "send_sticker";
+        public override async Task<Telegram.Bot.Types.Message> Execute()
+        {
+            var shortHash = InlineResult.Split('=')[1];
+            var stickerRelation = await UserStickerRelationDao.GetByShortHash(shortHash);
+            stickerRelation.Count--;
+            return new Telegram.Bot.Types.Message();
+        }
+        
+        public SendStickerResult(UserEntity user, Update update, string inlineResult)
+            : base(user, update, inlineResult) { }
+
+        public SendStickerResult() { }
+    }
+}

+ 6 - 1
CardCollector/DataBase/EntityDao/UserStickerRelationDao.cs

@@ -13,11 +13,16 @@ namespace CardCollector.DataBase.EntityDao
         public static async Task<Dictionary<string, UserStickerRelationEntity>> GetListById(long userId)
         {
             var result = await Table
-                .Where(i => i.UserId == userId)
+                .Where(i => i.UserId == userId && i.Count > 0)
                 .ToDictionaryAsync(p=> p.StickerId, p=> p);
             return result;
         }
 
+        public static async Task<UserStickerRelationEntity> GetByShortHash(string shortHash)
+        {
+            return await Table.FirstAsync(i => i.ShortHash == shortHash);
+        }
+
         private static async Task<UserStickerRelationEntity> AddNew(long userId, string stickerId, int count)
         {
             var cash = new UserStickerRelationEntity

+ 1 - 2
CardCollector/Resources/Constants.cs

@@ -4,8 +4,7 @@ namespace CardCollector.Resources
     {
         public const bool DEBUG = true;
 
-        public const int MEMORY_CLEANER_INTERVAL = 60 * 1000;
         public const double SAVING_CHANGES_INTERVAL = DEBUG ? 10 * 1000 : 5 * 60 * 1000;
-        public const int INLINE_RESULTS_CACHE_TIME = 5;
+        public const int INLINE_RESULTS_CACHE_TIME = 1;
     }
 }