static void Main() { // 1. BASIC TABLE EXAMPLE var basicTable = new TextTable(3); basicTable.AddCell("Artist"); basicTable.AddCell("Album"); basicTable.AddCell("Year"); basicTable.AddCell("Jamiroquai"); basicTable.AddCell("Emergency on Planet Earth"); basicTable.AddCell("1993"); basicTable.AddCell("Jamiroquai"); basicTable.AddCell("The Return of the Space Cowboy"); basicTable.AddCell("1994"); Console.WriteLine(basicTable.Render()); // +----------+-------------------------------+-----+ // |Artist |Album |Year| // +----------+-------------------------------+-----+ // |Jamiroquai|Emergency on Planet Earth |1993| // |Jamiroquai|The Return of the Space Cowboy|1994| // +----------+-------------------------------+-----+ // 2. ADVANCED TABLE EXAMPLE var numberStyleAdvancedTable = new CellStyle(CellHorizontalAlignment.Right); var advancedTable = new TextTable(3, TableBordersStyle.DESIGN_FORMAL, TableVisibleBorders.SURROUND_HEADER_FOOTER_AND_COLUMNS); advancedTable.SetColumnWidthRange(0, 6, 14); advancedTable.SetColumnWidthRange(1, 4, 12); advancedTable.SetColumnWidthRange(2, 4, 12); advancedTable.AddCell("Region"); advancedTable.AddCell("Orders", numberStyleAdvancedTable); advancedTable.AddCell("Sales", numberStyleAdvancedTable); advancedTable.AddCell("North"); advancedTable.AddCell("6,345", numberStyleAdvancedTable); advancedTable.AddCell("$87.230", numberStyleAdvancedTable); advancedTable.AddCell("Center"); advancedTable.AddCell("837", numberStyleAdvancedTable); advancedTable.AddCell("$12.855", numberStyleAdvancedTable); advancedTable.AddCell("South"); advancedTable.AddCell("5,344", numberStyleAdvancedTable); advancedTable.AddCell("$72.561", numberStyleAdvancedTable); advancedTable.AddCell("Total", numberStyleAdvancedTable, 2); advancedTable.AddCell("$172.646", numberStyleAdvancedTable); Console.WriteLine(advancedTable.Render()); // ====================== // Region Orders Sales // ------ ------ -------- // North 6,345 $87.230 // Center 837 $12.855 // South 5,344 $72.561 // ------ ------ -------- // Total $172.646 // ====================== // 3. FANCY TABLE EXAMPLE var numberStyleFancyTable = new CellStyle(CellHorizontalAlignment.Right); var fancyTable = new TextTable(3, TableBordersStyle.DESIGN_PAPYRUS, TableVisibleBorders.SURROUND_HEADER_FOOTER_AND_COLUMNS); fancyTable.AddCell("Region"); fancyTable.AddCell("Orders", numberStyleFancyTable); fancyTable.AddCell("Sales", numberStyleFancyTable); fancyTable.AddCell("North"); fancyTable.AddCell("6,345", numberStyleFancyTable); fancyTable.AddCell("$87.230", numberStyleFancyTable); fancyTable.AddCell("Center"); fancyTable.AddCell("837", numberStyleFancyTable); fancyTable.AddCell("$12.855", numberStyleFancyTable); fancyTable.AddCell("South"); fancyTable.AddCell("5,344", numberStyleFancyTable); fancyTable.AddCell("$72.561", numberStyleFancyTable); fancyTable.AddCell("Total", numberStyleFancyTable, 2); fancyTable.AddCell("$172.646", numberStyleFancyTable); Console.WriteLine(fancyTable.Render()); // o~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~o // ) Region Orders Sales ( // ) ~~~~~~ ~~~~~~ ~~~~~~~~ ( // ) North 6,345 $87.230 ( // ) Center 837 $12.855 ( // ) South 5,344 $72.561 ( // ) ~~~~~~ ~~~~~~ ~~~~~~~~ ( // ) Total $172.646 ( // o~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~o // 4. UNICODE TABLE EXAMPLE var numberStyleUnicodeTable = new CellStyle(CellHorizontalAlignment.Right); var unicodeTable = new TextTable(3, TableBordersStyle.UNICODE_BOX_DOUBLE_BORDER_WIDE, TableVisibleBorders.SURROUND_HEADER_FOOTER_AND_COLUMNS, true); unicodeTable.AddCell("Region"); unicodeTable.AddCell("Orders", numberStyleUnicodeTable); unicodeTable.AddCell("Sales", numberStyleUnicodeTable); unicodeTable.AddCell("North"); unicodeTable.AddCell("6,345", numberStyleUnicodeTable); unicodeTable.AddCell("$87.230", numberStyleUnicodeTable); unicodeTable.AddCell("Center"); unicodeTable.AddCell("837", numberStyleUnicodeTable); unicodeTable.AddCell("$12.855", numberStyleUnicodeTable); unicodeTable.AddCell("South"); unicodeTable.AddCell("5,344", numberStyleUnicodeTable); unicodeTable.AddCell("$72.561", numberStyleUnicodeTable); unicodeTable.AddCell("Total", numberStyleUnicodeTable, 2); unicodeTable.AddCell("$172.646", numberStyleUnicodeTable); var unicodeTableStringArray = unicodeTable.RenderAsStringArray(); var sb = new StringBuilder("<html><body><pre>"); foreach (string line in unicodeTableStringArray) { sb.Append(line); sb.Append("<br>"); } sb.Append("</pre></html>"); File.WriteAllText("unicode.html", sb.ToString(), Encoding.UTF8); // unicode.html // ╔════════╤════════╤══════════╗ // ║ Region │ Orders │ Sales ║ // ╟────────┼────────┼──────────╢ // ║ North │ 6,345 │ $87.230 ║ // ║ Center │ 837 │ $12.855 ║ // ║ South │ 5,344 │ $72.561 ║ // ╟────────┴────────┼──────────╢ // ║ Total │ $172.646 ║ // ╚═════════════════╧══════════╝ }
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."); } } }