I think it actually works! Time to give this a proper repo then :P
This commit is contained in:
parent
0b73e2f1c7
commit
608aecc1fa
2 changed files with 24 additions and 13 deletions
|
@ -2,6 +2,7 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
@ -23,7 +24,7 @@ namespace RhinoReminds
|
||||||
private readonly string password;
|
private readonly string password;
|
||||||
|
|
||||||
public string ReminderFilePath { get; set; } = "./Reminders.json";
|
public string ReminderFilePath { get; set; } = "./Reminders.json";
|
||||||
private ReminderList reminders = new ReminderList();
|
private ReminderList reminderList = new ReminderList();
|
||||||
|
|
||||||
private XmppClient client;
|
private XmppClient client;
|
||||||
|
|
||||||
|
@ -38,7 +39,7 @@ namespace RhinoReminds
|
||||||
if (File.Exists(ReminderFilePath))
|
if (File.Exists(ReminderFilePath))
|
||||||
{
|
{
|
||||||
Console.WriteLine($"[Rhino/Startup] Loading reminders list from {ReminderFilePath}");
|
Console.WriteLine($"[Rhino/Startup] Loading reminders list from {ReminderFilePath}");
|
||||||
reminders = JsonConvert.DeserializeObject<ReminderList>(File.ReadAllText(ReminderFilePath));
|
reminderList = JsonConvert.DeserializeObject<ReminderList>(File.ReadAllText(ReminderFilePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
client = new XmppClient(Hostname, Username, password);
|
client = new XmppClient(Hostname, Username, password);
|
||||||
|
@ -100,9 +101,18 @@ namespace RhinoReminds
|
||||||
case "list":
|
case "list":
|
||||||
case "show":
|
case "show":
|
||||||
if (parts.Select((n) => n.ToLower()).Contains("all")) {
|
if (parts.Select((n) => n.ToLower()).Contains("all")) {
|
||||||
|
// TODO: Make sure that you can't see other people's reminders
|
||||||
|
StringBuilder listMessage = new StringBuilder("I've got the following reminders on my list:\n");
|
||||||
|
foreach (Reminder nextReminder in reminderList.Reminders.Values) {
|
||||||
|
listMessage.AppendLine($" - {nextReminder.Message} at {nextReminder.Time}");
|
||||||
|
}
|
||||||
|
listMessage.AppendLine();
|
||||||
|
listMessage.AppendLine($"({reminderList.Reminders.Count} total)");
|
||||||
|
sendChatReply(message, listMessage.ToString());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sendChatReply(message, "Sorry, I can't show individual items on my list right now. Try saying 'list all' to see all of them!");
|
||||||
// TODO: Identify number
|
// TODO: Identify number
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -138,8 +148,8 @@ namespace RhinoReminds
|
||||||
|
|
||||||
sendChatReply(message, $"Ok! I'll remind you {reminder} at {dateTime}.");
|
sendChatReply(message, $"Ok! I'll remind you {reminder} at {dateTime}.");
|
||||||
|
|
||||||
Reminder newReminder = reminders.CreateReminder(message.From, dateTime, reminder);
|
Reminder newReminder = reminderList.CreateReminder(message.From, dateTime, reminder);
|
||||||
reminders.Save(ReminderFilePath);
|
reminderList.Save(ReminderFilePath);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
sendChatReply(message, "I don't understand that. Try rephrasing it or asking for help.");
|
sendChatReply(message, "I don't understand that. Try rephrasing it or asking for help.");
|
||||||
|
@ -171,9 +181,9 @@ namespace RhinoReminds
|
||||||
{
|
{
|
||||||
CancellationTokenSource cancellationSource = new CancellationTokenSource();
|
CancellationTokenSource cancellationSource = new CancellationTokenSource();
|
||||||
CancellationToken cancellationToken = cancellationSource.Token;
|
CancellationToken cancellationToken = cancellationSource.Token;
|
||||||
Reminder nextReminder = reminders.GetNextReminder();
|
Reminder nextReminder = reminderList.GetNextReminder();
|
||||||
reminders.OnReminderListUpdate += (object sender, Reminder newReminder) => {
|
reminderList.OnReminderListUpdate += (object sender, Reminder newReminder) => {
|
||||||
Reminder newNextReminder = reminders.GetNextReminder();
|
Reminder newNextReminder = reminderList.GetNextReminder();
|
||||||
Console.WriteLine("[Rhino/Reminderd/Canceller] Reminder added - comparing.");
|
Console.WriteLine("[Rhino/Reminderd/Canceller] Reminder added - comparing.");
|
||||||
Console.WriteLine($"[Rhino/Reminderd/Canceller] {nextReminder} / {newNextReminder}");
|
Console.WriteLine($"[Rhino/Reminderd/Canceller] {nextReminder} / {newNextReminder}");
|
||||||
if (nextReminder != newNextReminder) {
|
if (nextReminder != newNextReminder) {
|
||||||
|
@ -188,7 +198,7 @@ namespace RhinoReminds
|
||||||
TimeSpan nextWaitingTime;
|
TimeSpan nextWaitingTime;
|
||||||
try {
|
try {
|
||||||
if (nextReminder != null) {
|
if (nextReminder != null) {
|
||||||
nextWaitingTime = DateTime.Now - nextReminder.Time;
|
nextWaitingTime = nextReminder.Time - DateTime.Now;
|
||||||
if (DateTime.Now < nextReminder.Time) {
|
if (DateTime.Now < nextReminder.Time) {
|
||||||
Console.WriteLine($"[Rhino/Reminderd] Sleeping for {nextWaitingTime}");
|
Console.WriteLine($"[Rhino/Reminderd] Sleeping for {nextWaitingTime}");
|
||||||
await Task.Delay(nextWaitingTime, cancellationToken);
|
await Task.Delay(nextWaitingTime, cancellationToken);
|
||||||
|
@ -225,9 +235,9 @@ namespace RhinoReminds
|
||||||
"or you might have scheduled a reminder for the past)"
|
"or you might have scheduled a reminder for the past)"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
reminders.DeleteReminder(nextReminder);
|
reminderList.DeleteReminder(nextReminder);
|
||||||
reminders.Save(ReminderFilePath);
|
reminderList.Save(ReminderFilePath);
|
||||||
nextReminder = reminders.GetNextReminder();
|
nextReminder = reminderList.GetNextReminder();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
<RootNamespace>RhinoReminds</RootNamespace>
|
<RootNamespace>RhinoReminds</RootNamespace>
|
||||||
<AssemblyName>RhinoReminds</AssemblyName>
|
<AssemblyName>RhinoReminds</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
|
||||||
|
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
|
Loading…
Reference in a new issue