mirror of
https://github.com/cwinfo/matterbridge.git
synced 2025-06-26 17:49:23 +00:00
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
|
||||
## 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/)
|
||||
|
||||
## Building
|
||||
|
@ -33,8 +33,9 @@ type Message struct {
|
||||
}
|
||||
|
||||
type FileInfo struct {
|
||||
Name string
|
||||
Data *[]byte
|
||||
Name string
|
||||
Data *[]byte
|
||||
Comment string
|
||||
}
|
||||
|
||||
type ChannelInfo struct {
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,12 +81,22 @@ func (b *Birc) Connect() error {
|
||||
if err != nil {
|
||||
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{
|
||||
Server: server,
|
||||
ServerPass: b.Config.Password,
|
||||
Port: port,
|
||||
Nick: b.Config.Nick,
|
||||
User: b.Config.Nick,
|
||||
User: user,
|
||||
Name: b.Config.Nick,
|
||||
SSL: b.Config.UseTLS,
|
||||
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)
|
||||
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})
|
||||
}
|
||||
|
@ -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,11 +295,16 @@ 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})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package btelegram
|
||||
import (
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/42wim/matterbridge/bridge/config"
|
||||
"github.com/42wim/matterbridge/bridge/helper"
|
||||
@ -113,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) {
|
||||
@ -178,12 +173,11 @@ func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) {
|
||||
if message.Video != nil {
|
||||
b.handleDownload(message.Video, &fmsg)
|
||||
}
|
||||
if message.Photo != nil && b.Config.UseInsecureURL {
|
||||
if message.Photo != nil {
|
||||
b.handleDownload(message.Photo, &fmsg)
|
||||
}
|
||||
if message.Document != nil && b.Config.UseInsecureURL {
|
||||
b.handleDownload(message.Sticker, &fmsg)
|
||||
text = text + " " + message.Document.FileName + " : " + b.getFileDirectURL(message.Document.FileID)
|
||||
if message.Document != nil {
|
||||
b.handleDownload(message.Document, &fmsg)
|
||||
}
|
||||
|
||||
// quote the previous message
|
||||
@ -208,7 +202,7 @@ func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) {
|
||||
|
||||
if text != "" || len(fmsg.Extra) > 0 {
|
||||
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)
|
||||
b.Remote <- msg
|
||||
}
|
||||
@ -228,28 +222,35 @@ func (b *Btelegram) handleDownload(file interface{}, msg *config.Message) {
|
||||
url := ""
|
||||
name := ""
|
||||
text := ""
|
||||
fileid := ""
|
||||
switch v := file.(type) {
|
||||
case *tgbotapi.Sticker:
|
||||
size = v.FileSize
|
||||
url = b.getFileDirectURL(v.FileID)
|
||||
name = "sticker"
|
||||
urlPart := strings.Split(url, "/")
|
||||
name = urlPart[len(urlPart)-1]
|
||||
text = " " + url
|
||||
fileid = v.FileID
|
||||
case *tgbotapi.Video:
|
||||
size = v.FileSize
|
||||
url = b.getFileDirectURL(v.FileID)
|
||||
name = "video"
|
||||
urlPart := strings.Split(url, "/")
|
||||
name = urlPart[len(urlPart)-1]
|
||||
text = " " + url
|
||||
fileid = v.FileID
|
||||
case *[]tgbotapi.PhotoSize:
|
||||
photos := *v
|
||||
size = photos[len(photos)-1].FileSize
|
||||
url = b.getFileDirectURL(photos[len(photos)-1].FileID)
|
||||
name = "photo"
|
||||
urlPart := strings.Split(url, "/")
|
||||
name = urlPart[len(urlPart)-1]
|
||||
text = " " + url
|
||||
case *tgbotapi.Document:
|
||||
size = v.FileSize
|
||||
url = b.getFileDirectURL(v.FileID)
|
||||
name = v.FileName
|
||||
text = " " + v.FileName + " : " + url
|
||||
fileid = v.FileID
|
||||
}
|
||||
if b.Config.UseInsecureURL {
|
||||
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
|
||||
// limit to 1MB for now
|
||||
flog.Debugf("trying to download %#v fileid %#v with size %#v", name, fileid, size)
|
||||
if size <= 1000000 {
|
||||
data, err := helper.DownloadFile(url)
|
||||
if err != nil {
|
||||
flog.Errorf("download %s failed %#v", url, err)
|
||||
} 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})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
## Breaking changes
|
||||
* 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.
|
||||
// we need to check if we can't use fallback or text in other bridges
|
||||
if msg.Extra != nil {
|
||||
if dest.Protocol != "slack" {
|
||||
if dest.Protocol != "discord" &&
|
||||
dest.Protocol != "slack" &&
|
||||
dest.Protocol != "mattermost" &&
|
||||
dest.Protocol != "telegram" {
|
||||
if msg.Text == "" {
|
||||
return brMsgIDs
|
||||
}
|
||||
@ -210,8 +213,8 @@ func (gw *Gateway) ignoreMessage(msg *config.Message) bool {
|
||||
return true
|
||||
}
|
||||
if msg.Text == "" {
|
||||
// we have an attachment
|
||||
if msg.Extra != nil && msg.Extra["attachments"] != nil {
|
||||
// we have an attachment or actual bytes
|
||||
if msg.Extra != nil && (msg.Extra["attachments"] != nil || len(msg.Extra["file"]) > 0) {
|
||||
return false
|
||||
}
|
||||
log.Debugf("ignoring empty message %#v from %s", msg, msg.Account)
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
version = "1.4.0"
|
||||
version = "1.4.1"
|
||||
githash string
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user