go-bot/workers/lsp.go

47 lines
1.1 KiB
Go

package workers
import (
"fmt"
"github.com/goccy/go-json"
"io"
"net/http"
)
type Lsp struct {
*StdAns
}
func (a *Lsp) GetMsg() string {
a.AllowGroup = append(a.AllowGroup, []string{"313047773"})
url := "https://api.lolicon.app/setu/v2?r18=0&size=small"
resp, err := http.Get(url)
if err != nil {
return "请求图片失败"
}
defer resp.Body.Close()
budy, err := io.ReadAll(resp.Body)
if err != nil {
return "读取失败"
}
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["small"].(string)
// title := data[0].(map[string]interface{})["title"].(string)
// println("标题:" + title + "\n" + imgUrl)
msg := fmt.Sprintf("[CQ:reply,id=%s]Pixiv ID:%d", a.MID, int64(uid))
a.SendMsg(msg)
return fmt.Sprintf("[CQ:image,file=%s]", imgUrl)
}