Bugfix: Wait in the right reminder next, fix regexes
All checks were successful
continuous-integration/laminar-elessar Build 77 succeeded in 46 seconds .

This commit is contained in:
Starbeamrainbowlabs 2019-03-11 21:21:18 +00:00
parent 23a9fa3ed7
commit 64bb9550b3
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
3 changed files with 23 additions and 8 deletions

View file

@ -267,9 +267,9 @@ namespace RhinoReminds
@"^remind\s+(?:me\s+)?", @"^remind\s+(?:me\s+)?",
@"^me\s+", @"^me\s+",
@"^on\s+", @"^on\s+",
@"you", @"\byou\b",
@"your", @"\byour\b",
@"my", @"\bmy\b",
@"&" // Ampersands cause a crash when sending! @"&" // Ampersands cause a crash when sending!
}, new string[] { }, new string[] {
" ", " ",
@ -346,8 +346,12 @@ namespace RhinoReminds
nextWaitingTime = nextReminder.Time - DateTime.Now; nextWaitingTime = nextReminder.Time - DateTime.Now;
if (DateTime.Now < nextReminder.Time) if (DateTime.Now < nextReminder.Time)
{ {
Console.WriteLine($"[Rhino/Reminderd] Next reminder: {nextReminder}");
Console.WriteLine($"[Rhino/Reminderd] Sleeping for {nextWaitingTime}"); Console.WriteLine($"[Rhino/Reminderd] Sleeping for {nextWaitingTime}");
await Task.Delay(nextWaitingTime, reminderWatcherResetToken); int nextWaitingTimeMs = (int)nextWaitingTime.TotalMilliseconds;
if (nextWaitingTimeMs < 0) // if it overflows, sort it out
nextWaitingTimeMs = int.MaxValue;
await Task.Delay(nextWaitingTimeMs, reminderWatcherResetToken);
} }
} }
else { else {
@ -361,11 +365,14 @@ namespace RhinoReminds
continue; continue;
} }
if (reminderWatcherResetToken.IsCancellationRequested) if (reminderWatcherResetToken.IsCancellationRequested) {
{
Console.WriteLine("[Rhino/Reminderd] Sleep interrupted, recalculating (but no exception thrown)"); Console.WriteLine("[Rhino/Reminderd] Sleep interrupted, recalculating (but no exception thrown)");
continue; continue;
} }
if (nextReminder.Time > DateTime.Now.AddSeconds(-1)) {
Console.WriteLine("[Rhino/Reminderd] Didn't sleep for long enough, going back to bed *yawn*");
continue;
}
Console.WriteLine($"[Rhino/Reminderd] Sending notification {nextReminder}"); Console.WriteLine($"[Rhino/Reminderd] Sending notification {nextReminder}");
Jid targetJid = nextReminder.Jid; // Apparently nextReminder is null after the sendAndDeleteReminder() call - very odd! Jid targetJid = nextReminder.Jid; // Apparently nextReminder is null after the sendAndDeleteReminder() call - very odd!

View file

@ -11,7 +11,7 @@ namespace RhinoReminds
public int Compare(Reminder x, Reminder y) public int Compare(Reminder x, Reminder y)
{ {
return (int)(x.Time - y.Time).TotalMilliseconds; return (int)(y.Time - x.Time).TotalMilliseconds;
} }
} }
} }

View file

@ -41,7 +41,7 @@ namespace RhinoReminds
if (Reminders.Count == 0) if (Reminders.Count == 0)
return null; return null;
return Reminders.Min; return Reminders.Max;
} }
public Reminder GetById(int targetId) { public Reminder GetById(int targetId) {
@ -105,5 +105,13 @@ namespace RhinoReminds
} }
#endregion #endregion
public override string ToString()
{
string result = "Reminder list:";
foreach (Reminder nextReminder in Reminders)
Console.WriteLine($" - {nextReminder}");
return result;
}
} }
} }