Bridge incoming reply embeds as replies
This commit is contained in:
@@ -217,7 +217,7 @@ func (portal *Portal) convertMessageBatch(log zerolog.Logger, source *User, mess
|
|||||||
puppet := portal.bridge.GetPuppetByID(msg.Author.ID)
|
puppet := portal.bridge.GetPuppetByID(msg.Author.ID)
|
||||||
puppet.UpdateInfo(source, msg.Author)
|
puppet.UpdateInfo(source, msg.Author)
|
||||||
intent := puppet.IntentFor(portal)
|
intent := puppet.IntentFor(portal)
|
||||||
replyTo := portal.getReplyTarget(source, msg.MessageReference, true)
|
replyTo := portal.getReplyTarget(source, "", msg.MessageReference, msg.Embeds, true)
|
||||||
|
|
||||||
ts, _ := discordgo.SnowflakeTimestamp(msg.ID)
|
ts, _ := discordgo.SnowflakeTimestamp(msg.ID)
|
||||||
log := log.With().
|
log := log.With().
|
||||||
|
|||||||
23
portal.go
23
portal.go
@@ -8,6 +8,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -637,7 +638,7 @@ func (portal *Portal) handleDiscordMessageCreate(user *User, msg *discordgo.Mess
|
|||||||
lastThreadEvent = lastInThread.MXID
|
lastThreadEvent = lastInThread.MXID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
replyTo := portal.getReplyTarget(user, msg.MessageReference, false)
|
replyTo := portal.getReplyTarget(user, discordThreadID, msg.MessageReference, msg.Embeds, false)
|
||||||
|
|
||||||
ts, _ := discordgo.SnowflakeTimestamp(msg.ID)
|
ts, _ := discordgo.SnowflakeTimestamp(msg.ID)
|
||||||
parts := portal.convertDiscordMessage(ctx, intent, msg)
|
parts := portal.convertDiscordMessage(ctx, intent, msg)
|
||||||
@@ -677,7 +678,23 @@ func (portal *Portal) handleDiscordMessageCreate(user *User, msg *discordgo.Mess
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) getReplyTarget(source *User, ref *discordgo.MessageReference, allowNonExistent bool) *event.InReplyTo {
|
var hackyReplyPattern = regexp.MustCompile(`^\*\*\[Replying to]\(https://discord.com/channels/(\d+)/(\d+)/(\d+)\)`)
|
||||||
|
|
||||||
|
func isReplyEmbed(embed *discordgo.MessageEmbed) bool {
|
||||||
|
return hackyReplyPattern.MatchString(embed.Description)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (portal *Portal) getReplyTarget(source *User, threadID string, ref *discordgo.MessageReference, embeds []*discordgo.MessageEmbed, allowNonExistent bool) *event.InReplyTo {
|
||||||
|
if ref == nil && len(embeds) > 0 {
|
||||||
|
match := hackyReplyPattern.FindStringSubmatch(embeds[0].Description)
|
||||||
|
if match != nil && match[1] == portal.GuildID && (match[2] == portal.Key.ChannelID || match[2] == threadID) {
|
||||||
|
ref = &discordgo.MessageReference{
|
||||||
|
MessageID: match[3],
|
||||||
|
ChannelID: match[2],
|
||||||
|
GuildID: match[1],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if ref == nil {
|
if ref == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -689,7 +706,7 @@ func (portal *Portal) getReplyTarget(source *User, ref *discordgo.MessageReferen
|
|||||||
crossRoomReplies := isHungry
|
crossRoomReplies := isHungry
|
||||||
|
|
||||||
targetPortal := portal
|
targetPortal := portal
|
||||||
if ref.ChannelID != portal.Key.ChannelID && crossRoomReplies {
|
if ref.ChannelID != portal.Key.ChannelID && ref.ChannelID != threadID && crossRoomReplies {
|
||||||
targetPortal = portal.bridge.GetExistingPortalByID(database.PortalKey{ChannelID: ref.ChannelID, Receiver: source.DiscordID})
|
targetPortal = portal.bridge.GetExistingPortalByID(database.PortalKey{ChannelID: ref.ChannelID, Receiver: source.DiscordID})
|
||||||
if targetPortal == nil {
|
if targetPortal == nil {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -542,6 +542,9 @@ func (portal *Portal) convertDiscordTextMessage(ctx context.Context, intent *app
|
|||||||
}
|
}
|
||||||
previews := make([]*BeeperLinkPreview, 0)
|
previews := make([]*BeeperLinkPreview, 0)
|
||||||
for i, embed := range msg.Embeds {
|
for i, embed := range msg.Embeds {
|
||||||
|
if i == 0 && msg.MessageReference == nil && isReplyEmbed(embed) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
with := log.With().
|
with := log.With().
|
||||||
Str("embed_type", string(embed.Type)).
|
Str("embed_type", string(embed.Type)).
|
||||||
Int("embed_index", i)
|
Int("embed_index", i)
|
||||||
|
|||||||
Reference in New Issue
Block a user