go-bot/workers/lsp.go
liyp 13483b9643 feat(config): 添加OpenAI API配置并优化打印配置函数
在config.toml中添加了OPENAI_API_KEY、OPENAI_BaseURL和MODEL配置项,以支持OpenAI API的集成。
同时,优化了PrintConfig函数,使其能够递归打印嵌套的配置结构,提高了配置管理的可读性和易用性。
2024-06-30 21:56:34 +08:00

44 lines
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)
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)
}