瀏覽代碼

Fart Smella

Tigran 3 年之前
父節點
當前提交
ca9a424a19

+ 7 - 5
CardCollector/Bot.cs

@@ -30,9 +30,9 @@ namespace CardCollector
 
         private static readonly IEnumerable<BotCommand> _commands = new[]
         {
-            new BotCommand {Command = "/menu", Description = "Показать меню"},
+            new BotCommand {Command = "/menu", Description = "Показать меню"},/*
             new BotCommand {Command = "/help", Description = "Показать информацию"},
-            new BotCommand {Command = "/error", Description = "Сообщить об ошибке"},
+            new BotCommand {Command = "/error", Description = "Сообщить об ошибке"},*/
         };
 
         public static void Main(string[] args)
@@ -59,12 +59,14 @@ namespace CardCollector
 
         public static void StopProgram()
         {
-            _timer.Elapsed += (_, _) =>
+            _timer.Elapsed += OnTimerOnElapsed;
+
+            static async void OnTimerOnElapsed(object o, ElapsedEventArgs elapsedEventArgs)
             {
                 _timer.Stop();
-                UserDao.ClearMemory();
+                await UserDao.ClearMemory();
                 _end.Set();
-            };
+            }
         }
 
         private static async void SavingChanges(object o, ElapsedEventArgs e)

+ 2 - 1
CardCollector/Commands/CallbackQuery/OpenPackCallback.cs

@@ -18,6 +18,7 @@ namespace CardCollector.Commands.CallbackQuery
             var packId = int.Parse(CallbackData.Split("=")[1]);
             var userPack = await UsersPacksDao.GetUserPacks(User.Id);
             var rnd = new Random();
+            var packInfo = await PacksDao.GetById(packId);
             var tier = GetTier(rnd.NextDouble() * 100);
             switch (packId)
             {
@@ -31,13 +32,13 @@ namespace CardCollector.Commands.CallbackQuery
                 default:
                     if (!await TryOpen()) 
                         await MessageController.AnswerCallbackQuery(User, CallbackQueryId, Messages.packs_count_zero, true);
-                    var packInfo = await PacksDao.GetById(packId);
                     await OpenPack(await StickerDao.GetListWhere(item => item.Tier == tier && item.Author == packInfo.Author));
                     break;
             }
 
             async Task OpenPack(List<StickerEntity> stickers)
             {
+                packInfo.OpenedCount++;
                 await User.ClearChat();
                 var sticker = stickers[rnd.Next(stickers.Count)];
                 if (User.Stickers.ContainsKey(sticker.Md5Hash))

+ 2 - 2
CardCollector/DataBase/Entity/CashEntity.cs

@@ -17,10 +17,10 @@ namespace CardCollector.DataBase.Entity
         [Column("user_id"), MaxLength(127)] public long UserId { get; set; }
         
         /* Количество монет */
-        [Column("coins"), MaxLength(32)] public int Coins { get; set; } = 10000;
+        [Column("coins"), MaxLength(32)] public int Coins { get; set; } = 0;
         
         /* Количество алмазов */
-        [Column("gems"), MaxLength(32)] public int Gems { get; set; } = 1000;
+        [Column("gems"), MaxLength(32)] public int Gems { get; set; } = 0;
         
         /* Размер копилки */
         [Column("max_capacity"), MaxLength(32)] public int MaxCapacity { get; set; } = 200;

+ 3 - 0
CardCollector/DataBase/Entity/PackEntity.cs

@@ -14,5 +14,8 @@ namespace CardCollector.DataBase.Entity
         
         /* Описание */
         [Column("description"), MaxLength(512)] public string Description { get; set; }
+        
+        /* Количество открытий */
+        [Column("opened_count"), MaxLength(127)] public long OpenedCount { get; set; } = 0;
     }
 }

+ 4 - 4
CardCollector/DataBase/EntityDao/UserDao.cs

@@ -79,21 +79,21 @@ namespace CardCollector.DataBase.EntityDao
             return result.Entity;
         }
 
-        public static void ClearMemory(object sender, ElapsedEventArgs e)
+        public static async void ClearMemory(object sender, ElapsedEventArgs e)
         {
             foreach (var (id, user) in ActiveUsers)
             {
                 if (user.Session.GetLastAccessInterval() <= Constants.SESSION_ACTIVE_PERIOD) continue;
-                user.Session.EndSession();
+                await user.Session.EndSession();
                 ActiveUsers.Remove(id);
             }
         }
 
-        public static async void ClearMemory()
+        public static async Task ClearMemory()
         {
             foreach (var (id, user) in ActiveUsers.ToDictionary(pair => pair.Key, pair => pair.Value))
             {
-                user.Session.EndSession();
+                await user.Session.EndSession();
                 ActiveUsers.Remove(id);
                 await MessageController.SendMessage(user, Messages.bot_turning_off);
             }

+ 12 - 9
CardCollector/Resources/Constants.cs

@@ -7,27 +7,30 @@ namespace CardCollector.Resources
     public static class Constants
     {
         /* Переключить данный флаг при сборке на сервер */
-        public const bool DEBUG = true;
+        public const bool DEBUG = false;
 
         /* Интервал сохранения изменений */
         public const double SAVING_CHANGES_INTERVAL = DEBUG ? 10 * 1000 : 5 * 60 * 1000;
         /* Время кэширования результатов @имя_бота команд */
         public const int INLINE_RESULTS_CACHE_TIME = 1;
         /* Включает бесконечные стикеры без наличия их в коллекции */
-        public static readonly bool UNLIMITED_ALL_STICKERS = !DEBUG;
-
-
+        public static readonly bool UNLIMITED_ALL_STICKERS = false;
+        /* Время простоя удаления пользователей */
+        public const int SESSION_ACTIVE_PERIOD = DEBUG ? 1 : 60;
+        
         /* Уровни привилегий пользователей системы */
         public const int OWNER_PRIVILEGE_LEVEL = 10;
         public const int ADMIN_PRIVILEGE_LEVEL = 9;
-        public const int PROGRAMMER_PRIVILEGE_LEVEL = 5;
+        public const int PROGRAMMER_PRIVILEGE_LEVEL = 7;
         public const int ARTIST_PRIVILEGE_LEVEL = 4;
-        public const int SESSION_ACTIVE_PERIOD = DEBUG ? 1 : 60;
+        
+        /* Количество стикеров для создания комбинации */
         public const int COMBINE_COUNT = 5;
         
         /* Время оповещения и сброса ежедневных заданий */
-        public static readonly TimeSpan DailyTaskAlert = DEBUG ? new TimeSpan(20, 30, 00) : new TimeSpan(12, 0, 0);
-        public static readonly TimeSpan DailyTaskReset = DEBUG ? new TimeSpan(20, 30, 0) : new TimeSpan(0, 0, 0);
-        public static readonly TimeSpan DailyStickerRewardCheck = DEBUG ? new TimeSpan(20, 35, 0) : new TimeSpan(1, 0, 0);
+        public static readonly TimeSpan DailyTaskAlert = DEBUG ? new TimeSpan(20, 30, 0) : new TimeSpan(10, 0, 0);
+        public static readonly TimeSpan DailyTaskReset = DEBUG ? new TimeSpan(20, 30, 0) : new TimeSpan(10, 0, 0);
+        /* Время выдачи наград за пассивные эффекты стикеров */
+        public static readonly TimeSpan DailyStickerRewardCheck = DEBUG ? new TimeSpan(20, 35, 0) : new TimeSpan(11, 0, 0);
     }
 }

+ 1 - 1
CardCollector/Session/Session.cs

@@ -68,7 +68,7 @@ namespace CardCollector.Session
             Messages.Clear();
         }
 
-        public async void EndSession()
+        public async Task EndSession()
         {
             await ClearMessages();
             State = UserState.Default;