Skip to content

Commit

Permalink
improve linktest
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoMengXinX committed Oct 31, 2022
1 parent f7a146e commit 5bdbad7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions bot/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var (
reg4 = regexp.MustCompile("&(.*)")
reg3 = regexp.MustCompile(`\?(.*)`)
regInt = regexp.MustCompile(`\d+`)
regUrl = regexp.MustCompile("(http|https)://[\\w\\-_]+(\\.[\\w\\-_]+)+([\\w\\-.,@?^=%&:/~+#]*[\\w\\-@?^=%&/~+#])?")
)

var mdV2Replacer = strings.NewReplacer(
Expand Down
3 changes: 2 additions & 1 deletion bot/processMusic.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ func processMusic(musicID int, message tgbotapi.Message, bot *tgbotapi.BotAPI) (
}

func sendMusic(songInfo SongInfo, musicPath, picPath string, message tgbotapi.Message, bot *tgbotapi.BotAPI) (audio tgbotapi.Message, err error) {

var numericKeyboard tgbotapi.InlineKeyboardMarkup
numericKeyboard = tgbotapi.NewInlineKeyboardMarkup(
tgbotapi.NewInlineKeyboardRow(
Expand All @@ -325,6 +324,8 @@ func sendMusic(songInfo SongInfo, musicPath, picPath string, message tgbotapi.Me
newAudio = tgbotapi.NewAudio(message.Chat.ID, tgbotapi.FileID(songInfo.FileID))
} else {
newAudio = tgbotapi.NewAudio(message.Chat.ID, tgbotapi.FilePath(musicPath))
status := tgbotapi.NewChatAction(message.Chat.ID, "upload_document")
_, _ = bot.Send(status)
}
newAudio.Caption = fmt.Sprintf(musicInfo, songInfo.SongName, songInfo.SongArtists, songInfo.SongAlbum, songInfo.FileExt, float64(songInfo.MusicSize+songInfo.EmbPicSize)/1024/1024, float64(songInfo.BitRate)/1000, botName)
newAudio.Title = fmt.Sprintf("%s", songInfo.SongName)
Expand Down
11 changes: 11 additions & 0 deletions bot/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/hex"
"fmt"
"io"
"net/url"
"os"
"sort"
"strconv"
Expand Down Expand Up @@ -76,6 +77,16 @@ func verifyMD5(filePath string, md5str string) (bool, error) {
func parseMusicID(text string) int {
var replacer = strings.NewReplacer("\n", "", " ", "")
messageText := replacer.Replace(text)
musicUrl := regUrl.FindStringSubmatch(messageText)
if len(musicUrl) != 0 {
if strings.Contains(musicUrl[0], "song") {
ur, _ := url.Parse(musicUrl[0])
id := ur.Query().Get("id")
if musicid, _ := strconv.Atoi(id); musicid != 0 {
return musicid
}
}
}
musicid, _ := strconv.Atoi(linkTestMusic(messageText))
return musicid
}
Expand Down

0 comments on commit 5bdbad7

Please sign in to comment.