From ac2f7da59d79ea5b03414e3f4289417668ca6bb4 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Fri, 16 Aug 2024 08:59:32 +0100 Subject: [PATCH] discord: put attachment URLs into Extra["file"] previously, the urls were just appended to the message content. i couldn't find any other assignments directly to Extra["file"] anywhere in the codebase, so maybe there's a better way to do this. --- bridge/discord/handlers.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bridge/discord/handlers.go b/bridge/discord/handlers.go index 34cef554..851698f1 100644 --- a/bridge/discord/handlers.go +++ b/bridge/discord/handlers.go @@ -98,15 +98,19 @@ func (b *Bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreat return } + + rmsg := config.Message{Account: b.Account, Avatar: "https://cdn.discordapp.com/avatars/" + m.Author.ID + "/" + m.Author.Avatar + ".jpg", UserID: m.Author.ID, ID: m.ID, Extra: make(map[string][]interface{}, 0)} + // add the url of the attachments to content if len(m.Attachments) > 0 { for _, attach := range m.Attachments { - m.Content = m.Content + "\n" + attach.URL + rmsg.Extra["file"] = append(rmsg.Extra["file"], config.FileInfo { + URL: attach.URL, + }) + // m.Content = m.Content + "\n" + attach.URL } } - rmsg := config.Message{Account: b.Account, Avatar: "https://cdn.discordapp.com/avatars/" + m.Author.ID + "/" + m.Author.Avatar + ".jpg", UserID: m.Author.ID, ID: m.ID} - b.Log.Debugf("== Receiving event %#v", m.Message) if m.Content != "" { @@ -139,7 +143,7 @@ func (b *Bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreat } // no empty messages - if rmsg.Text == "" { + if rmsg.Text == "" && len(rmsg.Extra["file"]) == 0 { return }