修复换行符问题

This commit is contained in:
liyp 2024-04-14 15:18:23 +08:00
parent c0ef993b99
commit af666fee95
2 changed files with 12 additions and 5 deletions

View file

@ -22,6 +22,7 @@ func Router(data map[string]interface{}) {
role := sender["role"].(string) role := sender["role"].(string)
mid := data["message_id"].(float64) mid := data["message_id"].(float64)
raw_msg := data["raw_message"].(string)[1:] raw_msg := data["raw_message"].(string)[1:]
parms := strings.Split(raw_msg, " ") 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) worker := workers.NewWorker(parms, fmt.Sprintf("%d", int(uid)), fmt.Sprintf("%d", int(gid)), role, fmt.Sprintf("%d", int(mid)), raw_msg)

View file

@ -18,12 +18,17 @@ func (a *Pkg) GetMsg() string {
if len(a.Parms) < 2 { if len(a.Parms) < 2 {
return "请输入包名 如:/pkg linux 查询 linux 相关软件" return "请输入包名 如:/pkg linux 查询 linux 相关软件"
} }
url := "https://archlinux.org/packages/search/json/?name=" + a.Parms[1] // 去除换行符
if len(a.Parms) > 2 { raw_msg := strings.TrimRight(a.RawMsg, "\\n")
url += "&repo=" + strings.ToUpper(a.Parms[2][:1]) + a.Parms[2][1:] 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) req, err := http.Get(url)
if err != nil { if err != nil {
return err.Error() return err.Error()
@ -44,13 +49,14 @@ func (a *Pkg) GetMsg() string {
resultSlipe := pkg["results"].([]interface{}) resultSlipe := pkg["results"].([]interface{})
if len(resultSlipe) == 0 { 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) req, err := http.Get(url)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
defer req.Body.Close() defer req.Body.Close()
fmt.Println("aur url:", url)
re, err := io.ReadAll(req.Body) re, err := io.ReadAll(req.Body)
// fmt.Println(string(re)) // fmt.Println(string(re))
if err != nil { if err != nil {