2024-04-23 20:38:37 +08:00
|
|
|
package workers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/goccy/go-json"
|
|
|
|
|
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2024-07-05 22:33:55 +08:00
|
|
|
func init() {
|
|
|
|
RegisterWorkerFactory("lsp", func(parms []string, uid, gid, role, mid, rawMsg string) Worker {
|
|
|
|
return &Lsp{
|
|
|
|
StdAns: NewStdAns(parms, uid, gid, role, mid, rawMsg),
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-04-23 20:38:37 +08:00
|
|
|
type Lsp struct {
|
|
|
|
*StdAns
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Lsp) GetMsg() string {
|
2024-06-30 21:56:34 +08:00
|
|
|
a.AllowGroup = append(a.AllowGroup, []string{"313047773"})
|
2024-04-23 21:32:59 +08:00
|
|
|
url := "https://api.lolicon.app/setu/v2?r18=0&size=small"
|
2024-04-23 20:38:37 +08:00
|
|
|
resp, err := http.Get(url)
|
|
|
|
if err != nil {
|
2024-06-30 23:36:17 +08:00
|
|
|
return "请求图片失败"
|
2024-04-23 20:38:37 +08:00
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
budy, err := io.ReadAll(resp.Body)
|
2024-06-30 23:36:17 +08:00
|
|
|
if err != nil {
|
|
|
|
return "读取失败"
|
|
|
|
}
|
2024-04-23 20:38:37 +08:00
|
|
|
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{})
|
2024-04-23 21:32:59 +08:00
|
|
|
imgUrl := urls["small"].(string)
|
2024-04-23 20:38:37 +08:00
|
|
|
// title := data[0].(map[string]interface{})["title"].(string)
|
|
|
|
// println("标题:" + title + "\n" + imgUrl)
|
2024-04-23 21:32:59 +08:00
|
|
|
msg := fmt.Sprintf("[CQ:reply,id=%s]Pixiv ID:%d", a.MID, int64(uid))
|
2024-04-23 20:38:37 +08:00
|
|
|
a.SendMsg(msg)
|
2024-04-23 21:32:59 +08:00
|
|
|
return fmt.Sprintf("[CQ:image,file=%s]", imgUrl)
|
2024-04-23 20:38:37 +08:00
|
|
|
|
|
|
|
}
|