Browse Source

Start tidying some stuff up, & support date ranges

master
Starbeamrainbowlabs 4 years ago
parent
commit
131157c50b
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
  1. 3
      RhinoReminds/AIRecogniser.cs
  2. 4
      RhinoReminds/ClientListener.cs
  3. 8
      RhinoReminds/ReminderList.cs

3
RhinoReminds/AIRecogniser.cs

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.Recognizers.Text;
using Microsoft.Recognizers.Text.DateTime;
using SBRL.Geometry;
@ -57,7 +58,7 @@ namespace RhinoReminds @@ -57,7 +58,7 @@ namespace RhinoReminds
throw new AIException($"Error: An invalid type of {type} was encountered ('datetime' expected).");
string result = type == "datetimerange" ? aiResult["start"] : aiResult["value"];
string result = Regex.IsMatch(type, @"range$") ? aiResult["start"] : aiResult["value"];
return DateTime.Parse(result);
}

4
RhinoReminds/ClientListener.cs

@ -158,7 +158,7 @@ namespace RhinoReminds @@ -158,7 +158,7 @@ namespace RhinoReminds
}
private void sendChatMessage(Jid to, string message) {
Console.WriteLine($"[Rhino/Send/Chat] Sending {message} -> {to}");
//Console.WriteLine($"[Rhino/Send/Chat] Sending {message} -> {to}");
client.SendMessage(
to, message,
null, null, MessageType.Chat
@ -166,7 +166,7 @@ namespace RhinoReminds @@ -166,7 +166,7 @@ namespace RhinoReminds
}
private void sendChatReply(Message originalMessage, string reply)
{
Console.WriteLine($"[Rhino/Send/Reply] Sending {reply} -> {originalMessage.From}");
//Console.WriteLine($"[Rhino/Send/Reply] Sending {reply} -> {originalMessage.From}");
client.SendMessage(
originalMessage.From, reply,
null, originalMessage.Thread, MessageType.Chat

8
RhinoReminds/ReminderList.cs

@ -8,10 +8,14 @@ namespace RhinoReminds @@ -8,10 +8,14 @@ namespace RhinoReminds
{
public delegate void OnReminderListUpdateHandler(object sender, Reminder newReminder);
[JsonObject(MemberSerialization.OptIn)]
public class ReminderList
{
private int nextId = 0;
[JsonProperty]
public int NextId { get; private set; } = 0;
private object saveLock = new object();
[JsonProperty]
public SortedList<DateTime, Reminder> Reminders = new SortedList<DateTime, Reminder>();
public event OnReminderListUpdateHandler OnReminderListUpdate;
@ -22,7 +26,7 @@ namespace RhinoReminds @@ -22,7 +26,7 @@ namespace RhinoReminds
}
public Reminder CreateReminder(Jid inJid, DateTime time, string message) {
Reminder result = new Reminder(nextId++, $"{inJid.Node}@{inJid.Domain}", time, message);
Reminder result = new Reminder(NextId++, $"{inJid.Node}@{inJid.Domain}", time, message);
Console.WriteLine($"[Rhino/ReminderList] Created reminder {result}");
Reminders.Add(time, result);
OnReminderListUpdate(this, result);

Loading…
Cancel
Save