mautrix / discord

A Matrix-Discord puppeting bridge
https://go.mau.fi/mautrix-discord
GNU Affero General Public License v3.0
253 stars 21 forks source link

Convert discord mentions to matrix mentions #21

Closed Kitanit closed 1 year ago

Kitanit commented 2 years ago

situation: logged into my account discord, logged into the channel on the server and there I was mentioned, will be as a mention of the account and not me personally in matrix

sumnerevans commented 2 years ago

Not really sure what the issue is here... do you mean you got notified for a message that you did not expect to be mentioned in? In that case, you may have been notified due to your display name appearing in the message. There is a setting in element to disable this behavior.

Kitanit commented 2 years ago

Not really sure what the issue is here... do you mean you got notified for a message that you did not expect to be mentioned in? In that case, you may have been notified due to your display name appearing in the message. There is a setting in element to disable this behavior.

No, I mean that I logged into my discord account example#1234 example#1234 was mentioned in the chat but in the matrix it looks like a mention of example#1234 and not kitanit

*at least that's what the mau telegram can do, when mentioning my telegram account it mentions matrix

0xDEADCADE commented 2 years ago

I am not a go dev. This is pretty shitty code. But in case you're using a self-hosted instance, and are the only user of that instance, you should be able to make this work as a temporary solution.

EDIT: Messed up the code, as I said, not a go dev. This version does actually work.

Replace PUPPETMXID with the Matrix ID of your discord account puppet equivalent. Send a message from Discord in any bridged channel, and copy the Matrix ID of your Discord account (Looks like @discord(DISCORD ID):example.com)

formatter_tag.go
@@ -260,7 +260,11 @@
        switch node := n.(type) {
        case *astDiscordUserMention:
                puppet := r.portal.bridge.GetPuppetByID(strconv.FormatInt(node.id, 10))
-               _, _ = fmt.Fprintf(w, `<a href="https://matrix.to/#/%s">%s</a>`, puppet.MXID, puppet.Name)
+              if puppet.MXID == "PUPPET_MXID" {
+                       _, _ = fmt.Fprintf(w, `<a href="https://matrix.to/#/%s">%s</a>`, "MATRIX_ID", "MATRIX_NAME")
+               } else {
+                       _, _ = fmt.Fprintf(w, `<a href="https://matrix.to/#/%s">%s</a>`, puppet.MXID, puppet.Name)
+               }
                return
        case *astDiscordRoleMention:
                role := r.portal.bridge.DB.Role.GetByID(r.portal.GuildID, strconv.FormatInt(node.id, 10))