Skip to content
Extraits de code Groupes Projets
Valider 173a6b33 rédigé par Will Hunt's avatar Will Hunt Validation de GitHub
Parcourir les fichiers

Merge pull request #44 from Half-Shot/fix-43

Fix embeds not checking description value.
parents d48ba9b4 f2ad66d6
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -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;
......
......@@ -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`,
);
});
});
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment