fixed varname Textout. Changed fileextension logic to avoid chaining regex

This commit is contained in:
humorhenker
2021-02-18 09:16:16 +01:00
parent 594d7ace64
commit 4afe51f35d
2 changed files with 11 additions and 14 deletions

View File

@@ -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

View File

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