public async Task ExecuteAllActiveWebhooksAsync(DPSReportJSON reportJSON) { string bossName = reportJSON.Encounter.Boss + (reportJSON.ChallengeMode ? " CM" : ""); string successString = (reportJSON.Encounter.Success ?? false) ? ":white_check_mark:" : "❌"; string extraJSON = (reportJSON.ExtraJSON == null) ? "" : $"Recorded by: {reportJSON.ExtraJSON.RecordedBy}\nDuration: {reportJSON.ExtraJSON.Duration}\nElite Insights version: {reportJSON.ExtraJSON.EliteInsightsVersion}\n"; string icon = ""; BossData bossData = Bosses.GetBossDataFromId(reportJSON.Encounter.BossId); if (bossData != null) { bossName = bossData.Name + (reportJSON.ChallengeMode ? " CM" : ""); icon = bossData.Icon; } int color = (reportJSON.Encounter.Success ?? false) ? 32768 : 16711680; DiscordAPIJSONContentEmbedThumbnail discordContentEmbedThumbnail = new DiscordAPIJSONContentEmbedThumbnail() { Url = icon }; DateTime timestampDateTime = DateTime.UtcNow; if (DateTime.TryParse(reportJSON.ExtraJSON.TimeStart, out DateTime timeStart)) { timestampDateTime = timeStart; } string timestamp = timestampDateTime.ToString("yyyy'-'MM'-'ddTHH':'mm':'ssZ"); DiscordAPIJSONContentEmbed discordContentEmbed = new DiscordAPIJSONContentEmbed() { Title = bossName, Url = reportJSON.Permalink, Description = $"{extraJSON}Result: {successString}\narcdps version: {reportJSON.EVTC.Type}{reportJSON.EVTC.Version}", Color = color, TimeStamp = timestamp, Thumbnail = discordContentEmbedThumbnail }; DiscordAPIJSONContent discordContentWithoutPlayers = new DiscordAPIJSONContent() { Embeds = new List <DiscordAPIJSONContentEmbed>() { discordContentEmbed } }; DiscordAPIJSONContentEmbed discordContentEmbedForPlayers = new DiscordAPIJSONContentEmbed() { Title = bossName, Url = reportJSON.Permalink, Description = $"{extraJSON}Result: {successString}\narcdps version: {reportJSON.EVTC.Type}{reportJSON.EVTC.Version}", Color = color, TimeStamp = timestamp, Thumbnail = discordContentEmbedThumbnail }; if (reportJSON.Players.Values.Count <= 10) { List <DiscordAPIJSONContentEmbedField> fields = new List <DiscordAPIJSONContentEmbedField>(); foreach (DPSReportJSONPlayers player in reportJSON.Players.Values) { fields.Add(new DiscordAPIJSONContentEmbedField() { Name = player.CharacterName, Value = $"```\n{player.DisplayName}\n\n{Players.ResolveSpecName(player.Profession, player.EliteSpec)}\n```", Inline = true }); } discordContentEmbedForPlayers.Fields = fields; } DiscordAPIJSONContent discordContentWithPlayers = new DiscordAPIJSONContent() { Embeds = new List <DiscordAPIJSONContentEmbed>() { discordContentEmbedForPlayers } }; try { string jsonContentWithoutPlayers = JsonConvert.SerializeObject(discordContentWithoutPlayers); string jsonContentWithPlayers = JsonConvert.SerializeObject(discordContentWithPlayers); foreach (int key in allWebhooks.Keys) { DiscordWebhookData webhook = allWebhooks[key]; if (!webhook.Active || (webhook.SuccessFailToggle.Equals(DiscordWebhookDataSuccessToggle.OnSuccessOnly) && !(reportJSON.Encounter.Success ?? false)) || (webhook.SuccessFailToggle.Equals(DiscordWebhookDataSuccessToggle.OnFailOnly) && (reportJSON.Encounter.Success ?? false)) || webhook.BossesDisable.Contains(reportJSON.Encounter.BossId)) { continue; } Uri uri = new Uri(webhook.URL); if (webhook.ShowPlayers) { using (StringContent content = new StringContent(jsonContentWithPlayers, Encoding.UTF8, "application/json")) { using (await mainLink.HttpClientController.PostAsync(uri, content)) { } } } else { using (StringContent content = new StringContent(jsonContentWithoutPlayers, Encoding.UTF8, "application/json")) { using (await mainLink.HttpClientController.PostAsync(uri, content)) { } } } } if (allWebhooks.Count > 0) { mainLink.AddToText(">:> All active webhooks successfully executed."); } } catch { mainLink.AddToText(">:> Unable to execute active webhooks."); } }
public static DiscordEmbeds ConstructSessionEmbeds(List <DPSReportJSON> reportsJSON, LogSessionSettings logSessionSettings) { List <DiscordAPIJSONContentEmbed> discordEmbedsSuccessFailure = new List <DiscordAPIJSONContentEmbed>(); List <DiscordAPIJSONContentEmbed> discordEmbedsSuccess = new List <DiscordAPIJSONContentEmbed>(); List <DiscordAPIJSONContentEmbed> discordEmbedsFailure = new List <DiscordAPIJSONContentEmbed>(); var RaidLogs = reportsJSON .Where(x => Bosses.GetWingForBoss(x.EVTC.BossId) > 0) .Select(x => new { LogData = x, RaidWing = Bosses.GetWingForBoss(x.EVTC.BossId) }) .OrderBy(x => x.LogData.UploadTime) .ToList(); if (logSessionSettings.SortBy.Equals(LogSessionSortBy.Wing)) { RaidLogs = reportsJSON .Where(x => Bosses.GetWingForBoss(x.EVTC.BossId) > 0) .Select(x => new { LogData = x, RaidWing = Bosses.GetWingForBoss(x.EVTC.BossId) }) .OrderBy(x => Bosses.GetWingForBoss(x.LogData.EVTC.BossId)) .ThenBy(x => Bosses.GetBossOrder(x.LogData.Encounter.BossId)) .ThenBy(x => x.LogData.UploadTime) .ToList(); } List <DPSReportJSON> FractalLogs = reportsJSON .Where(x => allBosses .Where(y => y.Value.BossId.Equals(x.EVTC.BossId)) .Where(y => y.Value.Type.Equals(BossType.Fractal)) .Count() > 0) .ToList(); List <DPSReportJSON> StrikeLogs = reportsJSON .Where(x => allBosses .Where(y => y.Value.BossId.Equals(x.EVTC.BossId)) .Where(y => y.Value.Type.Equals(BossType.Strike)) .Count() > 0) .ToList(); List <DPSReportJSON> GolemLogs = reportsJSON .Where(x => allBosses .Where(y => y.Value.BossId.Equals(x.EVTC.BossId)) .Where(y => y.Value.Type.Equals(BossType.Golem)) .Count() > 0) .ToList(); List <DPSReportJSON> WvWLogs = reportsJSON .Where(x => allBosses .Where(y => y.Value.BossId.Equals(x.EVTC.BossId)) .Where(y => y.Value.Type.Equals(BossType.WvW)) .Count() > 0) .ToList(); List <DPSReportJSON> OtherLogs = reportsJSON .Where(x => allBosses .Where(y => y.Value.BossId.Equals(x.EVTC.BossId)) .Where(y => y.Value.Type.Equals(BossType.None)) .Count() > 0 || allBosses .Where(y => y.Value.BossId.Equals(x.EVTC.BossId)) .Count() == 0) .ToList(); string durationText = $"Session duration: {logSessionSettings.ElapsedTime}\n\n"; StringBuilder builderSuccessFailure = new StringBuilder(durationText); StringBuilder builderSuccess = new StringBuilder(durationText); StringBuilder builderFailure = new StringBuilder(durationText); int messageSuccessFailureCount = 0, messageSuccessCount = 0, messageFailureCount = 0; if (RaidLogs.Count > 0) { builderSuccessFailure.Append("***Raid logs:***\n"); if (logSessionSettings.SortBy.Equals(LogSessionSortBy.UploadTime)) { foreach (var data in RaidLogs) { string bossName = data.LogData.Encounter.Boss + (data.LogData.ChallengeMode ? " CM" : ""); BossData bossData = Bosses.GetBossDataFromId(data.LogData.Encounter.BossId); if (bossData != null) { bossName = bossData.Name + (data.LogData.ChallengeMode ? " CM" : ""); } string duration = (data.LogData.ExtraJSON == null) ? "" : $" {data.LogData.ExtraJSON.Duration}"; string successText = (logSessionSettings.ShowSuccess) ? ((data.LogData.Encounter.Success ?? false) ? " :white_check_mark:" : " ❌") : ""; builderSuccessFailure.Append($"[{bossName}]({data.LogData.Permalink}){duration}{successText}\n"); if (builderSuccessFailure.Length >= maxAllowedMessageSize) { messageSuccessFailureCount++; discordEmbedsSuccessFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessFailureCount > 1) ? $" part {messageSuccessFailureCount}" : ""), builderSuccessFailure.ToString())); builderSuccessFailure.Clear(); builderSuccessFailure.Append("***Raid logs:***\n"); } if (data.LogData.Encounter.Success ?? false) { builderSuccess.Append($"[{bossName}]({data.LogData.Permalink}){duration}{successText}\n"); if (builderSuccess.Length >= maxAllowedMessageSize) { messageSuccessCount++; discordEmbedsSuccess.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessCount > 1) ? $" part {messageSuccessCount}" : ""), builderSuccess.ToString())); builderSuccess.Clear(); builderSuccess.Append("***Raid logs:***\n"); } } else { builderFailure.Append($"[{bossName}]({data.LogData.Permalink}){duration}{successText}\n"); if (builderFailure.Length >= maxAllowedMessageSize) { messageFailureCount++; discordEmbedsFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageFailureCount > 1) ? $" part {messageFailureCount}" : ""), builderFailure.ToString())); builderFailure.Clear(); builderFailure.Append("***Raid logs:***\n"); } } } } else { int lastWing = 0; foreach (var data in RaidLogs) { if (!lastWing.Equals(Bosses.GetWingForBoss(data.LogData.EVTC.BossId))) { builderSuccessFailure.Append($"**{Bosses.GetWingName(data.RaidWing)} (wing {data.RaidWing})**\n"); lastWing = Bosses.GetWingForBoss(data.LogData.EVTC.BossId); } string bossName = data.LogData.Encounter.Boss + (data.LogData.ChallengeMode ? " CM" : ""); BossData bossData = Bosses.GetBossDataFromId(data.LogData.Encounter.BossId); if (bossData != null) { bossName = bossData.Name + (data.LogData.ChallengeMode ? " CM" : ""); } string duration = (data.LogData.ExtraJSON == null) ? "" : $" {data.LogData.ExtraJSON.Duration}"; string successText = (logSessionSettings.ShowSuccess) ? ((data.LogData.Encounter.Success ?? false) ? " :white_check_mark:" : " ❌") : ""; builderSuccessFailure.Append($"[{bossName}]({data.LogData.Permalink}){duration}{successText}\n"); if (builderSuccessFailure.Length >= maxAllowedMessageSize) { messageSuccessFailureCount++; discordEmbedsSuccessFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessFailureCount > 1) ? $" part {messageSuccessFailureCount}" : ""), builderSuccessFailure.ToString())); builderSuccessFailure.Clear(); builderSuccessFailure.Append($"**{Bosses.GetWingName(data.RaidWing)} (wing {data.RaidWing})**\n"); } if (data.LogData.Encounter.Success ?? false) { builderSuccess.Append($"[{bossName}]({data.LogData.Permalink}){duration}{successText}\n"); if (builderSuccess.Length >= maxAllowedMessageSize) { messageSuccessCount++; discordEmbedsSuccess.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessCount > 1) ? $" part {messageSuccessCount}" : ""), builderSuccess.ToString())); builderSuccess.Clear(); builderSuccess.Append("***Raid logs:***\n"); } } else { builderFailure.Append($"[{bossName}]({data.LogData.Permalink}){duration}{successText}\n"); if (builderFailure.Length >= maxAllowedMessageSize) { messageFailureCount++; discordEmbedsFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageFailureCount > 1) ? $" part {messageFailureCount}" : ""), builderFailure.ToString())); builderFailure.Clear(); builderFailure.Append("***Raid logs:***\n"); } } } } } if (FractalLogs.Count > 0) { if (!builderSuccessFailure.ToString().EndsWith("***\n")) { builderSuccessFailure.Append("\n\n"); } builderSuccessFailure.Append("***Fractal logs:***\n"); foreach (DPSReportJSON log in FractalLogs) { string bossName = log.Encounter.Boss; BossData bossData = Bosses.GetBossDataFromId(log.Encounter.BossId); if (bossData != null) { bossName = bossData.Name + (log.ChallengeMode ? " CM" : ""); } string duration = (log.ExtraJSON == null) ? "" : $" {log.ExtraJSON.Duration}"; string successText = (logSessionSettings.ShowSuccess) ? ((log.Encounter.Success ?? false) ? " :white_check_mark:" : " ❌") : ""; builderSuccessFailure.Append($"[{bossName}]({log.Permalink}){duration}{successText}\n"); if (builderSuccessFailure.Length >= maxAllowedMessageSize) { messageSuccessFailureCount++; discordEmbedsSuccessFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessFailureCount > 1) ? $" part {messageSuccessFailureCount}" : ""), builderSuccessFailure.ToString())); builderSuccessFailure.Clear(); builderSuccessFailure.Append("***Fractal logs:***\n"); } if (log.Encounter.Success ?? false) { builderSuccess.Append($"[{bossName}]({log.Permalink}){duration}{successText}\n"); if (builderSuccess.Length >= maxAllowedMessageSize) { messageSuccessCount++; discordEmbedsSuccess.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessCount > 1) ? $" part {messageSuccessCount}" : ""), builderSuccess.ToString())); builderSuccess.Clear(); builderSuccess.Append("***Fractal logs:***\n"); } } else { builderFailure.Append($"[{bossName}]({log.Permalink}){duration}{successText}\n"); if (builderFailure.Length >= maxAllowedMessageSize) { messageFailureCount++; discordEmbedsFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageFailureCount > 1) ? $" part {messageFailureCount}" : ""), builderFailure.ToString())); builderFailure.Clear(); builderFailure.Append("***Fractal logs:***\n"); } } } } if (StrikeLogs.Count > 0) { if (!builderSuccessFailure.ToString().EndsWith("***\n")) { builderSuccessFailure.Append("\n\n"); } builderSuccessFailure.Append("***Strike mission logs:***\n"); foreach (DPSReportJSON log in StrikeLogs) { string bossName = log.Encounter.Boss; BossData bossData = Bosses.GetBossDataFromId(log.Encounter.BossId); if (bossData != null) { bossName = bossData.Name; } string duration = (log.ExtraJSON == null) ? "" : $" {log.ExtraJSON.Duration}"; string successText = (logSessionSettings.ShowSuccess) ? ((log.Encounter.Success ?? false) ? " :white_check_mark:" : " ❌") : ""; builderSuccessFailure.Append($"[{bossName}]({log.Permalink}){duration}{successText}\n"); if (builderSuccessFailure.Length >= maxAllowedMessageSize) { messageSuccessFailureCount++; discordEmbedsSuccessFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessFailureCount > 1) ? $" part {messageSuccessFailureCount}" : ""), builderSuccessFailure.ToString())); builderSuccessFailure.Clear(); builderSuccessFailure.Append("***Strike mission logs:***\n"); } if (log.Encounter.Success ?? false) { builderSuccess.Append($"[{bossName}]({log.Permalink}){duration}{successText}\n"); if (builderSuccess.Length >= maxAllowedMessageSize) { messageSuccessCount++; discordEmbedsSuccess.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessCount > 1) ? $" part {messageSuccessCount}" : ""), builderSuccess.ToString())); builderSuccess.Clear(); builderSuccess.Append("***Strike mission logs:***\n"); } } else { builderFailure.Append($"[{bossName}]({log.Permalink}){duration}{successText}\n"); if (builderFailure.Length >= maxAllowedMessageSize) { messageFailureCount++; discordEmbedsFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageFailureCount > 1) ? $" part {messageFailureCount}" : ""), builderFailure.ToString())); builderFailure.Clear(); builderFailure.Append("***Strike mission logs:***\n"); } } } } if (GolemLogs.Count > 0) { if (!builderSuccessFailure.ToString().EndsWith("***\n")) { builderSuccessFailure.Append("\n\n"); } builderSuccessFailure.Append("***Golem logs:***\n"); foreach (DPSReportJSON log in GolemLogs) { builderSuccessFailure.Append($"{log.Permalink}\n"); if (builderSuccessFailure.Length >= maxAllowedMessageSize) { messageSuccessFailureCount++; discordEmbedsSuccessFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessFailureCount > 1) ? $" part {messageSuccessFailureCount}" : ""), builderSuccessFailure.ToString())); builderSuccessFailure.Clear(); builderSuccessFailure.Append("***Golem logs:***\n"); } if (log.Encounter.Success ?? false) { builderSuccess.Append($"{log.Permalink}\n"); if (builderSuccess.Length >= maxAllowedMessageSize) { messageSuccessCount++; discordEmbedsSuccess.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessCount > 1) ? $" part {messageSuccessCount}" : ""), builderSuccess.ToString())); builderSuccess.Clear(); builderSuccess.Append("***Golem logs:***\n"); } } else { builderFailure.Append($"{log.Permalink}\n"); if (builderFailure.Length >= maxAllowedMessageSize) { messageFailureCount++; discordEmbedsFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageFailureCount > 1) ? $" part {messageFailureCount}" : ""), builderFailure.ToString())); builderFailure.Clear(); builderFailure.Append("***Golem logs:***\n"); } } } } if (WvWLogs.Count > 0) { if (!builderSuccessFailure.ToString().EndsWith("***\n")) { builderSuccessFailure.Append("\n\n"); } builderSuccessFailure.Append("***WvW logs:***\n"); foreach (DPSReportJSON log in WvWLogs) { builderSuccessFailure.Append($"{log.Permalink}\n"); if (builderSuccessFailure.Length >= maxAllowedMessageSize) { messageSuccessFailureCount++; discordEmbedsSuccessFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessFailureCount > 1) ? $" part {messageSuccessFailureCount}" : ""), builderSuccessFailure.ToString())); builderSuccessFailure.Clear(); builderSuccessFailure.Append("***WvW logs:***\n"); } if (log.Encounter.Success ?? false) { builderSuccess.Append($"{log.Permalink}\n"); if (builderSuccess.Length >= maxAllowedMessageSize) { messageSuccessCount++; discordEmbedsSuccess.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessCount > 1) ? $" part {messageSuccessCount}" : ""), builderSuccess.ToString())); builderSuccess.Clear(); builderSuccess.Append("***WvW logs:***\n"); } } else { builderFailure.Append($"{log.Permalink}\n"); if (builderFailure.Length >= maxAllowedMessageSize) { messageFailureCount++; discordEmbedsFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageFailureCount > 1) ? $" part {messageFailureCount}" : ""), builderFailure.ToString())); builderFailure.Clear(); builderFailure.Append("***WvW logs:***\n"); } } } } if (OtherLogs.Count > 0) { if (!builderSuccessFailure.ToString().EndsWith("***\n")) { builderSuccessFailure.Append("\n\n"); } builderSuccessFailure.Append("***Other logs:***\n"); foreach (DPSReportJSON log in OtherLogs) { string bossName = log.Encounter.Boss; BossData bossData = Bosses.GetBossDataFromId(log.Encounter.BossId); if (bossData != null) { bossName = bossData.Name; } string duration = (log.ExtraJSON == null) ? "" : $" {log.ExtraJSON.Duration}"; string successText = (logSessionSettings.ShowSuccess) ? ((log.Encounter.Success ?? false) ? " :white_check_mark:" : " ❌") : ""; builderSuccessFailure.Append($"[{bossName}]({log.Permalink}){duration}{successText}\n"); if (builderSuccessFailure.Length >= maxAllowedMessageSize) { messageSuccessFailureCount++; discordEmbedsSuccessFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessFailureCount > 1) ? $" part {messageSuccessFailureCount}" : ""), builderSuccessFailure.ToString())); builderSuccessFailure.Clear(); builderSuccessFailure.Append("***Other logs:***\n"); } if (log.Encounter.Success ?? false) { builderSuccess.Append($"[{bossName}]({log.Permalink}){duration}{successText}\n"); if (builderSuccess.Length >= maxAllowedMessageSize) { messageSuccessCount++; discordEmbedsSuccess.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessCount > 1) ? $" part {messageSuccessCount}" : ""), builderSuccess.ToString())); builderSuccess.Clear(); builderSuccess.Append("***Other logs:***\n"); } } else { builderFailure.Append($"[{bossName}]({log.Permalink}){duration}{successText}\n"); if (builderFailure.Length >= maxAllowedMessageSize) { messageFailureCount++; discordEmbedsFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageFailureCount > 1) ? $" part {messageFailureCount}" : ""), builderFailure.ToString())); builderFailure.Clear(); builderFailure.Append("***Other logs:***\n"); } } } } if (!builderSuccessFailure.ToString().EndsWith("***\n")) { messageSuccessFailureCount++; discordEmbedsSuccessFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessFailureCount > 1) ? $" part {messageSuccessFailureCount}" : ""), builderSuccessFailure.ToString())); } if (!builderSuccess.ToString().EndsWith("***\n")) { messageSuccessCount++; discordEmbedsSuccess.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessCount > 1) ? $" part {messageSuccessCount}" : ""), builderSuccess.ToString())); } if (!builderFailure.ToString().EndsWith("***\n")) { messageFailureCount++; discordEmbedsFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageFailureCount > 1) ? $" part {messageFailureCount}" : ""), builderFailure.ToString())); } return(new DiscordEmbeds() { SuccessFailure = discordEmbedsSuccessFailure, Success = discordEmbedsSuccess, Failure = discordEmbedsFailure }); }
public static DiscordEmbeds ConstructSessionEmbeds(List <DPSReportJSON> reportsJSON, LogSessionSettings logSessionSettings) { var discordEmbedsSuccessFailure = new List <DiscordAPIJSONContentEmbed>(); var discordEmbedsSuccess = new List <DiscordAPIJSONContentEmbed>(); var discordEmbedsFailure = new List <DiscordAPIJSONContentEmbed>(); DiscordAPIJSONContentEmbed discordEmbedSummary = null; var RaidLogs = reportsJSON .Where(x => Bosses.GetWingForBoss(x.EVTC.BossId) > 0) .Select(x => new { LogData = x, RaidWing = Bosses.GetWingForBoss(x.EVTC.BossId) }) .OrderBy(x => x.LogData.UploadTime) .ToList(); if (logSessionSettings.SortBy.Equals(LogSessionSortBy.Wing)) { RaidLogs = reportsJSON .Where(x => Bosses.GetWingForBoss(x.EVTC.BossId) > 0) .Select(x => new { LogData = x, RaidWing = Bosses.GetWingForBoss(x.EVTC.BossId) }) .OrderBy(x => Bosses.GetWingForBoss(x.LogData.EVTC.BossId)) .ThenBy(x => Bosses.GetBossOrder(x.LogData.Encounter.BossId)) .ThenBy(x => x.LogData.UploadTime) .ToList(); } var FractalLogs = reportsJSON .Where(x => allBosses .Where(y => y.Value.BossId.Equals(x.EVTC.BossId)) .Where(y => y.Value.Type.Equals(BossType.Fractal)) .Count() > 0) .ToList(); var StrikeLogs = reportsJSON .Where(x => allBosses .Where(y => y.Value.BossId.Equals(x.EVTC.BossId)) .Where(y => y.Value.Type.Equals(BossType.Strike)) .Count() > 0) .ToList(); var GolemLogs = reportsJSON .Where(x => allBosses .Where(y => y.Value.BossId.Equals(x.EVTC.BossId)) .Where(y => y.Value.Type.Equals(BossType.Golem)) .Count() > 0) .ToList(); var WvWLogs = reportsJSON .Where(x => allBosses .Where(y => y.Value.BossId.Equals(x.EVTC.BossId)) .Where(y => y.Value.Type.Equals(BossType.WvW)) .Count() > 0) .ToList(); var OtherLogs = reportsJSON .Where(x => allBosses .Where(y => y.Value.BossId.Equals(x.EVTC.BossId)) .Where(y => y.Value.Type.Equals(BossType.None)) .Count() > 0 || allBosses .Where(y => y.Value.BossId.Equals(x.EVTC.BossId)) .Count() == 0) .ToList(); var durationText = $"Session duration: **{logSessionSettings.ElapsedTime}**"; var builderSuccessFailure = ((WvWLogs.Count > 0) && logSessionSettings.MakeWvWSummaryEmbed) ? new StringBuilder() : new StringBuilder($"{durationText}\n\n"); var builderSuccess = ((WvWLogs.Count > 0) && logSessionSettings.MakeWvWSummaryEmbed) ? new StringBuilder() : new StringBuilder($"{durationText}\n\n"); var builderFailure = ((WvWLogs.Count > 0) && logSessionSettings.MakeWvWSummaryEmbed) ? new StringBuilder() : new StringBuilder($"{durationText}\n\n"); int messageSuccessFailureCount = 0, messageSuccessCount = 0, messageFailureCount = 0; if (RaidLogs.Count > 0) { builderSuccessFailure.Append("***Raid logs:***\n"); if (logSessionSettings.SortBy.Equals(LogSessionSortBy.UploadTime)) { foreach (var data in RaidLogs) { var bossName = data.LogData.Encounter.Boss + (data.LogData.ChallengeMode ? " CM" : string.Empty); var bossData = Bosses.GetBossDataFromId(data.LogData.Encounter.BossId); if (!(bossData is null)) { bossName = bossData.Name + (data.LogData.ChallengeMode ? " CM" : string.Empty); } var duration = (data.LogData.ExtraJSON is null) ? string.Empty : $" {data.LogData.ExtraJSON.Duration}"; var successText = (logSessionSettings.ShowSuccess) ? ((data.LogData.Encounter.Success ?? false) ? " :white_check_mark:" : " ❌") : string.Empty; builderSuccessFailure.Append($"[{bossName}]({data.LogData.Permalink}){duration}{successText}\n"); if (builderSuccessFailure.Length >= maxAllowedMessageSize) { messageSuccessFailureCount++; discordEmbedsSuccessFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessFailureCount > 1) ? $" part {messageSuccessFailureCount}" : string.Empty), builderSuccessFailure.ToString())); builderSuccessFailure.Clear(); builderSuccessFailure.Append("***Raid logs:***\n"); } if (data.LogData.Encounter.Success ?? false) { builderSuccess.Append($"[{bossName}]({data.LogData.Permalink}){duration}{successText}\n"); if (builderSuccess.Length >= maxAllowedMessageSize) { messageSuccessCount++; discordEmbedsSuccess.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessCount > 1) ? $" part {messageSuccessCount}" : string.Empty), builderSuccess.ToString())); builderSuccess.Clear(); builderSuccess.Append("***Raid logs:***\n"); } } else { builderFailure.Append($"[{bossName}]({data.LogData.Permalink}){duration}{successText}\n"); if (builderFailure.Length >= maxAllowedMessageSize) { messageFailureCount++; discordEmbedsFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageFailureCount > 1) ? $" part {messageFailureCount}" : string.Empty), builderFailure.ToString())); builderFailure.Clear(); builderFailure.Append("***Raid logs:***\n"); } } } } else { var lastWing = 0; foreach (var data in RaidLogs) { if (!lastWing.Equals(Bosses.GetWingForBoss(data.LogData.EVTC.BossId))) { builderSuccessFailure.Append($"**{Bosses.GetWingName(data.RaidWing)} (wing {data.RaidWing})**\n"); lastWing = Bosses.GetWingForBoss(data.LogData.EVTC.BossId); } var bossName = data.LogData.Encounter.Boss + (data.LogData.ChallengeMode ? " CM" : string.Empty); var bossData = Bosses.GetBossDataFromId(data.LogData.Encounter.BossId); if (!(bossData is null)) { bossName = bossData.Name + (data.LogData.ChallengeMode ? " CM" : string.Empty); } var duration = (data.LogData.ExtraJSON is null) ? string.Empty : $" {data.LogData.ExtraJSON.Duration}"; var successText = (logSessionSettings.ShowSuccess) ? ((data.LogData.Encounter.Success ?? false) ? " :white_check_mark:" : " ❌") : string.Empty; builderSuccessFailure.Append($"[{bossName}]({data.LogData.Permalink}){duration}{successText}\n"); if (builderSuccessFailure.Length >= maxAllowedMessageSize) { messageSuccessFailureCount++; discordEmbedsSuccessFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessFailureCount > 1) ? $" part {messageSuccessFailureCount}" : string.Empty), builderSuccessFailure.ToString())); builderSuccessFailure.Clear(); builderSuccessFailure.Append($"**{Bosses.GetWingName(data.RaidWing)} (wing {data.RaidWing})**\n"); } if (data.LogData.Encounter.Success ?? false) { builderSuccess.Append($"[{bossName}]({data.LogData.Permalink}){duration}{successText}\n"); if (builderSuccess.Length >= maxAllowedMessageSize) { messageSuccessCount++; discordEmbedsSuccess.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessCount > 1) ? $" part {messageSuccessCount}" : string.Empty), builderSuccess.ToString())); builderSuccess.Clear(); builderSuccess.Append("***Raid logs:***\n"); } } else { builderFailure.Append($"[{bossName}]({data.LogData.Permalink}){duration}{successText}\n"); if (builderFailure.Length >= maxAllowedMessageSize) { messageFailureCount++; discordEmbedsFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageFailureCount > 1) ? $" part {messageFailureCount}" : string.Empty), builderFailure.ToString())); builderFailure.Clear(); builderFailure.Append("***Raid logs:***\n"); } } } } } if (FractalLogs.Count > 0) { if (!builderSuccessFailure.ToString().EndsWith("***\n")) { builderSuccessFailure.Append("\n\n"); } builderSuccessFailure.Append("***Fractal logs:***\n"); foreach (var log in FractalLogs) { var bossName = log.Encounter.Boss; var bossData = Bosses.GetBossDataFromId(log.Encounter.BossId); if (!(bossData is null)) { bossName = bossData.Name + (log.ChallengeMode ? " CM" : string.Empty); } var duration = (log.ExtraJSON is null) ? string.Empty : $" {log.ExtraJSON.Duration}"; var successText = (logSessionSettings.ShowSuccess) ? ((log.Encounter.Success ?? false) ? " :white_check_mark:" : " ❌") : string.Empty; builderSuccessFailure.Append($"[{bossName}]({log.Permalink}){duration}{successText}\n"); if (builderSuccessFailure.Length >= maxAllowedMessageSize) { messageSuccessFailureCount++; discordEmbedsSuccessFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessFailureCount > 1) ? $" part {messageSuccessFailureCount}" : string.Empty), builderSuccessFailure.ToString())); builderSuccessFailure.Clear(); builderSuccessFailure.Append("***Fractal logs:***\n"); } if (log.Encounter.Success ?? false) { builderSuccess.Append($"[{bossName}]({log.Permalink}){duration}{successText}\n"); if (builderSuccess.Length >= maxAllowedMessageSize) { messageSuccessCount++; discordEmbedsSuccess.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessCount > 1) ? $" part {messageSuccessCount}" : string.Empty), builderSuccess.ToString())); builderSuccess.Clear(); builderSuccess.Append("***Fractal logs:***\n"); } } else { builderFailure.Append($"[{bossName}]({log.Permalink}){duration}{successText}\n"); if (builderFailure.Length >= maxAllowedMessageSize) { messageFailureCount++; discordEmbedsFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageFailureCount > 1) ? $" part {messageFailureCount}" : string.Empty), builderFailure.ToString())); builderFailure.Clear(); builderFailure.Append("***Fractal logs:***\n"); } } } } if (StrikeLogs.Count > 0) { if (!builderSuccessFailure.ToString().EndsWith("***\n")) { builderSuccessFailure.Append("\n\n"); } builderSuccessFailure.Append("***Strike mission logs:***\n"); foreach (var log in StrikeLogs) { var bossName = log.Encounter.Boss; var bossData = Bosses.GetBossDataFromId(log.Encounter.BossId); if (!(bossData is null)) { bossName = bossData.Name; } var duration = (log.ExtraJSON is null) ? string.Empty : $" {log.ExtraJSON.Duration}"; var successText = (logSessionSettings.ShowSuccess) ? ((log.Encounter.Success ?? false) ? " :white_check_mark:" : " ❌") : string.Empty; builderSuccessFailure.Append($"[{bossName}]({log.Permalink}){duration}{successText}\n"); if (builderSuccessFailure.Length >= maxAllowedMessageSize) { messageSuccessFailureCount++; discordEmbedsSuccessFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessFailureCount > 1) ? $" part {messageSuccessFailureCount}" : string.Empty), builderSuccessFailure.ToString())); builderSuccessFailure.Clear(); builderSuccessFailure.Append("***Strike mission logs:***\n"); } if (log.Encounter.Success ?? false) { builderSuccess.Append($"[{bossName}]({log.Permalink}){duration}{successText}\n"); if (builderSuccess.Length >= maxAllowedMessageSize) { messageSuccessCount++; discordEmbedsSuccess.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessCount > 1) ? $" part {messageSuccessCount}" : string.Empty), builderSuccess.ToString())); builderSuccess.Clear(); builderSuccess.Append("***Strike mission logs:***\n"); } } else { builderFailure.Append($"[{bossName}]({log.Permalink}){duration}{successText}\n"); if (builderFailure.Length >= maxAllowedMessageSize) { messageFailureCount++; discordEmbedsFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageFailureCount > 1) ? $" part {messageFailureCount}" : string.Empty), builderFailure.ToString())); builderFailure.Clear(); builderFailure.Append("***Strike mission logs:***\n"); } } } } if (GolemLogs.Count > 0) { if (!builderSuccessFailure.ToString().EndsWith("***\n")) { builderSuccessFailure.Append("\n\n"); } builderSuccessFailure.Append("***Golem logs:***\n"); foreach (var log in GolemLogs) { builderSuccessFailure.Append($"{log.Permalink}\n"); if (builderSuccessFailure.Length >= maxAllowedMessageSize) { messageSuccessFailureCount++; discordEmbedsSuccessFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessFailureCount > 1) ? $" part {messageSuccessFailureCount}" : string.Empty), builderSuccessFailure.ToString())); builderSuccessFailure.Clear(); builderSuccessFailure.Append("***Golem logs:***\n"); } if (log.Encounter.Success ?? false) { builderSuccess.Append($"{log.Permalink}\n"); if (builderSuccess.Length >= maxAllowedMessageSize) { messageSuccessCount++; discordEmbedsSuccess.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessCount > 1) ? $" part {messageSuccessCount}" : string.Empty), builderSuccess.ToString())); builderSuccess.Clear(); builderSuccess.Append("***Golem logs:***\n"); } } else { builderFailure.Append($"{log.Permalink}\n"); if (builderFailure.Length >= maxAllowedMessageSize) { messageFailureCount++; discordEmbedsFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageFailureCount > 1) ? $" part {messageFailureCount}" : string.Empty), builderFailure.ToString())); builderFailure.Clear(); builderFailure.Append("***Golem logs:***\n"); } } } } if (WvWLogs.Count > 0) { if (logSessionSettings.MakeWvWSummaryEmbed) { var totalEnemyKills = WvWLogs.Select(x => x.ExtraJSON?.Players .Where(y => !y.FriendNPC && !y.NotInSquad) .Select(y => y.StatsTargets.Select(z => z.First().Killed).Sum()) .Sum() ?? 0) .Sum(); var totalSquadDeaths = WvWLogs.Select(x => x.ExtraJSON?.Players .Where(y => !y.FriendNPC && !y.NotInSquad) .Select(y => y.Defenses.First().DeadCount) .Sum() ?? 0) .Sum(); discordEmbedSummary = MakeEmbedFromText($"{logSessionSettings.Name} - WvW Summary", $"{durationText}\n\n" + $"Total kills: **{totalEnemyKills}**\nTotal kills per minute: **{Math.Round(totalEnemyKills / logSessionSettings.ElapsedTimeSpan.TotalMinutes, 3).ToString(CultureInfo.InvariantCulture.NumberFormat)}**\n\n" + $"Total squad deaths: **{totalSquadDeaths}**\nTotal squad deaths per minute: **{Math.Round(totalSquadDeaths / logSessionSettings.ElapsedTimeSpan.TotalMinutes, 3).ToString(CultureInfo.InvariantCulture.NumberFormat)}**"); discordEmbedSummary.Thumbnail = defaultWvWSummaryThumbnail; } if (!builderSuccessFailure.ToString().EndsWith("***\n")) { builderSuccessFailure.Append("\n\n"); } builderSuccessFailure.Append("***WvW logs:***\n"); foreach (var log in WvWLogs) { builderSuccessFailure.Append($"{log.Permalink}\n"); if (builderSuccessFailure.Length >= maxAllowedMessageSize) { messageSuccessFailureCount++; discordEmbedsSuccessFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessFailureCount > 1) ? $" part {messageSuccessFailureCount}" : string.Empty), builderSuccessFailure.ToString())); builderSuccessFailure.Clear(); builderSuccessFailure.Append("***WvW logs:***\n"); } if (log.Encounter.Success ?? false) { builderSuccess.Append($"{log.Permalink}\n"); if (builderSuccess.Length >= maxAllowedMessageSize) { messageSuccessCount++; discordEmbedsSuccess.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessCount > 1) ? $" part {messageSuccessCount}" : string.Empty), builderSuccess.ToString())); builderSuccess.Clear(); builderSuccess.Append("***WvW logs:***\n"); } } else { builderFailure.Append($"{log.Permalink}\n"); if (builderFailure.Length >= maxAllowedMessageSize) { messageFailureCount++; discordEmbedsFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageFailureCount > 1) ? $" part {messageFailureCount}" : string.Empty), builderFailure.ToString())); builderFailure.Clear(); builderFailure.Append("***WvW logs:***\n"); } } } } if (OtherLogs.Count > 0) { if (!builderSuccessFailure.ToString().EndsWith("***\n")) { builderSuccessFailure.Append("\n\n"); } builderSuccessFailure.Append("***Other logs:***\n"); foreach (var log in OtherLogs) { var bossName = log.Encounter.Boss; var bossData = Bosses.GetBossDataFromId(log.Encounter.BossId); if (!(bossData is null)) { bossName = bossData.Name; } var duration = (log.ExtraJSON is null) ? string.Empty : $" {log.ExtraJSON.Duration}"; var successText = (logSessionSettings.ShowSuccess) ? ((log.Encounter.Success ?? false) ? " :white_check_mark:" : " ❌") : string.Empty; builderSuccessFailure.Append($"[{bossName}]({log.Permalink}){duration}{successText}\n"); if (builderSuccessFailure.Length >= maxAllowedMessageSize) { messageSuccessFailureCount++; discordEmbedsSuccessFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessFailureCount > 1) ? $" part {messageSuccessFailureCount}" : string.Empty), builderSuccessFailure.ToString())); builderSuccessFailure.Clear(); builderSuccessFailure.Append("***Other logs:***\n"); } if (log.Encounter.Success ?? false) { builderSuccess.Append($"[{bossName}]({log.Permalink}){duration}{successText}\n"); if (builderSuccess.Length >= maxAllowedMessageSize) { messageSuccessCount++; discordEmbedsSuccess.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessCount > 1) ? $" part {messageSuccessCount}" : string.Empty), builderSuccess.ToString())); builderSuccess.Clear(); builderSuccess.Append("***Other logs:***\n"); } } else { builderFailure.Append($"[{bossName}]({log.Permalink}){duration}{successText}\n"); if (builderFailure.Length >= maxAllowedMessageSize) { messageFailureCount++; discordEmbedsFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageFailureCount > 1) ? $" part {messageFailureCount}" : string.Empty), builderFailure.ToString())); builderFailure.Clear(); builderFailure.Append("***Other logs:***\n"); } } } } if (!builderSuccessFailure.ToString().EndsWith("***\n")) { messageSuccessFailureCount++; discordEmbedsSuccessFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessFailureCount > 1) ? $" part {messageSuccessFailureCount}" : string.Empty), builderSuccessFailure.ToString())); } if (!builderSuccess.ToString().EndsWith("***\n")) { messageSuccessCount++; discordEmbedsSuccess.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessCount > 1) ? $" part {messageSuccessCount}" : string.Empty), builderSuccess.ToString())); } if (!builderFailure.ToString().EndsWith("***\n")) { messageFailureCount++; discordEmbedsFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageFailureCount > 1) ? $" part {messageFailureCount}" : string.Empty), builderFailure.ToString())); } if (!(discordEmbedSummary is null)) { discordEmbedsSuccessFailure.Insert(0, discordEmbedSummary); discordEmbedsSuccess.Insert(0, discordEmbedSummary); discordEmbedsFailure.Insert(0, discordEmbedSummary); } return(new DiscordEmbeds() { Summary = discordEmbedSummary, SuccessFailure = discordEmbedsSuccessFailure, Success = discordEmbedsSuccess, Failure = discordEmbedsFailure }); }
public async Task ExecuteAllActiveWebhooksAsync(DPSReportJSON reportJSON) { if (reportJSON.Encounter.BossId.Equals(1)) // WvW { var extraJSONFightName = (reportJSON.ExtraJSON is null) ? reportJSON.Encounter.Boss : reportJSON.ExtraJSON.FightName; var extraJSON = (reportJSON.ExtraJSON is null) ? string.Empty : $"Recorded by: {reportJSON.ExtraJSON.RecordedBy}\nDuration: {reportJSON.ExtraJSON.Duration}\nElite Insights version: {reportJSON.ExtraJSON.EliteInsightsVersion}"; var icon = string.Empty; var bossData = Bosses.GetBossDataFromId(1); if (!(bossData is null)) { icon = bossData.Icon; } var colour = 16752238; var discordContentEmbedThumbnail = new DiscordAPIJSONContentEmbedThumbnail() { Url = icon }; var timestampDateTime = DateTime.UtcNow; if (!(reportJSON.ExtraJSON is null)) { timestampDateTime = reportJSON.ExtraJSON.TimeStart; } var timestamp = timestampDateTime.ToString("o"); var discordContentEmbed = new DiscordAPIJSONContentEmbed() { Title = extraJSONFightName, Url = reportJSON.Permalink, Description = $"{extraJSON}\narcdps version: {reportJSON.EVTC.Type}{reportJSON.EVTC.Version}", Colour = colour, TimeStamp = timestamp, Thumbnail = discordContentEmbedThumbnail }; // fields if (!(reportJSON.ExtraJSON is null)) { // squad summary var squadPlayers = reportJSON.ExtraJSON.Players .Where(x => !x.FriendNPC && !x.NotInSquad) .Count(); var squadDamage = reportJSON.ExtraJSON.Players .Where(x => !x.FriendNPC && !x.NotInSquad) .Select(x => x.DpsTargets.Sum(y => y.Sum(z => z.Damage))) .Sum(); var squadDps = reportJSON.ExtraJSON.Players .Where(x => !x.FriendNPC && !x.NotInSquad) .Select(x => x.DpsTargets.Sum(y => y.Sum(z => z.DPS))) .Sum(); var squadDowns = reportJSON.ExtraJSON.Players .Where(x => !x.FriendNPC && !x.NotInSquad) .Select(x => x.Defenses.First().DownCount) .Sum(); var squadDeaths = reportJSON.ExtraJSON.Players .Where(x => !x.FriendNPC && !x.NotInSquad) .Select(x => x.Defenses.First().DeadCount) .Sum(); var squadSummary = new TextTable(5, tableStyle, tableBorders); squadSummary.SetColumnWidthRange(0, 3, 3); squadSummary.SetColumnWidthRange(1, 10, 10); squadSummary.SetColumnWidthRange(2, 10, 10); squadSummary.SetColumnWidthRange(3, 8, 8); squadSummary.SetColumnWidthRange(4, 8, 8); squadSummary.AddCell("#", tableCellCenterAlign); squadSummary.AddCell("DMG", tableCellCenterAlign); squadSummary.AddCell("DPS", tableCellCenterAlign); squadSummary.AddCell("Downs", tableCellCenterAlign); squadSummary.AddCell("Deaths", tableCellCenterAlign); squadSummary.AddCell($"{squadPlayers}", tableCellCenterAlign); squadSummary.AddCell($"{squadDamage.ParseAsK()}", tableCellCenterAlign); squadSummary.AddCell($"{squadDps.ParseAsK()}", tableCellCenterAlign); squadSummary.AddCell($"{squadDowns}", tableCellCenterAlign); squadSummary.AddCell($"{squadDeaths}", tableCellCenterAlign); var squadField = new DiscordAPIJSONContentEmbedField() { Name = "Squad summary:", Value = $"```{squadSummary.Render()}```" }; // enemy summary field var enemyField = new DiscordAPIJSONContentEmbedField() { Name = "Enemy summary:", Value = $"```Summary could not have been generated.\nToggle detailed WvW to enable this feature.```" }; if (reportJSON.ExtraJSON.Targets.Count > 1) { var enemyPlayers = reportJSON.ExtraJSON.Targets .Count() - 1; var enemyDamage = reportJSON.ExtraJSON.Targets .Where(x => !x.IsFake) .Select(x => x.DpsAll.First().Damage) .Sum(); var enemyDps = reportJSON.ExtraJSON.Targets .Where(x => !x.IsFake) .Select(x => x.DpsAll.First().DPS) .Sum(); var enemyDowns = reportJSON.ExtraJSON.Players .Where(x => !x.FriendNPC && !x.NotInSquad) .Select(x => x.StatsTargets.Select(y => y.First().Downed).Sum()) .Sum(); var enemyDeaths = reportJSON.ExtraJSON.Players .Where(x => !x.FriendNPC && !x.NotInSquad) .Select(x => x.StatsTargets.Select(y => y.First().Killed).Sum()) .Sum(); var enemySummary = new TextTable(5, tableStyle, tableBorders); enemySummary.SetColumnWidthRange(0, 3, 3); enemySummary.SetColumnWidthRange(1, 10, 10); enemySummary.SetColumnWidthRange(2, 10, 10); enemySummary.SetColumnWidthRange(3, 8, 8); enemySummary.SetColumnWidthRange(4, 8, 8); enemySummary.AddCell("#", tableCellCenterAlign); enemySummary.AddCell("DMG", tableCellCenterAlign); enemySummary.AddCell("DPS", tableCellCenterAlign); enemySummary.AddCell("Downs", tableCellCenterAlign); enemySummary.AddCell("Deaths", tableCellCenterAlign); enemySummary.AddCell($"{enemyPlayers}", tableCellCenterAlign); enemySummary.AddCell($"{enemyDamage.ParseAsK()}", tableCellCenterAlign); enemySummary.AddCell($"{enemyDps.ParseAsK()}", tableCellCenterAlign); enemySummary.AddCell($"{enemyDowns}", tableCellCenterAlign); enemySummary.AddCell($"{enemyDeaths}", tableCellCenterAlign); enemyField = new DiscordAPIJSONContentEmbedField() { Name = "Enemy summary:", Value = $"```{enemySummary.Render()}```" }; } // damage summary var damageStats = reportJSON.ExtraJSON.Players .Where(x => !x.FriendNPC && !x.NotInSquad) .Where(x => x.DpsTargets.Sum(y => y.First().Damage) > 0) .OrderByDescending(x => x.DpsTargets.Sum(y => y.First().Damage)) .Take(10) .ToList(); var damageSummary = new TextTable(4, tableStyle, tableBorders); damageSummary.SetColumnWidthRange(0, 3, 3); damageSummary.SetColumnWidthRange(1, 25, 25); damageSummary.SetColumnWidthRange(2, 7, 7); damageSummary.SetColumnWidthRange(3, 6, 6); damageSummary.AddCell("#", tableCellCenterAlign); damageSummary.AddCell("Name"); damageSummary.AddCell("DMG", tableCellRightAlign); damageSummary.AddCell("DPS", tableCellRightAlign); var rank = 0; foreach (var player in damageStats) { rank++; damageSummary.AddCell($"{rank}", tableCellCenterAlign); damageSummary.AddCell($"{player.Name} ({player.ProfessionShort})"); damageSummary.AddCell($"{player.DpsTargets.Sum(y => y.First().Damage).ParseAsK()}", tableCellRightAlign); damageSummary.AddCell($"{player.DpsTargets.Sum(y => y.First().DPS).ParseAsK()}", tableCellRightAlign); } var damageField = new DiscordAPIJSONContentEmbedField() { Name = "Damage summary:", Value = $"```{damageSummary.Render()}```" }; // cleanses summary var cleansesStats = reportJSON.ExtraJSON.Players .Where(x => !x.FriendNPC && !x.NotInSquad) .Where(x => x.Support.First().CondiCleanseTotal > 0) .OrderByDescending(x => x.Support.First().CondiCleanseTotal) .Take(10) .ToList(); var cleansesSummary = new TextTable(3, tableStyle, tableBorders); cleansesSummary.SetColumnWidthRange(0, 3, 3); cleansesSummary.SetColumnWidthRange(1, 27, 27); cleansesSummary.SetColumnWidthRange(2, 12, 12); cleansesSummary.AddCell("#", tableCellCenterAlign); cleansesSummary.AddCell("Name"); cleansesSummary.AddCell("Cleanses", tableCellRightAlign); rank = 0; foreach (var player in cleansesStats) { rank++; cleansesSummary.AddCell($"{rank}", tableCellCenterAlign); cleansesSummary.AddCell($"{player.Name} ({player.ProfessionShort})"); cleansesSummary.AddCell($"{player.Support.First().CondiCleanseTotal}", tableCellRightAlign); } var cleansesField = new DiscordAPIJSONContentEmbedField() { Name = "Cleanses summary:", Value = $"```{cleansesSummary.Render()}```" }; // boon strips summary var boonStripsStats = reportJSON.ExtraJSON.Players .Where(x => !x.FriendNPC && !x.NotInSquad) .Where(x => x.Support.First().BoonStrips > 0) .OrderByDescending(x => x.Support.First().BoonStrips) .Take(10) .ToList(); var boonStripsSummary = new TextTable(3, tableStyle, tableBorders); boonStripsSummary.SetColumnWidthRange(0, 3, 3); boonStripsSummary.SetColumnWidthRange(1, 27, 27); boonStripsSummary.SetColumnWidthRange(2, 12, 12); boonStripsSummary.AddCell("#", tableCellCenterAlign); boonStripsSummary.AddCell("Name"); boonStripsSummary.AddCell("Strips", tableCellRightAlign); rank = 0; foreach (var player in boonStripsStats) { rank++; boonStripsSummary.AddCell($"{rank}", tableCellCenterAlign); boonStripsSummary.AddCell($"{player.Name} ({player.ProfessionShort})"); boonStripsSummary.AddCell($"{player.Support.First().BoonStrips}", tableCellRightAlign); } var boonStripsField = new DiscordAPIJSONContentEmbedField() { Name = "Boon strips summary:", Value = $"```{boonStripsSummary.Render()}```" }; // add the fields discordContentEmbed.Fields = new List <DiscordAPIJSONContentEmbedField>() { squadField, enemyField, damageField, cleansesField, boonStripsField }; } // post to discord var discordContentWvW = new DiscordAPIJSONContent() { Embeds = new List <DiscordAPIJSONContentEmbed>() { discordContentEmbed } }; try { var jsonContentWvW = JsonConvert.SerializeObject(discordContentWvW); foreach (var key in allWebhooks.Keys) { var webhook = allWebhooks[key]; if (!webhook.Active || (webhook.SuccessFailToggle.Equals(DiscordWebhookDataSuccessToggle.OnSuccessOnly) && !(reportJSON.Encounter.Success ?? false)) || (webhook.SuccessFailToggle.Equals(DiscordWebhookDataSuccessToggle.OnFailOnly) && (reportJSON.Encounter.Success ?? false)) || (webhook.BossesDisable.Contains(reportJSON.Encounter.BossId)) || (!webhook.Team.IsSatisfied(reportJSON.ExtraJSON))) { continue; } var uri = new Uri(webhook.URL); using var content = new StringContent(jsonContentWvW, Encoding.UTF8, "application/json"); using var response = await mainLink.HttpClientController.PostAsync(uri, content); } if (allWebhooks.Count > 0) { mainLink.AddToText(">:> All active webhooks successfully executed."); } } catch { mainLink.AddToText(">:> Unable to execute active webhooks."); } } else // not WvW { var bossName = $"{reportJSON.Encounter.Boss}{(reportJSON.ChallengeMode ? " CM" : string.Empty)}"; var successString = (reportJSON.Encounter.Success ?? false) ? ":white_check_mark:" : "❌"; var extraJSON = (reportJSON.ExtraJSON is null) ? string.Empty : $"Recorded by: {reportJSON.ExtraJSON.RecordedBy}\nDuration: {reportJSON.ExtraJSON.Duration}\nElite Insights version: {reportJSON.ExtraJSON.EliteInsightsVersion}\n"; var icon = string.Empty; var bossData = Bosses.GetBossDataFromId(reportJSON.Encounter.BossId); if (!(bossData is null)) { bossName = $"{bossData.Name}{(reportJSON.ChallengeMode ? " CM" : string.Empty)}"; icon = bossData.Icon; } var colour = (reportJSON.Encounter.Success ?? false) ? 32768 : 16711680; var discordContentEmbedThumbnail = new DiscordAPIJSONContentEmbedThumbnail() { Url = icon }; var timestampDateTime = DateTime.UtcNow; if (!(reportJSON.ExtraJSON is null)) { timestampDateTime = reportJSON.ExtraJSON.TimeStart; } var timestamp = timestampDateTime.ToString("o"); var discordContentEmbed = new DiscordAPIJSONContentEmbed() { Title = bossName, Url = reportJSON.Permalink, Description = $"{extraJSON}Result: {successString}\narcdps version: {reportJSON.EVTC.Type}{reportJSON.EVTC.Version}", Colour = colour, TimeStamp = timestamp, Thumbnail = discordContentEmbedThumbnail }; var discordContentWithoutPlayers = new DiscordAPIJSONContent() { Embeds = new List <DiscordAPIJSONContentEmbed>() { discordContentEmbed } }; var discordContentEmbedForPlayers = new DiscordAPIJSONContentEmbed() { Title = bossName, Url = reportJSON.Permalink, Description = $"{extraJSON}Result: {successString}\narcdps version: {reportJSON.EVTC.Type}{reportJSON.EVTC.Version}", Colour = colour, TimeStamp = timestamp, Thumbnail = discordContentEmbedThumbnail }; if (reportJSON.Players.Values.Count <= 10) { var fields = new List <DiscordAPIJSONContentEmbedField>(); if (reportJSON.ExtraJSON is null) { foreach (var player in reportJSON.Players.Values) { fields.Add(new DiscordAPIJSONContentEmbedField() { Name = player.CharacterName, Value = $"```\n{player.DisplayName}\n\n{Players.ResolveSpecName(player.Profession, player.EliteSpec)}\n```", Inline = true }); } } else { // player list var playerNames = new TextTable(2, tableStyle, tableBorders); playerNames.SetColumnWidthRange(0, 21, 21); playerNames.SetColumnWidthRange(1, 20, 20); playerNames.AddCell("Character"); playerNames.AddCell("Account name"); foreach (var player in reportJSON.ExtraJSON.Players.Where(x => !x.FriendNPC).OrderBy(x => x.Name)) { playerNames.AddCell($"{player.Name}"); playerNames.AddCell($"{player.Account}"); } fields.Add(new DiscordAPIJSONContentEmbedField() { Name = "Players in squad/group:", Value = $"```{playerNames.Render()}```" }); var numberOfRealTargers = reportJSON.ExtraJSON.Targets .Where(x => !x.IsFake) .Count(); // damage summary var damageStats = reportJSON.ExtraJSON.Players .Where(x => !x.FriendNPC) .Select(x => new { Player = x, DPS = numberOfRealTargers > 0 ? reportJSON.ExtraJSON.PlayerTargetDPS[x] : x.DpsAll.First().DPS }) .OrderByDescending(x => x.DPS) .Take(10) .ToList(); var dpsTargetSummary = new TextTable(3, tableStyle, TableVisibleBorders.HEADER_AND_FOOTER); dpsTargetSummary.SetColumnWidthRange(0, 5, 5); dpsTargetSummary.SetColumnWidthRange(1, 27, 27); dpsTargetSummary.SetColumnWidthRange(2, 8, 8); dpsTargetSummary.AddCell("#", tableCellCenterAlign); dpsTargetSummary.AddCell("Name"); dpsTargetSummary.AddCell("DPS", tableCellRightAlign); var rank = 0; foreach (var player in damageStats) { rank++; dpsTargetSummary.AddCell($"{rank}", tableCellCenterAlign); dpsTargetSummary.AddCell($"{player.Player.Name} ({player.Player.ProfessionShort})"); dpsTargetSummary.AddCell($"{player.DPS.ParseAsK()}", tableCellRightAlign); } dpsTargetSummary.AddCell(string.Empty); dpsTargetSummary.AddCell("Total"); var totalDPS = damageStats .Select(x => x.DPS) .Sum(); dpsTargetSummary.AddCell($"{totalDPS.ParseAsK()}", tableCellRightAlign); fields.Add(new DiscordAPIJSONContentEmbedField() { Name = "DPS target summary:", Value = $"```{dpsTargetSummary.Render()}```" }); } discordContentEmbedForPlayers.Fields = fields; } var discordContentWithPlayers = new DiscordAPIJSONContent() { Embeds = new List <DiscordAPIJSONContentEmbed>() { discordContentEmbedForPlayers } }; try { var jsonContentWithoutPlayers = JsonConvert.SerializeObject(discordContentWithoutPlayers); var jsonContentWithPlayers = JsonConvert.SerializeObject(discordContentWithPlayers); foreach (var key in allWebhooks.Keys) { var webhook = allWebhooks[key]; if (!webhook.Active || (webhook.SuccessFailToggle.Equals(DiscordWebhookDataSuccessToggle.OnSuccessOnly) && !(reportJSON.Encounter.Success ?? false)) || (webhook.SuccessFailToggle.Equals(DiscordWebhookDataSuccessToggle.OnFailOnly) && (reportJSON.Encounter.Success ?? false)) || (webhook.BossesDisable.Contains(reportJSON.Encounter.BossId)) || (!webhook.Team.IsSatisfied(reportJSON.ExtraJSON))) { continue; } var uri = new Uri(webhook.URL); if (webhook.ShowPlayers) { using var content = new StringContent(jsonContentWithPlayers, Encoding.UTF8, "application/json"); using (await mainLink.HttpClientController.PostAsync(uri, content)) { } } else { using var content = new StringContent(jsonContentWithoutPlayers, Encoding.UTF8, "application/json"); using (await mainLink.HttpClientController.PostAsync(uri, content)) { } } } if (allWebhooks.Count > 0) { mainLink.AddToText(">:> All active webhooks successfully executed."); } } catch { mainLink.AddToText(">:> Unable to execute active webhooks."); } } }