Skip to content

Commit 5a08700

Browse files
authored
🐛 疫情查询、网易点歌、qq点歌问题 (#220)
* 🐛 修复网易点歌,qq点歌问题 * 🚨 错误输出 * 🚨 错误输出
1 parent 6b56d66 commit 5a08700

6 files changed

Lines changed: 41 additions & 144 deletions

File tree

plugin/epidemic/epidemic.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ type epidemic struct {
3434
type area struct {
3535
Name string `json:"name"`
3636
Today struct {
37-
Confirm int `json:"confirm"`
38-
Wzzadd int `json:"wzz_add"`
37+
Confirm int `json:"confirm"`
38+
Wzzadd interface{} `json:"wzz_add"`
3939
} `json:"today"`
4040
Total struct {
4141
NowConfirm int `json:"nowConfirm"`

plugin/music/selecter.go

Lines changed: 18 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"crypto/md5"
66
"encoding/hex"
77
"fmt"
8+
"github.com/FloatTech/zbputils/web"
89
"io"
910
"net/http"
1011
"net/url"
@@ -134,72 +135,28 @@ func kugou(keyword string) message.MessageSegment {
134135
}
135136

136137
// cloud163 返回网易云音乐卡片
137-
func cloud163(keyword string) message.MessageSegment {
138-
headers := http.Header{
139-
"Content-Type": []string{"application/x-www-form-urlencoded"},
140-
"User-Agent": []string{"Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0"},
141-
}
142-
data := url.Values{
143-
"keywords": []string{keyword},
138+
func cloud163(keyword string) (msg message.MessageSegment) {
139+
requestURL := "https://autumnfish.cn/search?keywords=" + url.QueryEscape(keyword)
140+
data, err := web.GetData(requestURL)
141+
if err != nil {
142+
msg = message.Text("ERROR:", err)
143+
return
144144
}
145-
// 通过API 搜索音乐信息 第一首
146-
// 返回音乐卡片
147-
return message.Music("163", gjson.ParseBytes(netPost("https://nemapi.windis.xyz/search", data, headers)).Get("result.songs.0.id").Int())
145+
msg = message.Music("163", gjson.ParseBytes(data).Get("result.songs.0.id").Int())
146+
return
148147
}
149148

150149
// qqmusic 返回QQ音乐卡片
151-
func qqmusic(keyword string) message.MessageSegment {
152-
// 搜索音乐信息 第一首歌
153-
h1 := http.Header{
154-
"User-Agent": []string{"Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0"},
155-
}
156-
search, _ := url.Parse("https://c.y.qq.com/soso/fcgi-bin/client_search_cp")
157-
search.RawQuery = url.Values{
158-
"w": []string{keyword},
159-
}.Encode()
160-
res := netGet(search.String(), h1)
161-
info := gjson.ParseBytes(res[9 : len(res)-1]).Get("data.song.list.0")
162-
// 获得音乐直链
163-
h2 := http.Header{
164-
"User-Agent": []string{"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1"},
165-
"referer": []string{"http://y.qq.com"},
166-
}
167-
music, _ := url.Parse("https://u.y.qq.com/cgi-bin/musicu.fcg")
168-
music.RawQuery = url.Values{
169-
"data": []string{`{"req": {"module": "CDN.SrfCdnDispatchServer", "method": "GetCdnDispatch", "param": {"guid": "3982823384", "calltype": 0, "userip": ""}}, "req_0": {"module": "vkey.GetVkeyServer", "method": "CgiGetVkey", "param": {"guid": "3982823384", "songmid": ["` + info.Get("songmid").Str + `"], "songtype": [0], "uin": "0", "loginflag": 1, "platform": "20"}}, "comm": {"uin": 0, "format": "json", "ct": 24, "cv": 0}}`},
170-
}.Encode()
171-
audio := gjson.ParseBytes(netGet(music.String(), h2))
172-
// 获得音乐封面
173-
image := "https://y.gtimg.cn/music/photo_new/" +
174-
find(
175-
`photo_new\u002F`,
176-
"?max_age",
177-
string(
178-
netGet("https://y.qq.com/n/yqq/song/"+info.Get("songmid").Str+".html", nil),
179-
),
180-
)
181-
// 返回音乐卡片
182-
return message.CustomMusic(
183-
"https://y.qq.com/n/yqq/song/"+info.Get("songmid").Str+".html",
184-
"https://isure.stream.qqmusic.qq.com/"+audio.Get("req_0.data.midurlinfo.0.purl").Str,
185-
info.Get("songname").Str,
186-
).Add("content", info.Get("singer.0.name").Str).Add("image", image)
187-
}
188-
189-
// find 返回 pre 到 suf 之间的文本
190-
func find(pre string, suf string, str string) string {
191-
n := strings.Index(str, pre)
192-
if n == -1 {
193-
n = 0
194-
} else {
195-
n += len(pre)
196-
}
197-
str = str[n:]
198-
m := strings.Index(str, suf)
199-
if m == -1 {
200-
m = len(str)
150+
func qqmusic(keyword string) (msg message.MessageSegment) {
151+
requestURL := "https://c.y.qq.com/soso/fcgi-bin/client_search_cp?w=" + url.QueryEscape(keyword)
152+
data, err := web.RequestDataWith(web.NewDefaultClient(), requestURL, "GET", "", web.RandUA())
153+
if err != nil {
154+
msg = message.Text("ERROR:", err)
155+
return
201156
}
202-
return str[:m]
157+
info := gjson.ParseBytes(data[9 : len(data)-1]).Get("data.song.list.0")
158+
msg = message.Music("qq", info.Get("songid").Int())
159+
return
203160
}
204161

205162
// md5str 返回字符串 MD5
@@ -223,17 +180,3 @@ func netGet(url string, header http.Header) []byte {
223180
result, _ := io.ReadAll(res.Body)
224181
return result
225182
}
226-
227-
// netPost 返回请求数据
228-
func netPost(url string, data url.Values, header http.Header) []byte {
229-
client := &http.Client{}
230-
request, _ := http.NewRequest("POST", url, strings.NewReader(data.Encode()))
231-
request.Header = header
232-
res, err := client.Do(request)
233-
if err != nil {
234-
return nil
235-
}
236-
defer res.Body.Close()
237-
result, _ := io.ReadAll(res.Body)
238-
return result
239-
}

plugin/shadiao/caihongpi.go

Lines changed: 0 additions & 21 deletions
This file was deleted.

plugin/shadiao/dujitang.go

Lines changed: 0 additions & 21 deletions
This file was deleted.

plugin/shadiao/pengyouquan.go

Lines changed: 0 additions & 21 deletions
This file was deleted.

plugin/shadiao/shadiao.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@ package shadiao
33

44
import (
55
control "github.com/FloatTech/zbputils/control"
6+
"github.com/FloatTech/zbputils/ctxext"
7+
"github.com/FloatTech/zbputils/web"
8+
"github.com/tidwall/gjson"
9+
zero "github.com/wdvxdr1123/ZeroBot"
10+
"github.com/wdvxdr1123/ZeroBot/message"
611
)
712

813
const (
9-
chpURL = "https://chp.shadiao.app/chp"
14+
chpURL = "https://api.shadiao.app/chp"
1015
duURL = "https://api.shadiao.app/du"
1116
pyqURL = "https://api.shadiao.app/pyq"
1217
yduanziURL = "http://www.yduanzi.com/duanzi/getduanzi"
1318
chayiURL = "https://api.lovelive.tools/api/SweetNothings/Web/0"
1419
ganhaiURL = "https://api.lovelive.tools/api/SweetNothings/Web/1"
1520
ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36"
16-
chpReferer = "https://chp.shadiao.app/"
17-
duReferer = "https://du.shadiao.app/"
18-
pyqReferer = "https://pyq.shadiao.app/"
21+
sdReferer = "https://api.shadiao.app/"
1922
yduanziReferer = "http://www.yduanzi.com/?utm_source=shadiao.app"
2023
loveliveReferer = "https://lovelive.tools/"
2124
)
@@ -26,4 +29,18 @@ var (
2629
Help: "沙雕app\n" +
2730
"- 哄我\n- 渣我\n- 来碗绿茶\n- 发个朋友圈\n- 来碗毒鸡汤\n- 讲个段子",
2831
})
32+
sdMap = map[string]string{"哄我": chpURL, "来碗毒鸡汤": duURL, "发个朋友圈": pyqURL}
2933
)
34+
35+
func init() {
36+
engine.OnFullMatchGroup([]string{"哄我", "来碗毒鸡汤", "发个朋友圈"}).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
37+
requestURL := sdMap[ctx.State["matched"].(string)]
38+
data, err := web.RequestDataWith(web.NewDefaultClient(), requestURL, "GET", sdReferer, ua)
39+
if err != nil {
40+
ctx.SendChain(message.Text("ERROR:", err))
41+
return
42+
}
43+
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(gjson.GetBytes(data, "data.text").String()))
44+
45+
})
46+
}

0 commit comments

Comments
 (0)