From 763bb95ceadde6aa51ee72ff8a40407909823024 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 17 Feb 2021 21:30:06 +0100 Subject: [PATCH 1/6] Fix webhooks for channels with special characters (xmpp) (#1405) --- bridge/xmpp/xmpp.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bridge/xmpp/xmpp.go b/bridge/xmpp/xmpp.go index b471326b..89a48742 100644 --- a/bridge/xmpp/xmpp.go +++ b/bridge/xmpp/xmpp.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "net/http" + "net/url" "strings" "sync" "time" @@ -157,7 +158,7 @@ func (b *Bxmpp) postSlackCompatibleWebhook(msg config.Message) error { return err } - resp, err := http.Post(b.GetString("WebhookURL")+"/"+msg.Channel, "application/json", bytes.NewReader(webhookBody)) + resp, err := http.Post(b.GetString("WebhookURL")+"/"+url.QueryEscape(msg.Channel), "application/json", bytes.NewReader(webhookBody)) if err != nil { b.Log.Errorf("Failed to POST webhook: %s", err) return err From 4e11e29f706a1ddcc7a0e6a017d3e084f7fa17ea Mon Sep 17 00:00:00 2001 From: Wim Date: Wed, 17 Feb 2021 21:37:14 +0100 Subject: [PATCH 2/6] Use go1.16 as binary builder. Remove go1.14 (#1407) --- .github/workflows/development.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/development.yml b/.github/workflows/development.yml index 958d9b99..c9e45fc1 100644 --- a/.github/workflows/development.yml +++ b/.github/workflows/development.yml @@ -16,7 +16,7 @@ jobs: test-build-upload: strategy: matrix: - go-version: [1.14.x, 1.15.x, 1.16.x] + go-version: [1.15.x, 1.16.x] platform: [ubuntu-latest] runs-on: ${{ matrix.platform }} steps: @@ -35,23 +35,23 @@ jobs: run: | mkdir -p output/{win,lin,arm,mac} VERSION=$(git describe --tags) - GOOS=linux GOARCH=amd64 go build -mod=vendor -ldflags "-s -X main.githash=$(git log --pretty=format:'%h' -n 1)" -o output/lin/matterbridge-$VERSION-linux-amd64 - GOOS=windows GOARCH=amd64 go build -mod=vendor -ldflags "-s -X main.githash=$(git log --pretty=format:'%h' -n 1)" -o output/win/matterbridge-$VERSION-windows-amd64.exe - GOOS=darwin GOARCH=amd64 go build -mod=vendor -ldflags "-s -X main.githash=$(git log --pretty=format:'%h' -n 1)" -o output/mac/matterbridge-$VERSION-darwin-amd64 + GOOS=linux GOARCH=amd64 go build -ldflags "-s -X main.githash=$(git log --pretty=format:'%h' -n 1)" -o output/lin/matterbridge-$VERSION-linux-amd64 + GOOS=windows GOARCH=amd64 go build -ldflags "-s -X main.githash=$(git log --pretty=format:'%h' -n 1)" -o output/win/matterbridge-$VERSION-windows-amd64.exe + GOOS=darwin GOARCH=amd64 go build -ldflags "-s -X main.githash=$(git log --pretty=format:'%h' -n 1)" -o output/mac/matterbridge-$VERSION-darwin-amd64 - name: Upload linux 64-bit - if: startsWith(matrix.go-version,'1.15') + if: startsWith(matrix.go-version,'1.16') uses: actions/upload-artifact@v2 with: name: matterbridge-linux-64bit path: output/lin - name: Upload windows 64-bit - if: startsWith(matrix.go-version,'1.15') + if: startsWith(matrix.go-version,'1.16') uses: actions/upload-artifact@v2 with: name: matterbridge-windows-64bit path: output/win - name: Upload darwin 64-bit - if: startsWith(matrix.go-version,'1.15') + if: startsWith(matrix.go-version,'1.16') uses: actions/upload-artifact@v2 with: name: matterbridge-darwin-64bit From 4afe51f35d247acf428d112b678023410062cf7e Mon Sep 17 00:00:00 2001 From: humorhenker Date: Thu, 18 Feb 2021 09:16:16 +0100 Subject: [PATCH 3/6] fixed varname Textout. Changed fileextension logic to avoid chaining regex --- bridge/telegram/handlers.go | 17 +++++++---------- bridge/telegram/telegram.go | 8 ++++---- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/bridge/telegram/handlers.go b/bridge/telegram/handlers.go index 3ca6779f..34aa0b50 100644 --- a/bridge/telegram/handlers.go +++ b/bridge/telegram/handlers.go @@ -2,10 +2,10 @@ package btelegram import ( "html" - "regexp" "strconv" "strings" "unicode/utf16" + "path/filepath" "github.com/42wim/matterbridge/bridge/config" "github.com/42wim/matterbridge/bridge/helper" @@ -389,27 +389,24 @@ func (b *Btelegram) handleUploadFile(msg *config.Message, chatid int64) string { Name: fi.Name, Bytes: *fi.Data, } - reimg := regexp.MustCompile(".(jpg|jpe|png)$") - revideo := regexp.MustCompile(".(mp4|m4v)$") - reaudio := regexp.MustCompile(".(mp3|oga)$") - revoice := regexp.MustCompile(".(ogg)$") - if reimg.MatchString(fi.Name) { + switch filepath.Ext(fi.Name) { + case ".jpg", ".jpe", ".png": pc := tgbotapi.NewPhotoUpload(chatid, file) pc.Caption, pc.ParseMode = TGGetParseMode(b, msg.Username, fi.Comment) c = pc - } else if revideo.MatchString(fi.Name) { + case ".mp4", ".m4v": vc := tgbotapi.NewVideoUpload(chatid, file) vc.Caption, vc.ParseMode = TGGetParseMode(b, msg.Username, fi.Comment) c = vc - } else if reaudio.MatchString(fi.Name) { + case ".mp3", ".oga": ac := tgbotapi.NewAudioUpload(chatid, file) ac.Caption, ac.ParseMode = TGGetParseMode(b, msg.Username, fi.Comment) c = ac - } else if revoice.MatchString(fi.Name) { + case ".ogg": voc := tgbotapi.NewVoiceUpload(chatid, file) voc.Caption, voc.ParseMode = TGGetParseMode(b, msg.Username, fi.Comment) c = voc - } else { + default: dc := tgbotapi.NewDocumentUpload(chatid, file) dc.Caption, dc.ParseMode = TGGetParseMode(b, msg.Username, fi.Comment) c = dc diff --git a/bridge/telegram/telegram.go b/bridge/telegram/telegram.go index f7a1e86c..66c47c88 100644 --- a/bridge/telegram/telegram.go +++ b/bridge/telegram/telegram.go @@ -69,8 +69,8 @@ func (b *Btelegram) JoinChannel(channel config.ChannelInfo) error { return nil } -func TGGetParseMode(b *Btelegram, username string, text string) (TextOut string, ParseMode string) { - TextOut = username + text +func TGGetParseMode(b *Btelegram, username string, text string) (Textout string, ParseMode string) { + Textout = username + text if b.GetString("MessageFormat") == HTMLFormat { b.Log.Debug("Using mode HTML") ParseMode = tgbotapi.ModeHTML @@ -85,10 +85,10 @@ func TGGetParseMode(b *Btelegram, username string, text string) (TextOut string, } if strings.ToLower(b.GetString("MessageFormat")) == HTMLNick { b.Log.Debug("Using mode HTML - nick only") - TextOut = username + html.EscapeString(text) + Textout = username + html.EscapeString(text) ParseMode = tgbotapi.ModeHTML } - return TextOut, ParseMode + return Textout, ParseMode } func (b *Btelegram) Send(msg config.Message) (string, error) { From 0ecef4285cc0e7b50c849c9ef5d3580c9d02cb66 Mon Sep 17 00:00:00 2001 From: humorhenker Date: Thu, 18 Feb 2021 09:17:36 +0100 Subject: [PATCH 4/6] fixed textout varname --- bridge/telegram/telegram.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bridge/telegram/telegram.go b/bridge/telegram/telegram.go index 66c47c88..49befe97 100644 --- a/bridge/telegram/telegram.go +++ b/bridge/telegram/telegram.go @@ -69,8 +69,8 @@ func (b *Btelegram) JoinChannel(channel config.ChannelInfo) error { return nil } -func TGGetParseMode(b *Btelegram, username string, text string) (Textout string, ParseMode string) { - Textout = username + text +func TGGetParseMode(b *Btelegram, username string, text string) (textout string, ParseMode string) { + textout = username + text if b.GetString("MessageFormat") == HTMLFormat { b.Log.Debug("Using mode HTML") ParseMode = tgbotapi.ModeHTML @@ -85,10 +85,10 @@ func TGGetParseMode(b *Btelegram, username string, text string) (Textout string, } if strings.ToLower(b.GetString("MessageFormat")) == HTMLNick { b.Log.Debug("Using mode HTML - nick only") - Textout = username + html.EscapeString(text) + textout = username + html.EscapeString(text) ParseMode = tgbotapi.ModeHTML } - return Textout, ParseMode + return textout, ParseMode } func (b *Btelegram) Send(msg config.Message) (string, error) { From d6912b7007e2265d8cbeffd7a33c8b56f3af0e7b Mon Sep 17 00:00:00 2001 From: humorhenker Date: Thu, 18 Feb 2021 09:18:54 +0100 Subject: [PATCH 5/6] fixed parsemode varname --- bridge/telegram/telegram.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bridge/telegram/telegram.go b/bridge/telegram/telegram.go index 49befe97..6f2fcc80 100644 --- a/bridge/telegram/telegram.go +++ b/bridge/telegram/telegram.go @@ -69,26 +69,26 @@ func (b *Btelegram) JoinChannel(channel config.ChannelInfo) error { return nil } -func TGGetParseMode(b *Btelegram, username string, text string) (textout string, ParseMode string) { +func TGGetParseMode(b *Btelegram, username string, text string) (textout string, parsemode string) { textout = username + text if b.GetString("MessageFormat") == HTMLFormat { b.Log.Debug("Using mode HTML") - ParseMode = tgbotapi.ModeHTML + parsemode = tgbotapi.ModeHTML } if b.GetString("MessageFormat") == "Markdown" { b.Log.Debug("Using mode markdown") - ParseMode = tgbotapi.ModeMarkdown + parsemode = tgbotapi.ModeMarkdown } if b.GetString("MessageFormat") == MarkdownV2 { b.Log.Debug("Using mode MarkdownV2") - ParseMode = MarkdownV2 + parsemode = MarkdownV2 } if strings.ToLower(b.GetString("MessageFormat")) == HTMLNick { b.Log.Debug("Using mode HTML - nick only") textout = username + html.EscapeString(text) - ParseMode = tgbotapi.ModeHTML + parsemode = tgbotapi.ModeHTML } - return textout, ParseMode + return textout, parsemode } func (b *Btelegram) Send(msg config.Message) (string, error) { From 5bfa59059b56ac51374f451fc036ec550825ff6e Mon Sep 17 00:00:00 2001 From: humorhenker Date: Thu, 18 Feb 2021 09:23:38 +0100 Subject: [PATCH 6/6] gofmt --- bridge/telegram/handlers.go | 2 +- bridge/telegram/telegram.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bridge/telegram/handlers.go b/bridge/telegram/handlers.go index 34aa0b50..3084dc0e 100644 --- a/bridge/telegram/handlers.go +++ b/bridge/telegram/handlers.go @@ -2,10 +2,10 @@ package btelegram import ( "html" + "path/filepath" "strconv" "strings" "unicode/utf16" - "path/filepath" "github.com/42wim/matterbridge/bridge/config" "github.com/42wim/matterbridge/bridge/helper" diff --git a/bridge/telegram/telegram.go b/bridge/telegram/telegram.go index 6f2fcc80..0f08a45b 100644 --- a/bridge/telegram/telegram.go +++ b/bridge/telegram/telegram.go @@ -89,7 +89,7 @@ func TGGetParseMode(b *Btelegram, username string, text string) (textout string, parsemode = tgbotapi.ModeHTML } return textout, parsemode -} +} func (b *Btelegram) Send(msg config.Message) (string, error) { b.Log.Debugf("=> Receiving %#v", msg)