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 committed 2018-10-08 18:59:50 +02:00
1 parent fd0a58293c
commit 25d2af9dda
2 files changed
+11

No files matched your search

+10
View File
@@ -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);
}
}
+1
View File
@@ -27,6 +27,7 @@ namespace DeukBot4
private static async Task SetupScheduler()
{
ReminderHandler.Main.CheckReminders();
BirthdayHandler.Initialize();
BirthdayHandler.CheckBirthdays();
}