From a1b9b90f964c954565da3c291366953e696239f4 Mon Sep 17 00:00:00 2001
From: Will Hunt <half-shot@molrams.com>
Date: Thu, 16 Mar 2017 14:38:21 +0000
Subject: [PATCH] Add mention support for Matrix->Discord

---
 src/bot.ts | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/bot.ts b/src/bot.ts
index b80cf60..6f50a49 100644
--- a/src/bot.ts
+++ b/src/bot.ts
@@ -123,7 +123,7 @@ export class DiscordBot {
   }
 
   public ProcessMatrixMsgEvent(event, guildId: string, channelId: string): Promise<any> {
-    let chan;
+    let chan: Discord.TextChannel;
     let embed;
     let botUser;
     const mxClient = this.bridge.getClientFactory().getClientAs();
@@ -174,6 +174,7 @@ export class DiscordBot {
       if (botUser) {
         return chan.sendEmbed(embed, opts);
       }
+      const body = this.HandleMentions(event.content.body, chan.members.array());
       return chan.sendMessage(event.content.body, opts);
     }).then((msg) => {
       this.sentMessages.push(msg.id);
@@ -196,6 +197,13 @@ export class DiscordBot {
     return "matrix-media." + mime.extension(content.info.mimetype);
   }
 
+  private HandleMentions(body: string, members: Discord.GuildMember[]): string {
+    for (const member of members) {
+      body = body.replace(new RegExp(member.displayName, "g"), `<@!${member.id}>`);
+    }
+    return body;
+  }
+
   private GetRoomIdsFromChannel(channel: Discord.Channel): Promise<string[]> {
     return this.bridge.getRoomStore().getEntriesByRemoteRoomData({
       discord_channel: channel.id,
-- 
GitLab