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 InsertUser(node: IDiscordNode, msg: Discord.Message, html: boolean = false): string { const id = node.id; const member = msg.guild.members.get(id); const memberId = `@_discord_${id}:${this.opts.domain}`; const memberName = member ? member.displayName : memberId; if (!html) { return memberName; } return `<a href="${MATRIX_TO_LINK}${escapeHtml(memberId)}">${escapeHtml(memberName)}</a>`; }
public InsertChannel(node: IDiscordNode, msg: Discord.Message, html: boolean = false): string { const id = node.id; const channel = msg.guild.channels.get(id); if (!channel) { return html ? `<#${escapeHtml(id)}>` : `<#${id}>`; } const channelStr = escapeHtml(channel ? "#" + channel.name : "#" + id); if (!html) { return channelStr; } const roomId = escapeHtml(`#_discord_${msg.guild.id}_${id}:${this.opts.domain}`); return `<a href="${MATRIX_TO_LINK}${roomId}">${escapeHtml(channelStr)}</a>`; }
public InsertEmoji(node: IEmojiNode): string { // unfortunately these callbacks are sync, so we flag our url with some special stuff // and later on grab the real url async const FLAG = "\x01"; const name = escapeHtml(node.name); return `${FLAG}${name}${FLAG}${node.animated ? 1 : 0}${FLAG}${node.id}${FLAG}`; }
(error: send.SendError) => { if (error.status === 404 && !filePathRegex.test(filePath)) { // The static file handling middleware failed to find a file on // disk. Serve the entry point HTML file instead of a 404. send(req, entrypoint, {root: root}).pipe(res); } else { res.status(error.status || 500); res.type('html'); res.end(escapeHtml(error.message)); } })
public InsertRole(node: IDiscordNode, msg: Discord.Message, html: boolean = false): string { const id = node.id; const role = msg.guild.roles.get(id); if (!role) { return html ? `<@&${id}>` : `<@&${id}>`; } if (!html) { return `@${role.name}`; } const color = Util.NumberToHTMLColor(role.color); return `<span data-mx-color="${color}"><strong>@${escapeHtml(role.name)}</strong></span>`; }
redisClient.get(escape(id), function (err, reply) { if (err) return errorHandler.handleError(res, err); if (!reply) { return errorHandler.sendError(res, errorHandler.ERROR_NOT_FOUND, "No se pudo cargar la imagen " + id); } req.image = { id: escape(id), image: reply }; next(); });
export function findByID(req: IFindByIdRequest, res: express.Response, next: NextFunction) { const id = req.params.imageId; redisClient.get(escape(id), function (err, reply) { if (err) return errorHandler.handleError(res, err); if (!reply) { return errorHandler.sendError(res, errorHandler.ERROR_NOT_FOUND, "No se pudo cargar la imagen " + id); } req.image = { id: escape(id), image: reply }; next(); }); }
export function fillProvinceIfPresent(req: IFindProvince, res: express.Response, next: NextFunction) { // Si no viene ninguna provincia definida, no hacemos nada if (!req.body.province) { return next(); } Province.findOne({ _id: escape(req.body.province), enabled: true }, function (err, province) { if (err) return errorHandler.handleError(res, err); if (!province) { return errorHandler.sendError(res, errorHandler.ERROR_NOT_FOUND, "No se encuentra la provincia " + req.body.province); } req.province = province; next(); }); }
public async FormatEdit( oldMsg: Discord.Message, newMsg: Discord.Message, link?: string, ): Promise<DiscordMessageProcessorResult> { oldMsg.embeds = []; // we don't want embeds on old msg const oldMsgParsed = await this.FormatMessage(oldMsg); const newMsgParsed = await this.FormatMessage(newMsg); const result = new DiscordMessageProcessorResult(); result.body = `*edit:* ~~${oldMsgParsed.body}~~ -> ${newMsgParsed.body}`; result.msgtype = newMsgParsed.msgtype; oldMsg.content = `*edit:* ~~${oldMsg.content}~~ -> ${newMsg.content}`; const linkStart = link ? `<a href="${escapeHtml(link)}">` : ""; const linkEnd = link ? "</a>" : ""; if (oldMsg.content.includes("\n") || newMsg.content.includes("\n") || newMsg.content.length > MAX_EDIT_MSG_LENGTH) { result.formattedBody = `<p>${linkStart}<em>edit:</em>${linkEnd}</p><p><del>${oldMsgParsed.formattedBody}` + `</del></p><hr><p>${newMsgParsed.formattedBody}</p>`; } else { result.formattedBody = `${linkStart}<em>edit:</em>${linkEnd} <del>${oldMsgParsed.formattedBody}</del>` + ` -> ${newMsgParsed.formattedBody}`; } return result; }