package workers import ( "fmt" "go-bot/config" "slices" "github.com/goccy/go-json" "io" "net/http" ) func init() { plugins := config.GetConfig()["PLUGINS"].([]interface{}) if slices.Contains(plugins, "lsp") { RegisterWorkerFactory("lsp", func(parms []string, uid, gid, role, mid, rawMsg string) Worker { return &Lsp{ StdAns: NewStdAns(parms, uid, gid, role, mid, rawMsg), } }) } } type Lsp struct { *StdAns } func (a *Lsp) GetMsg() string { 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) }