예제 #1
0
        /// <summary>
        /// Thread that handles all events that depend on the date
        /// </summary>
        public static void WeeklyReset()
        {
            while (true)
            {
                // Check for missed reset
                if (DateTime.UtcNow.RoundUp(TimeSpan.FromDays(1)) - LastDate.LastWeeklyReset.RoundUp(TimeSpan.FromDays(1)) >= new TimeSpan(7, 0, 0, 0))
                {
                    // reset things
                    UserDataManager.ResetWeekly();
                    UserDataManager.ResetRep();

                    // set the new time
                    LastDate.LastWeeklyReset = DateTime.UtcNow.LastSunday();

                    LastDate.Save();
                }
                else
                {
                    // if no reset was missed, wait for the next one.
                    Thread.Sleep(GetTimeDelay(TimeScale.WEEK));
                    // now reset rep
                    UserDataManager.ResetRep();
                    UserDataManager.ResetWeekly();
                    LastDate.LastWeeklyReset = DateTime.UtcNow.AddDays(-1).AddSeconds(1).RoundUp(TimeSpan.FromDays(1));
                    LastDate.Save();
                }

                KLog.Debug($"Last Weekly Reset: [{LastDate.LastWeeklyReset.ToString("F", CultureInfo.InvariantCulture)}]");

                Thread.Sleep(5000);  // SAFETY CLOCK, If the loop goes haywire it's not going to overload the bot.
            }
        }
예제 #2
0
        private static void SetupFiles()
        {
            // Check for the appropriate directories.
            foreach (string dir in DataFileNames.Folders) // Check through all the necessary directories
            {
                if (!Directory.Exists(dir))               // If the directory does not exist
                {
                    Directory.CreateDirectory(dir);       // Then create it
                }
            }

            // Special case for Excel files.
            // Only used for admin stuff atm
            AdminDataManager.InitExcel();

            // Now for the files
            // This loop uses Reflection to iterate through all of the file paths and create any missing files
            // The settings.json file is the only one that needs a default template generated for it, and was handled above.
            // The passedFolders variable is so that it skips the folder array.
            bool   passedFolders = false;
            string file;

            foreach (FieldInfo fieldInfo in typeof(DataFileNames).GetFields(BindingFlags.Static | BindingFlags.Public))
            {
                if (!passedFolders)
                {
                    passedFolders = true;
                    continue;
                }

                file = fieldInfo.GetValue(null) as string;

                if (!File.Exists(file))
                {
                    Console.WriteLine($"Generated {file}");
                    File.CreateText(file).Close();  // This creates the file, then closes the unecessary stream writer
                }
            }

            AchievementManager.LoadNodeMap();

            // RESET DATES
            LastDateNode dates = JsonConvert.DeserializeObject <LastDateNode>(FileManager.ReadFullFile(DataFileNames.LastDateFile));

            if (dates == null)
            {
                dates = new LastDateNode(DateTime.UtcNow.LastSunday(), DateTime.UtcNow);
                dates.Save();
            }

            BotUtils.LastDate = dates;
        }