Add slightly hacky support for interaction messages
This commit is contained in:
10
formatter.go
10
formatter.go
@@ -21,6 +21,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/bwmarrin/discordgo"
|
||||||
"github.com/yuin/goldmark"
|
"github.com/yuin/goldmark"
|
||||||
"github.com/yuin/goldmark/parser"
|
"github.com/yuin/goldmark/parser"
|
||||||
|
|
||||||
@@ -33,7 +34,14 @@ import (
|
|||||||
var discordExtensions = goldmark.WithExtensions(mdext.SimpleSpoiler, mdext.DiscordUnderline)
|
var discordExtensions = goldmark.WithExtensions(mdext.SimpleSpoiler, mdext.DiscordUnderline)
|
||||||
var escapeFixer = regexp.MustCompile(`\\(__[^_]|\*\*[^*])`)
|
var escapeFixer = regexp.MustCompile(`\\(__[^_]|\*\*[^*])`)
|
||||||
|
|
||||||
func (portal *Portal) renderDiscordMarkdown(text string) event.MessageEventContent {
|
const msgInteractionTemplate = `> <@%s> used /%s
|
||||||
|
|
||||||
|
`
|
||||||
|
|
||||||
|
func (portal *Portal) renderDiscordMarkdown(text string, interaction *discordgo.MessageInteraction) event.MessageEventContent {
|
||||||
|
if interaction != nil {
|
||||||
|
text = fmt.Sprintf(msgInteractionTemplate, interaction.User.ID, interaction.Name) + text
|
||||||
|
}
|
||||||
return format.HTMLToContent(portal.renderDiscordMarkdownOnlyHTML(text))
|
return format.HTMLToContent(portal.renderDiscordMarkdownOnlyHTML(text))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -976,8 +976,8 @@ func (portal *Portal) handleDiscordMessageCreate(user *User, msg *discordgo.Mess
|
|||||||
|
|
||||||
var parts []database.MessagePart
|
var parts []database.MessagePart
|
||||||
ts, _ := discordgo.SnowflakeTimestamp(msg.ID)
|
ts, _ := discordgo.SnowflakeTimestamp(msg.ID)
|
||||||
if msg.Content != "" && !isPlainGifMessage(msg) {
|
if (msg.Content != "" || msg.Interaction != nil) && !isPlainGifMessage(msg) {
|
||||||
content := portal.renderDiscordMarkdown(msg.Content)
|
content := portal.renderDiscordMarkdown(msg.Content, msg.Interaction)
|
||||||
content.RelatesTo = threadRelation.Copy()
|
content.RelatesTo = threadRelation.Copy()
|
||||||
|
|
||||||
extraContent := map[string]any{
|
extraContent := map[string]any{
|
||||||
@@ -1151,7 +1151,7 @@ func (portal *Portal) handleDiscordMessageUpdate(user *User, msg *discordgo.Mess
|
|||||||
deletedAttachment.Delete()
|
deletedAttachment.Delete()
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.Content == "" || existing[0].AttachmentID != "" {
|
if (msg.Content == "" && msg.Interaction == nil) || existing[0].AttachmentID != "" {
|
||||||
portal.log.Debugfln("Dropping non-text edit to %s (message on matrix: %t, text on discord: %t)", msg.ID, existing[0].AttachmentID == "", len(msg.Content) > 0)
|
portal.log.Debugfln("Dropping non-text edit to %s (message on matrix: %t, text on discord: %t)", msg.ID, existing[0].AttachmentID == "", len(msg.Content) > 0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -1162,7 +1162,7 @@ func (portal *Portal) handleDiscordMessageUpdate(user *User, msg *discordgo.Mess
|
|||||||
content = *converted.Content
|
content = *converted.Content
|
||||||
extraContent = converted.Extra
|
extraContent = converted.Extra
|
||||||
} else {
|
} else {
|
||||||
content = portal.renderDiscordMarkdown(msg.Content)
|
content = portal.renderDiscordMarkdown(msg.Content, msg.Interaction)
|
||||||
extraContent = map[string]any{
|
extraContent = map[string]any{
|
||||||
"com.beeper.linkpreviews": portal.convertDiscordLinkEmbedsToBeeper(intent, msg.Embeds),
|
"com.beeper.linkpreviews": portal.convertDiscordLinkEmbedsToBeeper(intent, msg.Embeds),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user