44 lines
1,019 B
Go
44 lines
1,019 B
Go
package workers
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/goccy/go-json"
|
|
|
|
"io"
|
|
"net/http"
|
|
)
|
|
|
|
type Lsp struct {
|
|
*StdAns
|
|
}
|
|
|
|
func (a *Lsp) GetMsg() string {
|
|
a.AllowGroup = []string{"313047773"}
|
|
url := "https://api.lolicon.app/setu/v2?size=mini&r18=0"
|
|
resp, err := http.Get(url)
|
|
if err != nil {
|
|
return "获取失败"
|
|
}
|
|
defer resp.Body.Close()
|
|
budy, err := io.ReadAll(resp.Body)
|
|
var res map[string]interface{}
|
|
err = json.Unmarshal(budy, &res)
|
|
if err != nil {
|
|
return "解析失败"
|
|
}
|
|
code := res["error"].(string)
|
|
if code != "" {
|
|
return "获取失败"
|
|
}
|
|
data := res["data"].([]interface{})
|
|
uid := data[0].(map[string]interface{})["uid"].(float64)
|
|
urls := data[0].(map[string]interface{})["urls"].(map[string]interface{})
|
|
imgUrl := urls["mini"].(string)
|
|
// title := data[0].(map[string]interface{})["title"].(string)
|
|
// println("标题:" + title + "\n" + imgUrl)
|
|
msg := fmt.Sprintf("[CQ:reply,id=%s]Pixiv ID:%f", a.MID, uid)
|
|
a.SendMsg(msg)
|
|
return fmt.Sprintf("[CQ:image,file=%s,type=flash]", imgUrl)
|
|
|
|
}
|