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
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -48,9 +48,14 @@ export class MessageProcessor { ...@@ -48,9 +48,14 @@ export class MessageProcessor {
public InsertEmbeds(content: string, msg: Discord.Message): string { public InsertEmbeds(content: string, msg: Discord.Message): string {
for (const embed of msg.embeds) { 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; 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; content += embedContent;
} }
return content; return content;
......
...@@ -175,7 +175,7 @@ describe("MessageProcessor", () => { ...@@ -175,7 +175,7 @@ describe("MessageProcessor", () => {
]; ];
const inContent = ""; const inContent = "";
const content = processor.InsertEmbeds(inContent, msg); const content = processor.InsertEmbeds(inContent, msg);
Chai.assert.equal(content, "\n----\nTestDescription"); Chai.assert.equal(content, "\n\n----\nTestDescription");
}); });
it("processes urlless embeds properly", () => { it("processes urlless embeds properly", () => {
const processor = new MessageProcessor(new MessageProcessorOpts("localhost"), <DiscordBot> bot); const processor = new MessageProcessor(new MessageProcessorOpts("localhost"), <DiscordBot> bot);
...@@ -188,7 +188,7 @@ describe("MessageProcessor", () => { ...@@ -188,7 +188,7 @@ describe("MessageProcessor", () => {
]; ];
const inContent = ""; const inContent = "";
const content = processor.InsertEmbeds(inContent, msg); 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", () => { it("processes linked embeds properly", () => {
const processor = new MessageProcessor(new MessageProcessorOpts("localhost"), <DiscordBot> bot); const processor = new MessageProcessor(new MessageProcessorOpts("localhost"), <DiscordBot> bot);
...@@ -202,7 +202,7 @@ describe("MessageProcessor", () => { ...@@ -202,7 +202,7 @@ describe("MessageProcessor", () => {
]; ];
const inContent = ""; const inContent = "";
const content = processor.InsertEmbeds(inContent, msg); 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", () => { it("processes multiple embeds properly", () => {
const processor = new MessageProcessor(new MessageProcessorOpts("localhost"), <DiscordBot> bot); const processor = new MessageProcessor(new MessageProcessorOpts("localhost"), <DiscordBot> bot);
...@@ -223,7 +223,7 @@ describe("MessageProcessor", () => { ...@@ -223,7 +223,7 @@ describe("MessageProcessor", () => {
const content = processor.InsertEmbeds(inContent, msg); const content = processor.InsertEmbeds(inContent, msg);
Chai.assert.equal( Chai.assert.equal(
content, 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", () => { it("inserts embeds properly", () => {
...@@ -240,7 +240,11 @@ describe("MessageProcessor", () => { ...@@ -240,7 +240,11 @@ describe("MessageProcessor", () => {
const content = processor.InsertEmbeds(inContent, msg); const content = processor.InsertEmbeds(inContent, msg);
Chai.assert.equal( Chai.assert.equal(
content, 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.
Veuillez vous inscrire ou vous pour commenter