添加lsp插件

This commit is contained in:
liyp 2024-04-23 20:38:37 +08:00
parent 59408e0ba3
commit ffab2cb534
6 changed files with 63 additions and 7 deletions

3
.gitignore vendored
View file

@ -1,2 +1,3 @@
data.db
test.json
test.json
config.toml

10
config example.toml Normal file
View file

@ -0,0 +1,10 @@
[Server]
APIURL = "0.0.0.0:5580"
POSTURL = "http://0.0.0.0:5700"
[Group]
AllowGroup = []
AllowUser = []
AllowRole = []
BlockGroup = []
BlockUser = []

7
go.mod
View file

@ -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
)

44
workers/lsp.go Normal file
View file

@ -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)
}

View file

@ -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)}

View file

@ -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:]
}
// 输出请求地址