Skip to content

Commit

Permalink
Fixed Discord embed issues caused by latest Discord update
Browse files Browse the repository at this point in the history
  • Loading branch information
Plenyx committed Apr 6, 2024
1 parent adc543b commit b9bf8e9
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 15 deletions.
22 changes: 22 additions & 0 deletions DiscordApi/DiscordApiJsonContent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Text;

namespace PlenBotLogUploader.DiscordApi
{
Expand All @@ -8,6 +9,27 @@ namespace PlenBotLogUploader.DiscordApi
/// </summary>
internal sealed class DiscordApiJsonContent
{
private static string _spacer = null;

internal static string Spacer
{
get
{
if (_spacer is null)
{
var spacerBuilder = new StringBuilder();

for (int i = 0; i < 26; i++)
{
spacerBuilder.Append("〰️");
}

_spacer = spacerBuilder.ToString();
}
return _spacer;
}
}

/// <summary>
/// the message contents (up to 2000 characters)
/// </summary>
Expand Down
49 changes: 34 additions & 15 deletions Forms/FormDiscordWebhooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ internal async Task ExecuteAllActiveWebhooksAsync(DpsReportJson reportJSON, List
TimeStamp = timestamp,
Thumbnail = discordContentEmbedThumbnail,
};
var discordContentEmbedSpacer = new DiscordApiJsonContentEmbed()
{
Title = "Log data",
Description = DiscordApiJsonContent.Spacer,
Colour = colour,
TimeStamp = timestamp,
};
// fields
var discordContentEmbedSquadAndPlayers = new List<DiscordApiJsonContentEmbedField>();
var discordContentEmbedSquad = new List<DiscordApiJsonContentEmbedField>();
Expand Down Expand Up @@ -331,16 +338,18 @@ internal async Task ExecuteAllActiveWebhooksAsync(DpsReportJson reportJSON, List
// post to discord
var discordContentWvW = new DiscordApiJsonContent()
{
Embeds = [discordContentEmbed]
Embeds = [discordContentEmbed],
};
discordContentWvW.Embeds[0].Fields = discordContentEmbedSquadAndPlayers;
discordContentWvW.Embeds[0].Fields = discordContentEmbedNone;
var jsonContentWvWNone = JsonConvert.SerializeObject(discordContentWvW);
discordContentWvW.Embeds.Add(discordContentEmbedSpacer);

discordContentWvW.Embeds[1].Fields = discordContentEmbedSquadAndPlayers;
var jsonContentWvWSquadAndPlayers = JsonConvert.SerializeObject(discordContentWvW);
discordContentWvW.Embeds[0].Fields = discordContentEmbedSquad;
discordContentWvW.Embeds[1].Fields = discordContentEmbedSquad;
var jsonContentWvWSquad = JsonConvert.SerializeObject(discordContentWvW);
discordContentWvW.Embeds[0].Fields = discordContentEmbedPlayers;
discordContentWvW.Embeds[1].Fields = discordContentEmbedPlayers;
var jsonContentWvWPlayers = JsonConvert.SerializeObject(discordContentWvW);
discordContentWvW.Embeds[0].Fields = discordContentEmbedNone;
var jsonContentWvWNone = JsonConvert.SerializeObject(discordContentWvW);

await SendLogViaWebhooks(reportJSON.Encounter.Success ?? false,
reportJSON.Encounter.BossId,
Expand Down Expand Up @@ -388,6 +397,13 @@ await SendLogViaWebhooks(reportJSON.Encounter.Success ?? false,
TimeStamp = timestamp,
Thumbnail = discordContentEmbedThumbnail,
};
var discordContentEmbedSpacer = new DiscordApiJsonContentEmbed()
{
Title = "Log data",
Description = DiscordApiJsonContent.Spacer,
Colour = colour,
TimeStamp = timestamp,
};
var discordContentEmbedSquadAndPlayers = new List<DiscordApiJsonContentEmbedField>();
var discordContentEmbedSquad = new List<DiscordApiJsonContentEmbedField>();
var discordContentEmbedPlayers = new List<DiscordApiJsonContentEmbedField>();
Expand Down Expand Up @@ -419,8 +435,8 @@ await SendLogViaWebhooks(reportJSON.Encounter.Success ?? false,
{
// player list
var playerNames = new TextTable(2, tableStyle, tableBorders);
playerNames.SetColumnWidthRange(0, 21, 21);
playerNames.SetColumnWidthRange(1, 20, 20);
playerNames.SetColumnWidthRange(0, 23, 23);
playerNames.SetColumnWidthRange(1, 23, 23);
playerNames.AddCell("Character");
playerNames.AddCell("Account name");
foreach (var player in reportJSON.ExtraJson.Players.Where(x => !x.FriendlyNpc).OrderBy(x => x.Name))
Expand Down Expand Up @@ -451,8 +467,8 @@ await SendLogViaWebhooks(reportJSON.Encounter.Success ?? false,
.ToArray();
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.SetColumnWidthRange(1, 31, 31);
dpsTargetSummary.SetColumnWidthRange(2, 10, 10);
dpsTargetSummary.AddCell("#", tableCellCenterAlign);
dpsTargetSummary.AddCell("Name");
dpsTargetSummary.AddCell("DPS", tableCellRightAlign);
Expand All @@ -479,18 +495,21 @@ await SendLogViaWebhooks(reportJSON.Encounter.Success ?? false,
discordContentEmbedPlayers.Add(playersEmbedField);
}
}

var discordContent = new DiscordApiJsonContent()
{
Embeds = [discordContentEmbed],
};
discordContent.Embeds[0].Fields = discordContentEmbedSquadAndPlayers;
discordContent.Embeds[0].Fields = discordContentEmbedNone;
discordContent.Embeds.Add(discordContentEmbedSpacer);
var jsonContentNone = JsonConvert.SerializeObject(discordContent);

discordContent.Embeds[1].Fields = discordContentEmbedSquadAndPlayers;
var jsonContentSquadAndPlayers = JsonConvert.SerializeObject(discordContent);
discordContent.Embeds[0].Fields = discordContentEmbedSquad;
discordContent.Embeds[1].Fields = discordContentEmbedSquad;
var jsonContentSquad = JsonConvert.SerializeObject(discordContent);
discordContent.Embeds[0].Fields = discordContentEmbedPlayers;
discordContent.Embeds[1].Fields = discordContentEmbedPlayers;
var jsonContentPlayers = JsonConvert.SerializeObject(discordContent);
discordContent.Embeds[0].Fields = discordContentEmbedNone;
var jsonContentNone = JsonConvert.SerializeObject(discordContent);

await SendLogViaWebhooks(reportJSON.Encounter.Success ?? false,
reportJSON.Encounter.BossId,
Expand Down

0 comments on commit b9bf8e9

Please sign in to comment.