Skip to content
Extraits de code Groupes Projets
Non vérifiée Valider e7cf5bdf rédigé par Sorunome's avatar Sorunome
Parcourir les fichiers

Merge remote-tracking branch 'origin/soru/embed-images' into develop

parents e9f22b29 811186f2
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -138,6 +138,16 @@ export class DiscordMessageProcessor {
escapeHTML: false,
});
}
if (embed.image) {
embedContent += "\nImage: " + embed.image.url;
}
if (embed.footer) {
embedContent += "\n" + markdown.toHTML(embed.footer.text, {
discordCallback: this.getDiscordParseCallbacks(msg),
discordOnly: true,
escapeHTML: false,
});
}
content += embedContent;
}
return content;
......@@ -154,15 +164,27 @@ export class DiscordMessageProcessor {
let embedContent = "<hr>"; // Horizontal rule. Two to make sure the content doesn't become a title.
const embedTitle = embed.url ?
`<a href="${escapeHtml(embed.url)}">${escapeHtml(embed.title)}</a>`
: escapeHtml(embed.title);
: (embed.title ? escapeHtml(embed.title) : undefined);
if (embedTitle) {
embedContent += `<h5>${embedTitle}</h5>`; // h5 is probably best.
}
if (embed.description) {
embedContent += "<p>";
embedContent += markdown.toHTML(embed.description, {
discordCallback: this.getDiscordParseCallbacksHTML(msg),
embed: true,
});
}) + "</p>";
}
if (embed.image) {
const imgUrl = escapeHtml(embed.image.url);
embedContent += `<p>Image: <a href="${imgUrl}">${imgUrl}</a></p>`;
}
if (embed.footer) {
embedContent += "<p>";
embedContent += markdown.toHTML(embed.footer.text, {
discordCallback: this.getDiscordParseCallbacksHTML(msg),
embed: true,
}) + "</p>";
}
content += embedContent;
}
......
......@@ -135,9 +135,9 @@ describe("DiscordMessageProcessor", () => {
createdTimestamp: {} as any,
description: "Description",
fields: {} as any,
footer: {} as any,
footer: undefined as any,
hexColor: {} as any,
image: {} as any,
image: undefined as any,
message: {} as any,
provider: {} as any,
thumbnail: {} as any,
......@@ -151,7 +151,7 @@ describe("DiscordMessageProcessor", () => {
const result = await processor.FormatMessage(msg);
Chai.assert.equal(result.body, "message\n\n----\n##### [Title](http://example.com)\nDescription");
Chai.assert.equal(result.formattedBody, "message<hr><h5><a href=\"http://example.com\">Title</a>" +
"</h5>Description");
"</h5><p>Description</p>");
});
it("should ignore same-url embeds", async () => {
const processor = new DiscordMessageProcessor(
......@@ -537,6 +537,54 @@ describe("DiscordMessageProcessor", () => {
TestDescription`,
);
});
it("adds images 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].image = { url: "http://example.com" } 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
Image: http://example.com`,
);
});
it("adds a footer 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].footer = { text: "footer" } 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
footer`,
);
});
});
describe("Message Type", () => {
it("sets non-bot messages as m.text", async () => {
......
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