/// <summary> /// Builds an embed that shows upcoming playtest events and events from the queue /// </summary> /// <param name="getSchedule">Get events from Queue</param> /// <param name="getCalendar">Get events from Calendar</param> /// <returns>Built embed with events</returns> public async Task <EmbedBuilder> GetUpcomingEvents(bool getSchedule, bool getCalendar) { var author = "Current "; var embed = new EmbedBuilder().WithColor(new Color(55, 55, 165)) .WithFooter($"Current CT Time: {DateTime.Now}") .WithDescription("[View Testing Calendar](http://playtesting.tophattwaffle.com) " + "| [View Testing Requirements](https://www.tophattwaffle.com/playtesting) " + "| View Queue with `>Schedule`"); if (getSchedule) { author += "Playtest Requests"; var testQueue = DatabaseUtil.GetAllPlaytestRequests().ToList(); //No tests found - do nothing if (testQueue.Count == 0) { embed.AddField("No playtest requests found!", "Submit your own with: `>request`"); } else { for (var i = 0; i < testQueue.Count; i++) { //Don't have more than 24 if (embed.Fields.Count >= 24) { break; } var info = "Creator(s): "; foreach (var creator in testQueue[i].CreatorsDiscord) { var user = _dataService.GetSocketGuildUser(creator); if (user != null) { info += $"`{user}`, "; } else { info += $"Could not get user `{creator}`, "; } } info = info.Trim(',', ' '); info += $"\nGame: `{testQueue[i].Game}`" + $"\nRequested Time: `{testQueue[i].TestDate:ddd, MMM d, HH:mm}`" + $"\n[Map Images]({testQueue[i].ImgurAlbum}) - " + $"[Workshop Link]({testQueue[i].WorkshopURL})\n"; embed.AddField($"[{i}] - {testQueue[i].MapName} - {testQueue[i].TestType}", info, true); } } } if (getCalendar) { //If we added requests, toss "and" in there. author += getSchedule ? " and " : ""; author += "Scheduled Playtests"; var testEvents = await _calendar.GetNextMonthAsync(DateTime.Now); if (testEvents.Items.Count == 0) { embed.AddField("No scheduled playtests found!", "Submit yours with: `>request`"); } else { foreach (var item in testEvents.Items) { if (embed.Fields.Count >= 24) { break; } //Get the moderator for each test var strippedHtml = item.Description.Replace("<br>", "\n").Replace(" ", ""); strippedHtml = Regex.Replace(strippedHtml, "<.*?>", string.Empty); var description = strippedHtml.Trim().Split('\n') .Select(line => line.Substring(line.IndexOf(':') + 1).Trim()).ToImmutableArray(); var mod = _dataService.GetSocketUser(description.ElementAtOrDefault(4)); embed.AddField($"{item.Summary} - {description.ElementAtOrDefault(3)}", $"`Scheduled`\nStart Time: `{item.Start.DateTime:ddd, MMM d, HH:mm}`\nModerator: {mod.Mention}" + $"\n[Map Images]({description.ElementAtOrDefault(1)}) - " + $"[Workshop Link]({description.ElementAtOrDefault(2)})\n", true); } } } if (embed.Fields.Count >= 24) { embed.AddField("Max Fields Added", "Somehow there are more items than Discord embeds allow. Some items omitted."); } embed.WithAuthor(author); return(embed); }