From af666fee953f76b6838b85bb5ebd34d2ee17bb42 Mon Sep 17 00:00:00 2001 From: liyp Date: Sun, 14 Apr 2024 15:18:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8D=A2=E8=A1=8C=E7=AC=A6?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/router.go | 1 + workers/pkg.go | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/utils/router.go b/utils/router.go index 87aece1..078b2ff 100644 --- a/utils/router.go +++ b/utils/router.go @@ -22,6 +22,7 @@ func Router(data map[string]interface{}) { role := sender["role"].(string) mid := data["message_id"].(float64) raw_msg := data["raw_message"].(string)[1:] + parms := strings.Split(raw_msg, " ") worker := workers.NewWorker(parms, fmt.Sprintf("%d", int(uid)), fmt.Sprintf("%d", int(gid)), role, fmt.Sprintf("%d", int(mid)), raw_msg) diff --git a/workers/pkg.go b/workers/pkg.go index 878531a..ee8cf78 100644 --- a/workers/pkg.go +++ b/workers/pkg.go @@ -18,12 +18,17 @@ func (a *Pkg) GetMsg() string { if len(a.Parms) < 2 { return "请输入包名 如:/pkg linux 查询 linux 相关软件" } - url := "https://archlinux.org/packages/search/json/?name=" + a.Parms[1] - if len(a.Parms) > 2 { - url += "&repo=" + strings.ToUpper(a.Parms[2][:1]) + a.Parms[2][1:] + // 去除换行符 + raw_msg := strings.TrimRight(a.RawMsg, "\\n") + fmt.Println("raw_msg:", raw_msg) + parms := strings.Split(raw_msg, " ") + + url := "https://archlinux.org/packages/search/json/?name=" + parms[1] + if len(parms) > 2 { + url += "&repo=" + strings.ToUpper(parms[2][:1]) + parms[2][1:] } // 输出请求地址 - // fmt.Println("pkg url:", url) + fmt.Println("pkg url:", url) req, err := http.Get(url) if err != nil { return err.Error() @@ -44,13 +49,14 @@ func (a *Pkg) GetMsg() string { resultSlipe := pkg["results"].([]interface{}) if len(resultSlipe) == 0 { - url := "https://aur.archlinux.org/rpc/v5/suggest/" + a.Parms[1] + url := "https://aur.archlinux.org/rpc/v5/suggest/" + parms[1] req, err := http.Get(url) if err != nil { fmt.Println(err) } defer req.Body.Close() + fmt.Println("aur url:", url) re, err := io.ReadAll(req.Body) // fmt.Println(string(re)) if err != nil {