Persist the date that was last checked for bdays, so we don't get double congratulations when the bot restarts

This commit is contained in:
Deukhoofd 2018-10-08 18:59:50 +02:00
parent fd0a58293c
commit 25d2af9dda
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
2 changed files with 11 additions and 0 deletions

View File

@ -67,6 +67,14 @@ namespace DeukBot4.Database
((end.Month == start.Month) && (end.Day >= start.Day))) ? 1 : 0); ((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; private static DateTime _lastCheckedDate;
// ReSharper disable once FunctionRecursiveOnAllPaths // ReSharper disable once FunctionRecursiveOnAllPaths
public static async Task CheckBirthdays() public static async Task CheckBirthdays()
@ -81,6 +89,8 @@ namespace DeukBot4.Database
if (today != _lastCheckedDate) if (today != _lastCheckedDate)
{ {
_lastCheckedDate = today; _lastCheckedDate = today;
var db = Redis.GetDatabase();
db.StringSet("lastCheckedBirthday", _lastCheckedDate.ToBinary().ToString("D"));
await ActualBirthdayCheck(today); await ActualBirthdayCheck(today);
} }
} }

View File

@ -27,6 +27,7 @@ namespace DeukBot4
private static async Task SetupScheduler() private static async Task SetupScheduler()
{ {
ReminderHandler.Main.CheckReminders(); ReminderHandler.Main.CheckReminders();
BirthdayHandler.Initialize();
BirthdayHandler.CheckBirthdays(); BirthdayHandler.CheckBirthdays();
} }