Fixes for BirthdayHandler

This commit is contained in:
Deukhoofd 2020-03-22 10:16:00 +01:00
parent 8e56152201
commit da6c73be42
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
1 changed files with 20 additions and 18 deletions

View File

@ -81,19 +81,21 @@ namespace DeukBot4.Database
} }
private static DateTime _lastCheckedDate; private static DateTime _lastCheckedDate;
// ReSharper disable once FunctionRecursiveOnAllPaths
public static async Task CheckBirthdays() public static async Task CheckBirthdays()
{ {
var today = DateTime.UtcNow.Date - new TimeSpan(6, 0 , 0); while (true)
{
try
{
var today = DateTime.UtcNow - new TimeSpan(6, 0, 0);
while (!Program.IsConnected) while (!Program.IsConnected)
{ {
await Task.Delay(500); await Task.Delay(500);
} }
try
if (today.Date != _lastCheckedDate)
{ {
if (today != _lastCheckedDate) _lastCheckedDate = today.Date;
{
_lastCheckedDate = today;
var db = Redis.GetDatabase(); var db = Redis.GetDatabase();
db.StringSet("lastCheckedBirthday", _lastCheckedDate.ToBinary().ToString("D")); db.StringSet("lastCheckedBirthday", _lastCheckedDate.ToBinary().ToString("D"));
await ActualBirthdayCheck(today); await ActualBirthdayCheck(today);
@ -104,7 +106,7 @@ namespace DeukBot4.Database
Logger.Main.LogError(e); Logger.Main.LogError(e);
} }
await Task.Delay(TimeSpan.FromHours(1)); await Task.Delay(TimeSpan.FromHours(1));
await CheckBirthdays(); }
} }