42wim / matterbridge

bridge between mattermost, IRC, gitter, xmpp, slack, discord, telegram, rocketchat, twitch, ssh-chat, zulip, whatsapp, keybase, matrix, microsoft teams, nextcloud, mumble, vk and more with REST API (mattermost not required!)
Apache License 2.0
6.43k stars 605 forks source link

Support (Discord) reply context in IRC #2132

Open PointMeAtTheDawn opened 2 months ago

PointMeAtTheDawn commented 2 months ago

Is your feature request related to a problem? Please describe. Discord replies have no context in IRC (even that they ARE a reply), leading to confusion.

Describe the solution you'd like Discord replies -> IRC should include some level of context: that it's a reply at all, reply to a particular user, reply to a message at a particular timestamp, or the beginning of the parent message.

Additional context Quick and dirty pseudocode if there's interest in merging a tested PR: In https://github.com/42wim/matterbridge/blob/master/bridge/discord/handlers.go#L85 In

    // Add our parent id if it exists, and if it's not referring to a message in another channel
    if ref := m.MessageReference; ref != nil && ref.ChannelID == m.ChannelID {
        rmsg.ParentID = ref.MessageID
    }

(MessageReference is just an id, ReferencedMessage has the actual content)

I would do something along the lines of this (but better typed :p)

DESIRED_SNIPPET_LENGTH := 25
DISCORD_PARENT_CONTENT := "discord_parent_content"
    // Add our parent id if it exists, and if it's not referring to a message in another channel.
        // Also, include a snippet of the parent to let bridges include it when the id is unusable.
    if ref := m.MessageReference; ref != nil && ref.ChannelID == m.ChannelID {
        rmsg.ParentID = ref.MessageID
                // Proper null safety here for best practice

                rmsg.Extra[DISCORD_PARENT_CONTENT] = ref.ReferencedMessage.content[:DESIRED_SNIPPET_LENGTH-1]
    }

Then in IRC https://github.com/42wim/matterbridge/blob/master/bridge/irc/irc.go#L140

if msg.Extra[DISCORD_PARENT_CONTENT] != "" (or w.e) {
    msg.Text = msg.Extra[DISCORD_PARENT_CONTENT].prettyFormatOrWhatever() + msg.Text
}
thechantaro commented 1 month ago

Yes please, would be perfect if they looked just like telegram!