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:
parent
fd0a58293c
commit
25d2af9dda
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue