@@ -21,6 +21,10 @@ import (
2121 "github.com/wdvxdr1123/ZeroBot/message"
2222)
2323
24+ var (
25+ longZhuURL = "https://www.hhlqilongzhu.cn/api/joox/juhe_music.php?msg=%v"
26+ )
27+
2428func init () {
2529 control .AutoRegister (& ctrl.Options [* zero.Ctx ]{
2630 DisableOnDefault : false ,
@@ -29,7 +33,8 @@ func init() {
2933 "- 网易点歌[xxx]\n " +
3034 "- 酷我点歌[xxx]\n " +
3135 "- 酷狗点歌[xxx]\n " +
32- "- 咪咕点歌[xxx]" ,
36+ "- 咪咕点歌[xxx]\n " +
37+ "- qq点歌[xxx]\n " ,
3338 }).OnRegex (`^(.{0,2})点歌\s?(.{1,25})$` ).SetBlock (true ).Limit (ctxext .LimitByUser ).
3439 Handle (func (ctx * zero.Ctx ) {
3540 // switch 平台
@@ -42,12 +47,37 @@ func init() {
4247 ctx .SendChain (kugou (ctx .State ["regex_matched" ].([]string )[2 ]))
4348 case "网易" :
4449 ctx .SendChain (cloud163 (ctx .State ["regex_matched" ].([]string )[2 ]))
45- default : // 默认 QQ音乐
50+ case "qq" :
4651 ctx .SendChain (qqmusic (ctx .State ["regex_matched" ].([]string )[2 ]))
52+ default : // 默认聚合点歌
53+ ctx .SendChain (longzhu (ctx .State ["regex_matched" ].([]string )[2 ]))
4754 }
4855 })
4956}
5057
58+ // longzhu 聚合平台
59+ func longzhu (keyword string ) message.Segment {
60+ data , _ := web .GetData (fmt .Sprintf (longZhuURL , url .QueryEscape (keyword )))
61+ // 假设 data 是包含整个 JSON 数组的字节切片
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+ results = gjson .GetBytes (data , "#.full_track" ).Array ()
72+ if len (results ) > 0 {
73+ if musicURL := results [0 ].String (); musicURL != "" {
74+ return message .Record (musicURL )
75+ }
76+ }
77+
78+ return message .Text ("点歌失败, 找不到 " , keyword , " 的相关结果" )
79+ }
80+
5181// migu 返回咪咕音乐卡片
5282func migu (keyword string ) message.Segment {
5383 headers := http.Header {
0 commit comments