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) {