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 {