summaryrefslogtreecommitdiffstats
path: root/bridge
diff options
context:
space:
mode:
Diffstat (limited to 'bridge')
-rw-r--r--bridge/config/config.go5
-rw-r--r--bridge/discord/discord.go3
-rw-r--r--bridge/mattermost/mattermost.go4
-rw-r--r--bridge/slack/slack.go18
-rw-r--r--bridge/telegram/telegram.go28
5 files changed, 36 insertions, 22 deletions
diff --git a/bridge/config/config.go b/bridge/config/config.go
index 0dfba94b..b4124347 100644
--- a/bridge/config/config.go
+++ b/bridge/config/config.go
@@ -33,8 +33,9 @@ type Message struct {
}
type FileInfo struct {
- Name string
- Data *[]byte
+ Name string
+ Data *[]byte
+ Comment string
}
type ChannelInfo struct {
diff --git a/bridge/discord/discord.go b/bridge/discord/discord.go
index 12e0d827..183b1193 100644
--- a/bridge/discord/discord.go
+++ b/bridge/discord/discord.go
@@ -151,11 +151,12 @@ func (b *bdiscord) Send(msg config.Message) (string, error) {
fi := f.(config.FileInfo)
files := []*discordgo.File{}
files = append(files, &discordgo.File{fi.Name, "", bytes.NewReader(*fi.Data)})
- _, err = b.c.ChannelMessageSendComplex(channelID, &discordgo.MessageSend{Content: msg.Text, Files: files})
+ _, err = b.c.ChannelMessageSendComplex(channelID, &discordgo.MessageSend{Content: msg.Username + fi.Comment, Files: files})
if err != nil {
flog.Errorf("file upload failed: %#v", err)
}
}
+ return "", nil
}
}
diff --git a/bridge/mattermost/mattermost.go b/bridge/mattermost/mattermost.go
index 3274d81d..9d9990b2 100644
--- a/bridge/mattermost/mattermost.go
+++ b/bridge/mattermost/mattermost.go
@@ -190,9 +190,9 @@ func (b *Bmattermost) Send(msg config.Message) (string, error) {
flog.Debugf("ERROR %#v", err)
return "", err
}
- message = "uploaded a file: " + fi.Name
+ message = fi.Comment
if b.Config.PrefixMessagesWithNick {
- message = nick + "uploaded a file: " + fi.Name
+ message = nick + fi.Comment
}
res, err = b.mc.PostMessageWithFiles(b.mc.GetChannelId(channel, ""), message, []string{id})
}
diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go
index 74003753..b753c1a5 100644
--- a/bridge/slack/slack.go
+++ b/bridge/slack/slack.go
@@ -195,9 +195,10 @@ func (b *Bslack) Send(msg config.Message) (string, error) {
for _, f := range msg.Extra["file"] {
fi := f.(config.FileInfo)
_, err = b.sc.UploadFile(slack.FileUploadParameters{
- Reader: bytes.NewReader(*fi.Data),
- Filename: fi.Name,
- Channels: []string{schannel.ID},
+ Reader: bytes.NewReader(*fi.Data),
+ Filename: fi.Name,
+ Channels: []string{schannel.ID},
+ InitialComment: fi.Comment,
})
if err != nil {
flog.Errorf("uploadfile %#v", err)
@@ -294,16 +295,21 @@ func (b *Bslack) handleSlack() {
if message.Raw.File != nil {
// limit to 1MB for now
if message.Raw.File.Size <= 1000000 {
+ comment := ""
data, err := b.downloadFile(message.Raw.File.URLPrivateDownload)
if err != nil {
flog.Errorf("download %s failed %#v", message.Raw.File.URLPrivateDownload, err)
} else {
- msg.Extra["file"] = append(msg.Extra["file"], config.FileInfo{Name: message.Raw.File.Name, Data: data})
+ results := regexp.MustCompile(`.*?commented: (.*)`).FindAllStringSubmatch(msg.Text, -1)
+ if len(results) > 0 {
+ comment = results[0][1]
+ }
+ msg.Extra["file"] = append(msg.Extra["file"], config.FileInfo{Name: message.Raw.File.Name, Data: data, Comment: comment})
}
+ flog.Debugf("Message is %#v", msg)
+ b.Remote <- msg
}
}
- flog.Debugf("Message is %#v", msg)
- b.Remote <- msg
}
}
diff --git a/bridge/telegram/telegram.go b/bridge/telegram/telegram.go
index f4662669..5cd49253 100644
--- a/bridge/telegram/telegram.go
+++ b/bridge/telegram/telegram.go
@@ -114,20 +114,14 @@ func (b *Btelegram) Send(msg config.Message) (string, error) {
if err != nil {
log.Errorf("file upload failed: %#v", err)
}
+ if fi.Comment != "" {
+ b.sendMessage(chatid, msg.Username+fi.Comment)
+ }
}
+ return "", nil
}
}
-
- m := tgbotapi.NewMessage(chatid, msg.Username+msg.Text)
- if b.Config.MessageFormat == "HTML" {
- m.ParseMode = tgbotapi.ModeHTML
- }
- res, err := b.c.Send(m)
- if err != nil {
- return "", err
- }
- return strconv.Itoa(res.MessageID), nil
-
+ return b.sendMessage(chatid, msg.Username+msg.Text)
}
func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) {
@@ -275,3 +269,15 @@ func (b *Btelegram) handleDownload(file interface{}, msg *config.Message) {
}
}
}
+
+func (b *Btelegram) sendMessage(chatid int64, text string) (string, error) {
+ m := tgbotapi.NewMessage(chatid, text)
+ if b.Config.MessageFormat == "HTML" {
+ m.ParseMode = tgbotapi.ModeHTML
+ }
+ res, err := b.c.Send(m)
+ if err != nil {
+ return "", err
+ }
+ return strconv.Itoa(res.MessageID), nil
+}