|
|
|
@ -1,4 +1,5 @@ |
|
|
|
|
using System; |
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
using System.IO; |
|
|
|
|
using System.Linq; |
|
|
|
|
using System.Net; |
|
|
|
@ -22,6 +23,8 @@ namespace RhinoReminds |
|
|
|
|
public string Hostname => Jid.Split('@')[1]; |
|
|
|
|
private readonly string password; |
|
|
|
|
|
|
|
|
|
public readonly List<string> AllowedDomains = new List<string>(); |
|
|
|
|
|
|
|
|
|
public string ReminderFilePath { get; set; } = "./reminders.xml"; |
|
|
|
|
private ReminderList reminderList = new ReminderList(); |
|
|
|
|
|
|
|
|
@ -62,6 +65,10 @@ namespace RhinoReminds |
|
|
|
|
#region XMPP Event Handling |
|
|
|
|
private bool subscriptionRequestHandler(Jid from) |
|
|
|
|
{ |
|
|
|
|
if (!AllowedDomains.Contains("*") && !AllowedDomains.Contains(from.Domain)) { |
|
|
|
|
sendChatMessage(from, "Sorry! The domain of your JID doesn't match the ones in my allowed list."); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
Console.WriteLine($"[Rhino/SubscriptionRequest] Approving subscription from {from}"); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
@ -90,6 +97,11 @@ namespace RhinoReminds |
|
|
|
|
|
|
|
|
|
private void messageHandler(Message message) |
|
|
|
|
{ |
|
|
|
|
if (!AllowedDomains.Contains("*") && !AllowedDomains.Contains(message.From.Domain)) { |
|
|
|
|
sendChatMessage(message.From, "Sorry! The domain of your JID doesn't match the ones in my allowed list."); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
string messageText = message.Body; |
|
|
|
|
string[] parts = Regex.Split(messageText.Trim(), @"\s+"); |
|
|
|
|
string instruction = parts[0].ToLower(); |
|
|
|
@ -117,8 +129,6 @@ namespace RhinoReminds |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case "remind": |
|
|
|
|
Console.WriteLine("[Rhino/Reciever] Identified remind request"); |
|
|
|
|
|
|
|
|
|
DateTime dateTime; string rawDateTimeString; |
|
|
|
|
try { |
|
|
|
|
dateTime = AIRecogniser.RecogniseDateTime(messageText, out rawDateTimeString); |
|
|
|
@ -183,10 +193,10 @@ namespace RhinoReminds |
|
|
|
|
Reminder nextReminder = reminderList.GetNextReminder(); |
|
|
|
|
reminderList.OnReminderListUpdate += (object sender, Reminder newReminder) => { |
|
|
|
|
Reminder newNextReminder = reminderList.GetNextReminder(); |
|
|
|
|
Console.WriteLine("[Rhino/Reminderd/Canceller] Reminder added - comparing."); |
|
|
|
|
Console.WriteLine($"[Rhino/Reminderd/Canceller] {nextReminder} / {newNextReminder}"); |
|
|
|
|
//Console.WriteLine("[Rhino/Reminderd/Canceller] Reminder added - comparing."); |
|
|
|
|
//Console.WriteLine($"[Rhino/Reminderd/Canceller] {nextReminder} / {newNextReminder}"); |
|
|
|
|
if (nextReminder != newNextReminder) { |
|
|
|
|
Console.WriteLine($"[Rhino/Reminderd/Canceller] Cancelling"); |
|
|
|
|
//Console.WriteLine($"[Rhino/Reminderd/Canceller] Cancelling"); |
|
|
|
|
nextReminder = newNextReminder; |
|
|
|
|
cancellationSource.Cancel(); |
|
|
|
|
} |
|
|
|
@ -199,15 +209,15 @@ namespace RhinoReminds |
|
|
|
|
if (nextReminder != null) { |
|
|
|
|
nextWaitingTime = nextReminder.Time - DateTime.Now; |
|
|
|
|
if (DateTime.Now < nextReminder.Time) { |
|
|
|
|
Console.WriteLine($"[Rhino/Reminderd] Sleeping for {nextWaitingTime}"); |
|
|
|
|
//Console.WriteLine($"[Rhino/Reminderd] Sleeping for {nextWaitingTime}"); |
|
|
|
|
await Task.Delay(nextWaitingTime, cancellationToken); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
Console.WriteLine("[Rhino/Reminderd] Sleeping until interrupted"); |
|
|
|
|
//Console.WriteLine("[Rhino/Reminderd] Sleeping until interrupted"); |
|
|
|
|
await Task.Delay(Timeout.Infinite, cancellationToken); |
|
|
|
|
} |
|
|
|
|
} catch (TaskCanceledException) { |
|
|
|
|
Console.WriteLine("[Rhino/Reminderd] Sleep interrupted, recalculating"); |
|
|
|
|
//Console.WriteLine("[Rhino/Reminderd] Sleep interrupted, recalculating"); |
|
|
|
|
cancellationSource = new CancellationTokenSource(); |
|
|
|
|
cancellationToken = cancellationSource.Token; |
|
|
|
|
continue; |
|
|
|
|