diff --git a/DeukBot4/Database/BirthdayHandler.cs b/DeukBot4/Database/BirthdayHandler.cs index a074ff6..61e81d9 100644 --- a/DeukBot4/Database/BirthdayHandler.cs +++ b/DeukBot4/Database/BirthdayHandler.cs @@ -67,6 +67,14 @@ namespace DeukBot4.Database ((end.Month == start.Month) && (end.Day >= start.Day))) ? 1 : 0); } + public static void Initialize() + { + var db = Redis.GetDatabase(); + var dbValue = db.StringGet("lastCheckedBirthday"); + if (dbValue.HasValue) + _lastCheckedDate = DateTime.FromBinary(long.Parse(dbValue)); + } + private static DateTime _lastCheckedDate; // ReSharper disable once FunctionRecursiveOnAllPaths public static async Task CheckBirthdays() @@ -81,6 +89,8 @@ namespace DeukBot4.Database if (today != _lastCheckedDate) { _lastCheckedDate = today; + var db = Redis.GetDatabase(); + db.StringSet("lastCheckedBirthday", _lastCheckedDate.ToBinary().ToString("D")); await ActualBirthdayCheck(today); } } diff --git a/DeukBot4/Program.cs b/DeukBot4/Program.cs index 283e30b..244a82d 100644 --- a/DeukBot4/Program.cs +++ b/DeukBot4/Program.cs @@ -27,6 +27,7 @@ namespace DeukBot4 private static async Task SetupScheduler() { ReminderHandler.Main.CheckReminders(); + BirthdayHandler.Initialize(); BirthdayHandler.CheckBirthdays(); }