Add support to upload files to discord, from bridges with private urls like slack/mattermost/telegram. (discord)
This commit is contained in:
parent
4f8ae761a2
commit
d1e8ff814b
|
@ -1,6 +1,7 @@
|
||||||
package bdiscord
|
package bdiscord
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"github.com/42wim/matterbridge/bridge/config"
|
"github.com/42wim/matterbridge/bridge/config"
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
|
@ -141,6 +142,23 @@ func (b *bdiscord) Send(msg config.Message) (string, error) {
|
||||||
_, err := b.c.ChannelMessageEdit(channelID, msg.ID, msg.Username+msg.Text)
|
_, err := b.c.ChannelMessageEdit(channelID, msg.ID, msg.Username+msg.Text)
|
||||||
return msg.ID, err
|
return msg.ID, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if msg.Extra != nil {
|
||||||
|
// check if we have files to upload (from slack, telegram or mattermost)
|
||||||
|
if len(msg.Extra["file"]) > 0 {
|
||||||
|
for _, f := range msg.Extra["file"] {
|
||||||
|
fi := f.(config.FileInfo)
|
||||||
|
files := []*discordgo.File{}
|
||||||
|
files = append(files, &discordgo.File{fi.Name, "", bytes.NewReader(*fi.Data)})
|
||||||
|
res, err := b.c.ChannelMessageSendComplex(channelID, &discordgo.MessageSend{Content: msg.Text, Files: files})
|
||||||
|
if err != nil {
|
||||||
|
flog.Debugf("ERROR channelMessageSendComplex: %#v", err)
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return res.ID, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
res, err := b.c.ChannelMessageSend(channelID, msg.Username+msg.Text)
|
res, err := b.c.ChannelMessageSend(channelID, msg.Username+msg.Text)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|
Loading…
Reference in New Issue