public async Task AddReminderEventCommand([Remainder] string message) { Match matches = Regex.Match(message); if (matches.Success) { var milliseconds = 0; switch (matches.Groups["unit"].Value.ToLower()[0]) { case 's': milliseconds = int.Parse(matches.Groups["digits"].Value) * 1000; break; case 'm': milliseconds = int.Parse(matches.Groups["digits"].Value) * 1000 * 60; break; case 'h': milliseconds = int.Parse(matches.Groups["digits"].Value) * 1000 * 60 * 60; break; case 'd': milliseconds = int.Parse(matches.Groups["digits"].Value) * 1000 * 60 * 60 * 24; break; default: await ReplyAsync("Couldn't find any supported time units, please use [seconds|minutes|hour|days]").ConfigureAwait(false); break; } var reminderEvent = new ReminderEvent { RequestedTime = DateTime.Now.AddMilliseconds(milliseconds), UserId = Context.User.Id, Reason = matches.Groups["reason"].Success ? matches.Groups["reason"].Value : "No specified reason" }; ReminderService.AddReminder(reminderEvent); await ReplyAsync( $"Reminder set for {reminderEvent.RequestedTime.ToUniversalTime().ToString("g", new CultureInfo("en-US"))} UTC with reason: {reminderEvent.Reason}").ConfigureAwait(false); } else { await ReplyAsync("Couldn't parse your command, please use the format \"!Reminder [number] [seconds|minutes|hour|days] [optional: reason for reminder]\"").ConfigureAwait(false); } }
public void AddReminder(ReminderEvent reminderEvent) { if (_reminderList.Count == 0) { _reminderList.AddFirst(reminderEvent); SetTimer(reminderEvent.RequestedTime); } else { var laternode = _reminderList.EnumerateNodes() .FirstOrDefault(x => x.Value.RequestedTime.CompareTo(reminderEvent.RequestedTime) > 0); if (laternode == null) { _reminderList.AddLast(reminderEvent); } else { _reminderList.AddBefore(laternode, reminderEvent); } } Save(); }