From ffab2cb534b723bac1b6568e1eef61dd8982713b Mon Sep 17 00:00:00 2001 From: liyp Date: Tue, 23 Apr 2024 20:38:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0lsp=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- config example.toml | 10 ++++++++++ go.mod | 7 ++----- workers/lsp.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ workers/newworker.go | 4 ++++ workers/pkg.go | 2 +- 6 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 config example.toml create mode 100644 workers/lsp.go diff --git a/.gitignore b/.gitignore index 945acc2..74eeb37 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ data.db -test.json \ No newline at end of file +test.json +config.toml \ No newline at end of file diff --git a/config example.toml b/config example.toml new file mode 100644 index 0000000..fc3a200 --- /dev/null +++ b/config example.toml @@ -0,0 +1,10 @@ +[Server] +APIURL = "0.0.0.0:5580" +POSTURL = "http://0.0.0.0:5700" + +[Group] +AllowGroup = [] +AllowUser = [] +AllowRole = [] +BlockGroup = [] +BlockUser = [] \ No newline at end of file diff --git a/go.mod b/go.mod index 5667b21..91eeedc 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,10 @@ module go-bot -go 1.21.0 +go 1.22.2 require github.com/BurntSushi/toml v1.3.2 -require golang.org/x/net v0.17.0 // indirect - require ( - github.com/goccy/go-json v0.10.2 // indirect - github.com/gorilla/websocket v1.5.1 + github.com/goccy/go-json v0.10.2 github.com/mattn/go-sqlite3 v1.14.22 ) diff --git a/workers/lsp.go b/workers/lsp.go new file mode 100644 index 0000000..c3c1e0c --- /dev/null +++ b/workers/lsp.go @@ -0,0 +1,44 @@ +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) + +} diff --git a/workers/newworker.go b/workers/newworker.go index 8d14c8c..9992d51 100644 --- a/workers/newworker.go +++ b/workers/newworker.go @@ -22,6 +22,10 @@ func NewWorker(parms []string, uid, gid, role, mid, rawMsg string) Worker { return &Ip{ StdAns: NewStdAns(parms, uid, gid, role, mid, rawMsg), } + case "lsp": + return &Lsp{ + StdAns: NewStdAns(parms, uid, gid, role, mid, rawMsg), + } default: return &Emm{ StdAns: NewStdAns(parms, uid, gid, role, mid, rawMsg)} diff --git a/workers/pkg.go b/workers/pkg.go index 7eeb5eb..437111a 100644 --- a/workers/pkg.go +++ b/workers/pkg.go @@ -25,7 +25,7 @@ func (a *Pkg) GetMsg() string { parms := strings.Split(raw_msg, " ") url := "https://archlinux.org/packages/search/json/?name=" + parms[1] - if len(parms) > 2 { + if len(parms) > 2 && parms[1] != "" { url += "&repo=" + strings.ToUpper(parms[2][:1]) + parms[2][1:] } // 输出请求地址