public async Task <RuntimeResult> ListEvents(string query = "pending", int limit = 10) { try { query = query.ToLowerInvariant(); if (query == "status" || query == "state") { DateTime? date; ScheduledEvent[] events; _schedulingService.GetNextPingInfo(Context.Guild.Id, out date, out events); if (!date.HasValue) { await ReplyAsync("No ping events pending"); } else { EmbedBuilder embedBuilder = new EmbedBuilder(); embedBuilder.Title = "Next ping event - " + date.Value.ToString("dd.MM.yyyy HH:mm"); // Use only two embed fields: reminders and main events List <string> reminders = new List <string>(); List <string> main = new List <string>(); foreach (ScheduledEvent se in events) { string value = string.Format("[{0}] at {1} from {2}", se.Id, se.TargetDateString, se.User); if (date.Value < se.TargetDate) { reminders.Add(value); } else { main.Add(value); } } if (reminders.Any()) { embedBuilder.AddField( "Reminder for", string.Join("\n", reminders)); } if (main.Any()) { embedBuilder.AddField( "Main event for", string.Join("\n", main)); } await ReplyAsync(string.Empty, false, embedBuilder.Build()); } } else { EventState?state; switch (query) { case "pending": state = EventState.Pending; break; case "all": state = null; break; case "cancelled": state = EventState.Cancelled; break; case "passed": state = EventState.Passed; break; default: throw new ArgumentException(string.Format("Invalid query type '{0}'", query)); } var sb = new StringBuilder(); foreach (var se in _schedulingService.GetEvents(Context.Guild.Id, state, limit)) { sb.Append("----------\n"); sb.AppendFormat("[{0}] {1} - From {2}\n", se.Id, se.ETA, se.User); sb.Append(Format.Code(se.Message) + "\n"); } if (sb.Length == 0) { await ReplyAsync("No events found"); } else { await ReplyAsync(sb.ToString()); } } return(CommandResult.FromSuccess()); } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(CommandResult.FromError(ex.Message)); } }