From bee1162b4eb7ee97375e5e28c2c2e777ae802bbc Mon Sep 17 00:00:00 2001 From: Will Hunt <half-shot@molrams.com> Date: Mon, 20 Feb 2017 23:41:39 +0000 Subject: [PATCH] Convert mentions to usernames. --- src/discordbot.ts | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/discordbot.ts b/src/discordbot.ts index 14a0e52..7d63d8c 100644 --- a/src/discordbot.ts +++ b/src/discordbot.ts @@ -276,19 +276,22 @@ export class DiscordBot { }); }); if (msg.content !== null && msg.content !== "") { - const markdown = marked(msg.content); - if (markdown !== msg.content) { - // Markdown message - intent.sendMessage(room, { - body: msg.content, - msgtype: "m.text", - formatted_body: markdown, - format: "org.matrix.custom.html", - }); - } else { - // Plain text - intent.sendText(room, msg.content); - } + // Replace mentions. + const content = msg.content.replace(/<@[0-9]*>/g, (item) => { + const id = item.substr(2, item.length - 3); + const member = msg.guild.members.get(id); + if (member) { + return member.user.username; + } else { + return `@_discord_${id}:${this.config.bridge.domain}`; + } + }); + intent.sendMessage(room, { + body: content, + msgtype: "m.text", + formatted_body: marked(content), + format: "org.matrix.custom.html", + }); } }); } -- GitLab