forked from lug/matterbridge
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
962062fe44 | ||
|
|
0578b21270 | ||
|
|
36a800c3f5 | ||
|
|
6d21f84187 | ||
|
|
f1e9833310 | ||
|
|
46f5acc4f9 | ||
|
|
95d4dcaeb3 | ||
|
|
64c542e614 | ||
|
|
13d081ea80 | ||
|
|
c0f9d86287 | ||
|
|
bcdecdaa73 |
@@ -54,7 +54,7 @@ See https://github.com/42wim/matterbridge/wiki
|
|||||||
|
|
||||||
# Installing
|
# Installing
|
||||||
## Binaries
|
## Binaries
|
||||||
* Latest stable release [v1.4.0](https://github.com/42wim/matterbridge/releases/latest)
|
* Latest stable release [v1.4.1](https://github.com/42wim/matterbridge/releases/latest)
|
||||||
* Development releases (follows master) can be downloaded [here](https://dl.bintray.com/42wim/nightly/)
|
* Development releases (follows master) can be downloaded [here](https://dl.bintray.com/42wim/nightly/)
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
|
|||||||
@@ -33,8 +33,9 @@ type Message struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type FileInfo struct {
|
type FileInfo struct {
|
||||||
Name string
|
Name string
|
||||||
Data *[]byte
|
Data *[]byte
|
||||||
|
Comment string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChannelInfo struct {
|
type ChannelInfo struct {
|
||||||
|
|||||||
@@ -151,11 +151,12 @@ func (b *bdiscord) Send(msg config.Message) (string, error) {
|
|||||||
fi := f.(config.FileInfo)
|
fi := f.(config.FileInfo)
|
||||||
files := []*discordgo.File{}
|
files := []*discordgo.File{}
|
||||||
files = append(files, &discordgo.File{fi.Name, "", bytes.NewReader(*fi.Data)})
|
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 {
|
if err != nil {
|
||||||
flog.Errorf("file upload failed: %#v", err)
|
flog.Errorf("file upload failed: %#v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return "", nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,12 +81,22 @@ func (b *Birc) Connect() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// fix strict user handling of girc
|
||||||
|
user := b.Config.Nick
|
||||||
|
for !girc.IsValidUser(user) {
|
||||||
|
if len(user) == 1 {
|
||||||
|
user = "matterbridge"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
user = user[1:]
|
||||||
|
}
|
||||||
|
|
||||||
i := girc.New(girc.Config{
|
i := girc.New(girc.Config{
|
||||||
Server: server,
|
Server: server,
|
||||||
ServerPass: b.Config.Password,
|
ServerPass: b.Config.Password,
|
||||||
Port: port,
|
Port: port,
|
||||||
Nick: b.Config.Nick,
|
Nick: b.Config.Nick,
|
||||||
User: b.Config.Nick,
|
User: user,
|
||||||
Name: b.Config.Nick,
|
Name: b.Config.Nick,
|
||||||
SSL: b.Config.UseTLS,
|
SSL: b.Config.UseTLS,
|
||||||
TLSConfig: &tls.Config{InsecureSkipVerify: b.Config.SkipTLSVerify, ServerName: server},
|
TLSConfig: &tls.Config{InsecureSkipVerify: b.Config.SkipTLSVerify, ServerName: server},
|
||||||
|
|||||||
@@ -190,9 +190,9 @@ func (b *Bmattermost) Send(msg config.Message) (string, error) {
|
|||||||
flog.Debugf("ERROR %#v", err)
|
flog.Debugf("ERROR %#v", err)
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
message = "uploaded a file: " + fi.Name
|
message = fi.Comment
|
||||||
if b.Config.PrefixMessagesWithNick {
|
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})
|
res, err = b.mc.PostMessageWithFiles(b.mc.GetChannelId(channel, ""), message, []string{id})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -195,9 +195,10 @@ func (b *Bslack) Send(msg config.Message) (string, error) {
|
|||||||
for _, f := range msg.Extra["file"] {
|
for _, f := range msg.Extra["file"] {
|
||||||
fi := f.(config.FileInfo)
|
fi := f.(config.FileInfo)
|
||||||
_, err = b.sc.UploadFile(slack.FileUploadParameters{
|
_, err = b.sc.UploadFile(slack.FileUploadParameters{
|
||||||
Reader: bytes.NewReader(*fi.Data),
|
Reader: bytes.NewReader(*fi.Data),
|
||||||
Filename: fi.Name,
|
Filename: fi.Name,
|
||||||
Channels: []string{schannel.ID},
|
Channels: []string{schannel.ID},
|
||||||
|
InitialComment: fi.Comment,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
flog.Errorf("uploadfile %#v", err)
|
flog.Errorf("uploadfile %#v", err)
|
||||||
@@ -294,11 +295,16 @@ func (b *Bslack) handleSlack() {
|
|||||||
if message.Raw.File != nil {
|
if message.Raw.File != nil {
|
||||||
// limit to 1MB for now
|
// limit to 1MB for now
|
||||||
if message.Raw.File.Size <= 1000000 {
|
if message.Raw.File.Size <= 1000000 {
|
||||||
|
comment := ""
|
||||||
data, err := b.downloadFile(message.Raw.File.URLPrivateDownload)
|
data, err := b.downloadFile(message.Raw.File.URLPrivateDownload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
flog.Errorf("download %s failed %#v", message.Raw.File.URLPrivateDownload, err)
|
flog.Errorf("download %s failed %#v", message.Raw.File.URLPrivateDownload, err)
|
||||||
} else {
|
} 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})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package btelegram
|
|||||||
import (
|
import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/42wim/matterbridge/bridge/config"
|
"github.com/42wim/matterbridge/bridge/config"
|
||||||
"github.com/42wim/matterbridge/bridge/helper"
|
"github.com/42wim/matterbridge/bridge/helper"
|
||||||
@@ -113,20 +114,14 @@ func (b *Btelegram) Send(msg config.Message) (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("file upload failed: %#v", err)
|
log.Errorf("file upload failed: %#v", err)
|
||||||
}
|
}
|
||||||
|
if fi.Comment != "" {
|
||||||
|
b.sendMessage(chatid, msg.Username+fi.Comment)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return "", nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return b.sendMessage(chatid, msg.Username+msg.Text)
|
||||||
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
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) {
|
func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) {
|
||||||
@@ -178,12 +173,11 @@ func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) {
|
|||||||
if message.Video != nil {
|
if message.Video != nil {
|
||||||
b.handleDownload(message.Video, &fmsg)
|
b.handleDownload(message.Video, &fmsg)
|
||||||
}
|
}
|
||||||
if message.Photo != nil && b.Config.UseInsecureURL {
|
if message.Photo != nil {
|
||||||
b.handleDownload(message.Photo, &fmsg)
|
b.handleDownload(message.Photo, &fmsg)
|
||||||
}
|
}
|
||||||
if message.Document != nil && b.Config.UseInsecureURL {
|
if message.Document != nil {
|
||||||
b.handleDownload(message.Sticker, &fmsg)
|
b.handleDownload(message.Document, &fmsg)
|
||||||
text = text + " " + message.Document.FileName + " : " + b.getFileDirectURL(message.Document.FileID)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// quote the previous message
|
// quote the previous message
|
||||||
@@ -208,7 +202,7 @@ func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) {
|
|||||||
|
|
||||||
if text != "" || len(fmsg.Extra) > 0 {
|
if text != "" || len(fmsg.Extra) > 0 {
|
||||||
flog.Debugf("Sending message from %s on %s to gateway", username, b.Account)
|
flog.Debugf("Sending message from %s on %s to gateway", username, b.Account)
|
||||||
msg := config.Message{Username: username, Text: text, Channel: channel, Account: b.Account, UserID: strconv.Itoa(message.From.ID), ID: strconv.Itoa(message.MessageID)}
|
msg := config.Message{Username: username, Text: text, Channel: channel, Account: b.Account, UserID: strconv.Itoa(message.From.ID), ID: strconv.Itoa(message.MessageID), Extra: fmsg.Extra}
|
||||||
flog.Debugf("Message is %#v", msg)
|
flog.Debugf("Message is %#v", msg)
|
||||||
b.Remote <- msg
|
b.Remote <- msg
|
||||||
}
|
}
|
||||||
@@ -228,28 +222,35 @@ func (b *Btelegram) handleDownload(file interface{}, msg *config.Message) {
|
|||||||
url := ""
|
url := ""
|
||||||
name := ""
|
name := ""
|
||||||
text := ""
|
text := ""
|
||||||
|
fileid := ""
|
||||||
switch v := file.(type) {
|
switch v := file.(type) {
|
||||||
case *tgbotapi.Sticker:
|
case *tgbotapi.Sticker:
|
||||||
size = v.FileSize
|
size = v.FileSize
|
||||||
url = b.getFileDirectURL(v.FileID)
|
url = b.getFileDirectURL(v.FileID)
|
||||||
name = "sticker"
|
urlPart := strings.Split(url, "/")
|
||||||
|
name = urlPart[len(urlPart)-1]
|
||||||
text = " " + url
|
text = " " + url
|
||||||
|
fileid = v.FileID
|
||||||
case *tgbotapi.Video:
|
case *tgbotapi.Video:
|
||||||
size = v.FileSize
|
size = v.FileSize
|
||||||
url = b.getFileDirectURL(v.FileID)
|
url = b.getFileDirectURL(v.FileID)
|
||||||
name = "video"
|
urlPart := strings.Split(url, "/")
|
||||||
|
name = urlPart[len(urlPart)-1]
|
||||||
text = " " + url
|
text = " " + url
|
||||||
|
fileid = v.FileID
|
||||||
case *[]tgbotapi.PhotoSize:
|
case *[]tgbotapi.PhotoSize:
|
||||||
photos := *v
|
photos := *v
|
||||||
size = photos[len(photos)-1].FileSize
|
size = photos[len(photos)-1].FileSize
|
||||||
url = b.getFileDirectURL(photos[len(photos)-1].FileID)
|
url = b.getFileDirectURL(photos[len(photos)-1].FileID)
|
||||||
name = "photo"
|
urlPart := strings.Split(url, "/")
|
||||||
|
name = urlPart[len(urlPart)-1]
|
||||||
text = " " + url
|
text = " " + url
|
||||||
case *tgbotapi.Document:
|
case *tgbotapi.Document:
|
||||||
size = v.FileSize
|
size = v.FileSize
|
||||||
url = b.getFileDirectURL(v.FileID)
|
url = b.getFileDirectURL(v.FileID)
|
||||||
name = v.FileName
|
name = v.FileName
|
||||||
text = " " + v.FileName + " : " + url
|
text = " " + v.FileName + " : " + url
|
||||||
|
fileid = v.FileID
|
||||||
}
|
}
|
||||||
if b.Config.UseInsecureURL {
|
if b.Config.UseInsecureURL {
|
||||||
msg.Text = text
|
msg.Text = text
|
||||||
@@ -257,12 +258,26 @@ func (b *Btelegram) handleDownload(file interface{}, msg *config.Message) {
|
|||||||
}
|
}
|
||||||
// if we have a file attached, download it (in memory) and put a pointer to it in msg.Extra
|
// if we have a file attached, download it (in memory) and put a pointer to it in msg.Extra
|
||||||
// limit to 1MB for now
|
// limit to 1MB for now
|
||||||
|
flog.Debugf("trying to download %#v fileid %#v with size %#v", name, fileid, size)
|
||||||
if size <= 1000000 {
|
if size <= 1000000 {
|
||||||
data, err := helper.DownloadFile(url)
|
data, err := helper.DownloadFile(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
flog.Errorf("download %s failed %#v", url, err)
|
flog.Errorf("download %s failed %#v", url, err)
|
||||||
} else {
|
} else {
|
||||||
|
flog.Debugf("download OK %#v %#v %#v", name, len(*data), len(url))
|
||||||
msg.Extra["file"] = append(msg.Extra["file"], config.FileInfo{Name: name, Data: data})
|
msg.Extra["file"] = append(msg.Extra["file"], config.FileInfo{Name: name, Data: data})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
# v1.4.1
|
||||||
|
## Bugfix
|
||||||
|
* telegram: fix issue with uploading for images/documents/stickers
|
||||||
|
* slack: remove double messages sent to other bridges when uploading files
|
||||||
|
* irc: Fix strict user handling of girc (irc). Closes #298
|
||||||
|
|
||||||
# v1.4.0
|
# v1.4.0
|
||||||
## Breaking changes
|
## Breaking changes
|
||||||
* general: `[general]` settings don't override the specific bridge settings
|
* general: `[general]` settings don't override the specific bridge settings
|
||||||
|
|||||||
@@ -152,7 +152,10 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
|
|||||||
// only slack now, check will have to be done in the different bridges.
|
// only slack now, check will have to be done in the different bridges.
|
||||||
// we need to check if we can't use fallback or text in other bridges
|
// we need to check if we can't use fallback or text in other bridges
|
||||||
if msg.Extra != nil {
|
if msg.Extra != nil {
|
||||||
if dest.Protocol != "slack" {
|
if dest.Protocol != "discord" &&
|
||||||
|
dest.Protocol != "slack" &&
|
||||||
|
dest.Protocol != "mattermost" &&
|
||||||
|
dest.Protocol != "telegram" {
|
||||||
if msg.Text == "" {
|
if msg.Text == "" {
|
||||||
return brMsgIDs
|
return brMsgIDs
|
||||||
}
|
}
|
||||||
@@ -210,8 +213,8 @@ func (gw *Gateway) ignoreMessage(msg *config.Message) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if msg.Text == "" {
|
if msg.Text == "" {
|
||||||
// we have an attachment
|
// we have an attachment or actual bytes
|
||||||
if msg.Extra != nil && msg.Extra["attachments"] != nil {
|
if msg.Extra != nil && (msg.Extra["attachments"] != nil || len(msg.Extra["file"]) > 0) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
log.Debugf("ignoring empty message %#v from %s", msg, msg.Account)
|
log.Debugf("ignoring empty message %#v from %s", msg, msg.Account)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
version = "1.4.0"
|
version = "1.4.1"
|
||||||
githash string
|
githash string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user