matterbridge icon indicating copy to clipboard operation
matterbridge copied to clipboard

Optimising Bridged Replies on Discord

Open glasgowm148 opened this issue 2 years ago • 1 comments

Is your feature request related to a problem? Please describe.

Discord does not support webhooks replying to messages, and doesn't look keen to implement it either. The current method makes chats look cluttered and ugly and can be improved in other ways.

Describe the solution you'd like

Screenshot 2023-03-30 at 13 02 12

created with the Embed builder found here

Describe alternatives you've considered

My current format, which looks okay - but if the reply is from a few days ago, impossible for the user on Discord to locate the message unless they search.

# The format of the OUTGOING message. (How it will display on Discord)
QuoteFormat = """
> (re @{QUOTENICK} : *{QUOTEMESSAGE}*)

{MESSAGE}
"""
# Length to trim the quote at
QuoteLengthLimit=46

Screenshot 2023-03-30 at 13 24 55

Additional context

I've never touched Go before, but feeding some docs and code in GPT it spat out this which may help as a starting point.

discord.go

// Check if the message has a valid ParentID
if msg.ParentID != "" {
  // Set the message reference to the parent message
  m.Reference = &discordgo.MessageReference{
	  MessageID: msg.ParentID,
	  ChannelID: channelID,
	  GuildID:   b.guildID,
  }
  
  // Fetch the content of the parent message using ParentID
  parentMessage, err := b.c.ChannelMessage(channelID, msg.ParentID)
  if err != nil {
	  // Handle the error if the message couldn't be fetched
	  b.Log.Errorf("Could not fetch the parent message with ID %s: %v", msg.ParentID, err)
  } else {
	  // Truncate ParentText to the first 20 characters
	  truncatedParentText := parentMessage.Content
	  if len(truncatedParentText) > 20 {
		  truncatedParentText = truncatedParentText[:20] + "..."
	  }
  
	  // Create a button component using the discordgo Button struct
	  button := discordgo.Button{
		  Label:    fmt.Sprintf("⤴️ in response to: \"%s\"", truncatedParentText),
		  Style:    discordgo.LinkButton,
		  Disabled: false,
		  URL:      fmt.Sprintf("https://discord.com/channels/%s/%s/%s", b.guildID, channelID, msg.ParentID),
	  }
  
	  // Create an ActionsRow component and add the button component to it
	  actionRow := discordgo.ActionsRow{
		  Components: []discordgo.MessageComponent{button},
	  }
  
	  // Set the components of the message as an array containing the ActionsRow component
	  m.Components = []discordgo.MessageComponent{actionRow}
  }
}

glasgowm148 avatar Mar 30 '23 12:03 glasgowm148

yes please, this is one of the large pain points on a discord > TG bridge is the replies not being associated and hard to track

lordkitsuna avatar Jul 01 '23 19:07 lordkitsuna