|
4 | 4 | "github.com/bwmarrin/discordgo" |
5 | 5 | "github.com/davecgh/go-spew/spew" |
6 | 6 | "github.com/matterbridge-org/matterbridge/bridge/config" |
| 7 | + "github.com/matterbridge-org/matterbridge/bridge/helper" |
7 | 8 | ) |
8 | 9 |
|
9 | 10 | func (b *Bdiscord) messageDelete(s *discordgo.Session, m *discordgo.MessageDelete) { //nolint:unparam |
@@ -98,15 +99,44 @@ func (b *Bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreat |
98 | 99 | return |
99 | 100 | } |
100 | 101 |
|
| 102 | + 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{})} |
| 103 | + |
101 | 104 | // add the url of the attachments to content |
102 | 105 | if len(m.Attachments) > 0 { |
| 106 | + first := true |
103 | 107 | for _, attach := range m.Attachments { |
104 | | - m.Content = m.Content + "\n" + attach.URL |
| 108 | + if b.alwaysDownloadFiles { |
| 109 | + var url, name, caption string |
| 110 | + |
| 111 | + url = attach.URL |
| 112 | + name = attach.Filename |
| 113 | + |
| 114 | + err := helper.HandleDownloadSize(b.Log, &rmsg, name, int64(attach.Size), b.General) |
| 115 | + if err != nil { |
| 116 | + return |
| 117 | + } |
| 118 | + data, err := helper.DownloadFile(url) |
| 119 | + if err != nil { |
| 120 | + return |
| 121 | + } |
| 122 | + |
| 123 | + if first { |
| 124 | + caption = m.Content |
| 125 | + if caption == "" { |
| 126 | + caption = name |
| 127 | + } |
| 128 | + first = false |
| 129 | + } else { |
| 130 | + caption = "" |
| 131 | + } |
| 132 | + |
| 133 | + helper.HandleDownloadData(b.Log, &rmsg, name, caption, "", data, b.General) |
| 134 | + } else { |
| 135 | + m.Content = m.Content + "\n" + attach.URL |
| 136 | + } |
105 | 137 | } |
106 | 138 | } |
107 | 139 |
|
108 | | - 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} |
109 | | - |
110 | 140 | b.Log.Debugf("== Receiving event %#v", m.Message) |
111 | 141 |
|
112 | 142 | if m.Content != "" { |
@@ -139,7 +169,7 @@ func (b *Bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreat |
139 | 169 | } |
140 | 170 |
|
141 | 171 | // no empty messages |
142 | | - if rmsg.Text == "" { |
| 172 | + if rmsg.Text == "" && len(m.Attachments) == 0 { |
143 | 173 | return |
144 | 174 | } |
145 | 175 |
|
|
0 commit comments