public async Task RemList() { try { // Read all reminders into an array ReadAndWrite rw = new ReadAndWrite(); ArrayList reminders = new ArrayList(); using (StreamReader file = File.OpenText(rw.getPath(@"Reminders\ReminderList"))) { while (!file.EndOfStream) { reminders.Add(await file.ReadLineAsync()); } file.Close(); } // Foreach reminder foreach (Object obj in reminders) { // Read in reminder data string fileName = @"Reminders\" + obj; String name = rw.ReadSection(fileName, "Name"); String message = rw.ReadSection(fileName, "Message"); DateTime expires = DateTime.Parse(rw.ReadSection(fileName, "Time Expires")); String users = rw.ReadSection(fileName, "Target Users"); // Print it as an embed var eb = new EmbedBuilder(); eb.WithColor(Color.Orange); eb.WithTitle("New Reminder:"); eb.WithDescription(message); eb.AddField("Reminder Name:", name, true); eb.AddField("For time:", "(" + expires + ")", true); eb.AddField("Will notify: ", users, false); eb.WithFooter("Reminder logged!"); await Context.Channel.SendMessageAsync("", false, eb.Build()); } } catch (Exception e) { Console.WriteLine(e); } }
// Expires reminders when they reach their time public async Task expireReminders() { try { // Read all reminders into an array ReadAndWrite rw = new ReadAndWrite(); ArrayList reminders = new ArrayList(); using (StreamReader file = File.OpenText(rw.getPath(@"Reminders\ReminderList"))) { while (!file.EndOfStream) { reminders.Add(await file.ReadLineAsync()); } file.Close(); } // Foreach reminder foreach (Object obj in reminders) { // Read in reminder time string fileName = @"Reminders\" + obj; DateTime expires = DateTime.Parse(rw.ReadSection(fileName, "Time Expires")); // Check if expired if (DateTime.Now > expires) { // Read in the rest of the reminder data String name = rw.ReadSection(fileName, "Name"); String message = rw.ReadSection(fileName, "Message"); String users = rw.ReadSection(fileName, "Target Users"); // Print it as an embed var eb = new EmbedBuilder(); eb.WithColor(Color.Orange); eb.WithTitle("New Reminder:"); eb.WithDescription(message); eb.AddField("Reminder Name:", name, true); eb.AddField("For time:", "(" + expires + ")", true); eb.AddField("Will notify: ", users, false); eb.WithFooter("Reminder logged!"); await Context.Channel.SendMessageAsync("", false, eb.Build()); // Delete the file rw.deleteFile(fileName); // Remove it from the reminder list string[] Lines = File.ReadAllLines(rw.getPath(@"Reminders\ReminderList")); // Read all of reminderList.txt rw.deleteFile(@"Reminders\ReminderList"); // Delete it using (StreamWriter sw = File.AppendText(rw.getPath(@"Reminders\ReminderList"))) // Rebuild it { foreach (string line in Lines) { if (line.Trim() == name.Trim()) { //Skip the line continue; } else { sw.WriteLine(line); } } } } } } catch (Exception e) { Console.WriteLine(e); } }