From 608aecc1fa13894f8862332f65136cc17bff5d59 Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Sat, 10 Nov 2018 18:31:58 +0000
Subject: [PATCH] I think it actually works! Time to give this a proper repo
 then :P

---
 RhinoReminds/ClientListener.cs   | 34 +++++++++++++++++++++-----------
 RhinoReminds/RhinoReminds.csproj |  3 ++-
 2 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/RhinoReminds/ClientListener.cs b/RhinoReminds/ClientListener.cs
index 2a0f2a8..69271bc 100644
--- a/RhinoReminds/ClientListener.cs
+++ b/RhinoReminds/ClientListener.cs
@@ -2,6 +2,7 @@
 using System.IO;
 using System.Linq;
 using System.Net;
+using System.Text;
 using System.Text.RegularExpressions;
 using System.Threading;
 using System.Threading.Tasks;
@@ -23,7 +24,7 @@ namespace RhinoReminds
 		private readonly string password;
 
 		public string ReminderFilePath { get; set; } = "./Reminders.json";
-		private ReminderList reminders = new ReminderList();
+		private ReminderList reminderList = new ReminderList();
 
 		private XmppClient client;
 
@@ -38,7 +39,7 @@ namespace RhinoReminds
 			if (File.Exists(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);
@@ -100,9 +101,18 @@ namespace RhinoReminds
 				case "list":
 				case "show":
 					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
 
 					break;
@@ -138,8 +148,8 @@ namespace RhinoReminds
 
 					sendChatReply(message, $"Ok! I'll remind you {reminder} at {dateTime}.");
 
-					Reminder newReminder = reminders.CreateReminder(message.From, dateTime, reminder);
-					reminders.Save(ReminderFilePath);
+					Reminder newReminder = reminderList.CreateReminder(message.From, dateTime, reminder);
+					reminderList.Save(ReminderFilePath);
 					break;
 				default:
 					sendChatReply(message, "I don't understand that. Try rephrasing it or asking for help.");
@@ -171,9 +181,9 @@ namespace RhinoReminds
 		{
 			CancellationTokenSource cancellationSource = new CancellationTokenSource();
 			CancellationToken cancellationToken = cancellationSource.Token;
-			Reminder nextReminder = reminders.GetNextReminder();
-			reminders.OnReminderListUpdate += (object sender, Reminder newReminder) => {
-				Reminder newNextReminder = reminders.GetNextReminder();
+			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}");
 				if (nextReminder != newNextReminder) {
@@ -188,7 +198,7 @@ namespace RhinoReminds
 				TimeSpan nextWaitingTime;
 				try {
 					if (nextReminder != null) {
-						nextWaitingTime = DateTime.Now - nextReminder.Time;
+						nextWaitingTime = nextReminder.Time - DateTime.Now;
 						if (DateTime.Now < nextReminder.Time) {
 							Console.WriteLine($"[Rhino/Reminderd] Sleeping for {nextWaitingTime}");
 							await Task.Delay(nextWaitingTime, cancellationToken);
@@ -225,9 +235,9 @@ namespace RhinoReminds
 						"or you might have scheduled a reminder for the past)"
 					);
 				}
-				reminders.DeleteReminder(nextReminder);
-				reminders.Save(ReminderFilePath);
-				nextReminder = reminders.GetNextReminder();
+				reminderList.DeleteReminder(nextReminder);
+				reminderList.Save(ReminderFilePath);
+				nextReminder = reminderList.GetNextReminder();
 			}
 		}
 
diff --git a/RhinoReminds/RhinoReminds.csproj b/RhinoReminds/RhinoReminds.csproj
index 66c9ea1..5d31958 100644
--- a/RhinoReminds/RhinoReminds.csproj
+++ b/RhinoReminds/RhinoReminds.csproj
@@ -8,6 +8,7 @@
     <RootNamespace>RhinoReminds</RootNamespace>
     <AssemblyName>RhinoReminds</AssemblyName>
     <TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
+    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
     <DebugSymbols>true</DebugSymbols>
@@ -76,4 +77,4 @@
     <Folder Include="Utilities\" />
   </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
-</Project>
\ No newline at end of file
+</Project>
