Skip to content

Commit ca596c1

Browse files
committed
🎨 优化聚合搜索
1 parent 2ad3da7 commit ca596c1

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

plugin/music/selecter.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,22 @@ func init() {
5959
func longzhu(keyword string) message.Segment {
6060
data, _ := web.GetData(fmt.Sprintf(longZhuURL, url.QueryEscape(keyword)))
6161
// 假设 data 是包含整个 JSON 数组的字节切片
62-
result := gjson.GetBytes(data, "#.full_track")
63-
// 取第一个非空的 full_track 链接
64-
firstFullTrack := result.Array()[0].String()
65-
return message.Record(firstFullTrack)
62+
results := gjson.ParseBytes(data).Array()
63+
for _, result := range results {
64+
if strings.Contains(strings.ToLower(result.Get("title").String()), strings.ToLower(keyword)) {
65+
if musicURL := result.Get("full_track").String(); musicURL != "" {
66+
return message.Record(musicURL)
67+
}
68+
}
69+
}
70+
71+
if len(results) > 0 {
72+
if musicURL := results[0].Get("full_track").String(); musicURL != "" {
73+
return message.Record(musicURL)
74+
}
75+
}
76+
77+
return message.Text("点歌失败, 找不到 ", keyword, " 的相关结果")
6678
}
6779

6880
// migu 返回咪咕音乐卡片

0 commit comments

Comments
 (0)