summaryrefslogtreecommitdiffstats
path: root/bridge
diff options
context:
space:
mode:
authorWim <wim@42.be>2017-11-03 00:05:10 +0100
committerWim <wim@42.be>2017-11-03 00:05:10 +0100
commitd1e8ff814b616d38ad778f8b85e38caf53c33552 (patch)
treef363ac38f4552bc01a791c24aae6448df22ac8b8 /bridge
parent4f8ae761a27302c7575ac0ef7ca1c45fe329e9a7 (diff)
downloadmatterbridge-msglm-d1e8ff814b616d38ad778f8b85e38caf53c33552.tar.gz
matterbridge-msglm-d1e8ff814b616d38ad778f8b85e38caf53c33552.tar.bz2
matterbridge-msglm-d1e8ff814b616d38ad778f8b85e38caf53c33552.zip
Add support to upload files to discord, from bridges with private urls like slack/mattermost/telegram. (discord)
Diffstat (limited to 'bridge')
-rw-r--r--bridge/discord/discord.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/bridge/discord/discord.go b/bridge/discord/discord.go
index d8320c76..c82844a4 100644
--- a/bridge/discord/discord.go
+++ b/bridge/discord/discord.go
@@ -1,6 +1,7 @@
package bdiscord
import (
+ "bytes"
"github.com/42wim/matterbridge/bridge/config"
log "github.com/Sirupsen/logrus"
"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)
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)
if err != nil {
return "", err