mirror of
https://github.com/42wim/matterbridge.git
synced 2024-12-18 06:52:01 -08:00
parent
24f6747516
commit
3ffd96a350
@ -1,7 +1,10 @@
|
|||||||
package bdiscord
|
package bdiscord
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"path"
|
||||||
|
|
||||||
"github.com/42wim/matterbridge/bridge/config"
|
"github.com/42wim/matterbridge/bridge/config"
|
||||||
|
"github.com/42wim/matterbridge/bridge/helper"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
)
|
)
|
||||||
@ -98,14 +101,13 @@ func (b *Bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreat
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the url of the attachments to content
|
rmsg := config.Message{
|
||||||
if len(m.Attachments) > 0 {
|
Account: b.Account,
|
||||||
for _, attach := range m.Attachments {
|
Avatar: "https://cdn.discordapp.com/avatars/" + m.Author.ID + "/" + m.Author.Avatar + ".jpg",
|
||||||
m.Content = m.Content + "\n" + attach.URL
|
UserID: m.Author.ID,
|
||||||
|
ID: m.ID,
|
||||||
|
Extra: make(map[string][]interface{}),
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
b.Log.Debugf("== Receiving event %#v", m.Message)
|
||||||
|
|
||||||
@ -138,8 +140,14 @@ func (b *Bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// no empty messages
|
if len(m.Attachments) > 0 {
|
||||||
if rmsg.Text == "" {
|
b.handleDownloadFile(&rmsg, m)
|
||||||
|
}
|
||||||
|
|
||||||
|
hasAttachment := len(rmsg.Extra["file"]) > 0
|
||||||
|
|
||||||
|
// no empty messages unless has attachment
|
||||||
|
if rmsg.Text == "" && !hasAttachment {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,3 +287,14 @@ func handleEmbed(embed *discordgo.MessageEmbed) string {
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *Bdiscord) handleDownloadFile(rmsg *config.Message, m *discordgo.MessageCreate) {
|
||||||
|
for _, attach := range m.Attachments {
|
||||||
|
data, err := helper.DownloadFile(attach.URL)
|
||||||
|
if err != nil {
|
||||||
|
b.Log.Errorf("download %s failed %#v", attach.URL, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
helper.HandleDownloadData(b.Log, rmsg, path.Base(attach.URL), rmsg.Text, attach.URL, data, b.General)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user