public async FormatMessage(msg: Discord.Message): Promise<DiscordMessageProcessorResult> { const result = new DiscordMessageProcessorResult(); let content = msg.content; // for the formatted body we need to parse markdown first // as else it'll HTML escape the result of the discord syntax let contentPostmark = markdown.toHTML(content, { discordCallback: this.getDiscordParseCallbacksHTML(msg), }); // parse the plain text stuff content = markdown.toHTML(content, { discordCallback: this.getDiscordParseCallbacks(msg), discordOnly: true, escapeHTML: false, }); content = this.InsertEmbeds(content, msg); content = await this.InsertMxcImages(content, msg); // parse postmark stuff contentPostmark = this.InsertEmbedsPostmark(contentPostmark, msg); contentPostmark = await this.InsertMxcImages(contentPostmark, msg, true); result.body = content; result.formattedBody = contentPostmark; result.msgtype = msg.author.bot ? "m.notice" : "m.text"; return result; }
public InsertEmbedsPostmark(content: string, msg: Discord.Message): string { for (const embed of msg.embeds) { if (embed.title === undefined && embed.description === undefined) { continue; } if (this.isEmbedInBody(msg, embed)) { continue; } 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); if (embedTitle) { embedContent += `<h5>${embedTitle}</h5>`; // h5 is probably best. } if (embed.description) { embedContent += markdown.toHTML(embed.description, { discordCallback: this.getDiscordParseCallbacksHTML(msg), embed: true, }); } content += embedContent; } return content; }
public InsertEmbeds(content: string, msg: Discord.Message): string { for (const embed of msg.embeds) { if (embed.title === undefined && embed.description === undefined) { continue; } if (this.isEmbedInBody(msg, embed)) { continue; } 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; if (embedTitle) { embedContent += "\n##### " + embedTitle; // h5 is probably best. } if (embed.description) { embedContent += "\n" + markdown.toHTML(embed.description, { discordCallback: this.getDiscordParseCallbacks(msg), discordOnly: true, escapeHTML: false, }); } content += embedContent; } return content; }