diff --git a/src/discordmessageprocessor.ts b/src/discordmessageprocessor.ts index 408020531fc7309e146654611400f3681308d0db..e91b8bf6112ff2f9cf88c11a30029514a3d301d8 100644 --- a/src/discordmessageprocessor.ts +++ b/src/discordmessageprocessor.ts @@ -138,6 +138,16 @@ export class DiscordMessageProcessor { escapeHTML: false, }); } + if (embed.fields) { + for (const field of embed.fields) { + embedContent += `\n**${field.name}**\n`; + embedContent += markdown.toHTML(field.value, { + discordCallback: this.getDiscordParseCallbacks(msg), + discordOnly: true, + escapeHTML: false, + }); + } + } if (embed.image) { embedContent += "\nImage: " + embed.image.url; } @@ -175,6 +185,15 @@ export class DiscordMessageProcessor { embed: true, }) + "</p>"; } + if (embed.fields) { + for (const field of embed.fields) { + embedContent += `<p><strong>${escapeHtml(field.name)}</strong><br>`; + embedContent += markdown.toHTML(field.value, { + discordCallback: this.getDiscordParseCallbacks(msg), + embed: true, + }) + "</p>"; + } + } if (embed.image) { const imgUrl = escapeHtml(embed.image.url); embedContent += `<p>Image: <a href="${imgUrl}">${imgUrl}</a></p>`; diff --git a/test/test_discordmessageprocessor.ts b/test/test_discordmessageprocessor.ts index bdab358568283a893cc4c214902c0a0371122316..68206a5ed9ab3b68a4ef784b1e5caef4eed32276 100644 --- a/test/test_discordmessageprocessor.ts +++ b/test/test_discordmessageprocessor.ts @@ -134,7 +134,7 @@ describe("DiscordMessageProcessor", () => { createdAt: {} as any, createdTimestamp: {} as any, description: "Description", - fields: {} as any, + fields: [] as any, footer: undefined as any, hexColor: {} as any, image: undefined as any, @@ -165,7 +165,7 @@ describe("DiscordMessageProcessor", () => { createdAt: {} as any, createdTimestamp: {} as any, description: "Description", - fields: {} as any, + fields: [] as any, footer: {} as any, hexColor: {} as any, image: {} as any, @@ -537,6 +537,38 @@ describe("DiscordMessageProcessor", () => { TestDescription`, ); }); + it("adds fields properly", () => { + const processor = new DiscordMessageProcessor( + new DiscordMessageProcessorOpts("localhost"), bot as DiscordBot); + const msg = new MockMessage() as any; + msg.embeds = [ + new Discord.MessageEmbed(msg, { + description: "TestDescription", + title: "TestTitle", + url: "testurl", + }), + ]; + msg.embeds[0].fields = [ + { + embed: msg.embeds[0], + inline: false, + name: "fox", + value: "floof", + }, + ] as any; + const inContent = "Content that goes in the message"; + const content = processor.InsertEmbeds(inContent, msg); + Chai.assert.equal( + content, +`Content that goes in the message + +---- +##### [TestTitle](testurl) +TestDescription +**fox** +floof`, + ); + }); it("adds images properly", () => { const processor = new DiscordMessageProcessor( new DiscordMessageProcessorOpts("localhost"), bot as DiscordBot);