Start tidying some stuff up, & support date ranges

This commit is contained in:
Starbeamrainbowlabs 2018-11-10 18:57:49 +00:00
parent 4875d749d1
commit 131157c50b
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
3 changed files with 10 additions and 5 deletions

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.Recognizers.Text; using Microsoft.Recognizers.Text;
using Microsoft.Recognizers.Text.DateTime; using Microsoft.Recognizers.Text.DateTime;
using SBRL.Geometry; using SBRL.Geometry;
@ -57,7 +58,7 @@ namespace RhinoReminds
throw new AIException($"Error: An invalid type of {type} was encountered ('datetime' expected)."); 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); return DateTime.Parse(result);
} }

View file

@ -158,7 +158,7 @@ namespace RhinoReminds
} }
private void sendChatMessage(Jid to, string message) { 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( client.SendMessage(
to, message, to, message,
null, null, MessageType.Chat null, null, MessageType.Chat
@ -166,7 +166,7 @@ namespace RhinoReminds
} }
private void sendChatReply(Message originalMessage, string reply) 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( client.SendMessage(
originalMessage.From, reply, originalMessage.From, reply,
null, originalMessage.Thread, MessageType.Chat null, originalMessage.Thread, MessageType.Chat

View file

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