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

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+)?",
@"^me\s+",
@"^on\s+",
@"you",
@"your",
@"my",
@"\byou\b",
@"\byour\b",
@"\bmy\b",
@"&" // Ampersands cause a crash when sending!
}, new string[] {
" ",
@ -346,8 +346,12 @@ namespace RhinoReminds
nextWaitingTime = nextReminder.Time - DateTime.Now;
if (DateTime.Now < nextReminder.Time)
{
Console.WriteLine($"[Rhino/Reminderd] Next reminder: {nextReminder}");
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 {
@ -361,11 +365,14 @@ namespace RhinoReminds
continue;
}
if (reminderWatcherResetToken.IsCancellationRequested)
{
if (reminderWatcherResetToken.IsCancellationRequested) {
Console.WriteLine("[Rhino/Reminderd] Sleep interrupted, recalculating (but no exception thrown)");
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}");
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)
{
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)
return null;
return Reminders.Min;
return Reminders.Max;
}
public Reminder GetById(int targetId) {
@ -105,5 +105,13 @@ namespace RhinoReminds
}
#endregion
public override string ToString()
{
string result = "Reminder list:";
foreach (Reminder nextReminder in Reminders)
Console.WriteLine($" - {nextReminder}");
return result;
}
}
}