From f2ad66d659256622ec271e13833a5bacaaf9c0a5 Mon Sep 17 00:00:00 2001 From: Will Hunt <half-shot@molrams.com> Date: Sun, 17 Sep 2017 09:31:17 +0100 Subject: [PATCH] Fix embeds not checking description value. --- src/messageprocessor.ts | 9 +++++++-- test/test_messageprocessor.ts | 14 +++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/messageprocessor.ts b/src/messageprocessor.ts index 8142611..3d186bf 100644 --- a/src/messageprocessor.ts +++ b/src/messageprocessor.ts @@ -48,9 +48,14 @@ export class MessageProcessor { public InsertEmbeds(content: string, msg: Discord.Message): string { for (const embed of msg.embeds) { - let embedContent = "\n----\n"; // Horizontal rule. + let embedContent = "\n\n----"; // Horizontal rule. Two to make sure the content doesn't become a title. const embedTitle = embed.url ? `[${embed.title}](${embed.url})` : embed.title; - embedContent += embedTitle != null ? `#### ${embedTitle}\n\n${embed.description}` : embed.description; + if (embedTitle) { + embedContent += "\n##### " + embedTitle; // h5 is probably best. + } + if (embed.description) { + embedContent += "\n" + embed.description; + } content += embedContent; } return content; diff --git a/test/test_messageprocessor.ts b/test/test_messageprocessor.ts index 71b527e..a793d3a 100644 --- a/test/test_messageprocessor.ts +++ b/test/test_messageprocessor.ts @@ -175,7 +175,7 @@ describe("MessageProcessor", () => { ]; const inContent = ""; const content = processor.InsertEmbeds(inContent, msg); - Chai.assert.equal(content, "\n----\nTestDescription"); + Chai.assert.equal(content, "\n\n----\nTestDescription"); }); it("processes urlless embeds properly", () => { const processor = new MessageProcessor(new MessageProcessorOpts("localhost"), <DiscordBot> bot); @@ -188,7 +188,7 @@ describe("MessageProcessor", () => { ]; const inContent = ""; const content = processor.InsertEmbeds(inContent, msg); - Chai.assert.equal(content, "\n----\n#### TestTitle\n\nTestDescription"); + Chai.assert.equal(content, "\n\n----\n##### TestTitle\nTestDescription"); }); it("processes linked embeds properly", () => { const processor = new MessageProcessor(new MessageProcessorOpts("localhost"), <DiscordBot> bot); @@ -202,7 +202,7 @@ describe("MessageProcessor", () => { ]; const inContent = ""; const content = processor.InsertEmbeds(inContent, msg); - Chai.assert.equal(content, "\n----\n#### [TestTitle](testurl)\n\nTestDescription"); + Chai.assert.equal(content, "\n\n----\n##### [TestTitle](testurl)\nTestDescription"); }); it("processes multiple embeds properly", () => { const processor = new MessageProcessor(new MessageProcessorOpts("localhost"), <DiscordBot> bot); @@ -223,7 +223,7 @@ describe("MessageProcessor", () => { const content = processor.InsertEmbeds(inContent, msg); Chai.assert.equal( content, -"\n----\n#### [TestTitle](testurl)\n\nTestDescription\n----\n#### [TestTitle2](testurl2)\n\nTestDescription2", +"\n\n----\n##### [TestTitle](testurl)\nTestDescription\n\n----\n##### [TestTitle2](testurl2)\nTestDescription2", ); }); it("inserts embeds properly", () => { @@ -240,7 +240,11 @@ describe("MessageProcessor", () => { const content = processor.InsertEmbeds(inContent, msg); Chai.assert.equal( content, - "Content that goes in the message\n----\n#### [TestTitle](testurl)\n\nTestDescription", +`Content that goes in the message + +---- +##### [TestTitle](testurl) +TestDescription`, ); }); }); -- GitLab