I think it actually works! Time to give this a proper repo then :P

This commit is contained in:
Starbeamrainbowlabs 2018-11-10 18:31:58 +00:00
parent 0b73e2f1c7
commit 608aecc1fa
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
2 changed files with 24 additions and 13 deletions

View file

@ -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();
}
}

View file

@ -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>
</Project>