fix pkg
This commit is contained in:
parent
3846c6b4a4
commit
9b9fa6a616
2 changed files with 14 additions and 11 deletions
|
@ -1,7 +1,6 @@
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"go-bot/workers"
|
"go-bot/workers"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -9,13 +8,13 @@ import (
|
||||||
|
|
||||||
func Router(data map[string]interface{}) {
|
func Router(data map[string]interface{}) {
|
||||||
// 将map转换为格式化的JSON字符串
|
// 将map转换为格式化的JSON字符串
|
||||||
jsonString, err := json.MarshalIndent(data, "", " ")
|
// jsonString, err := json.MarshalIndent(data, "", " ")
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
panic(err)
|
// panic(err)
|
||||||
}
|
// }
|
||||||
|
|
||||||
// 输出格式化后的JSON
|
// 输出格式化后的JSON
|
||||||
fmt.Println(string(jsonString))
|
// fmt.Println(string(jsonString))
|
||||||
// 读取字段值
|
// 读取字段值
|
||||||
uid := data["user_id"].(float64)
|
uid := data["user_id"].(float64)
|
||||||
gid := data["group_id"].(float64)
|
gid := data["group_id"].(float64)
|
||||||
|
@ -28,7 +27,7 @@ func Router(data map[string]interface{}) {
|
||||||
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)
|
||||||
|
|
||||||
// fmt.Println("router:", parms[0])
|
// fmt.Println("router:", parms[0])
|
||||||
fmt.Println(worker.CheckPermission())
|
// fmt.Println(worker.CheckPermission())
|
||||||
// ans := NewStdAns(parms[0], fmt.Sprintf("%d", int(uid)), fmt.Sprintf("%d", int(gid)), role, fmt.Sprintf("%d", int(mid)), raw_msg)
|
// ans := NewStdAns(parms[0], fmt.Sprintf("%d", int(uid)), fmt.Sprintf("%d", int(gid)), role, fmt.Sprintf("%d", int(mid)), raw_msg)
|
||||||
message := worker.CheckPermission()
|
message := worker.CheckPermission()
|
||||||
if message != "0" {
|
if message != "0" {
|
||||||
|
|
|
@ -15,11 +15,11 @@ 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[0]
|
url := "https://archlinux.org/packages/search/json/?name=" + a.Parms[1]
|
||||||
if len(a.Parms) > 2 {
|
if len(a.Parms) > 2 {
|
||||||
url += "&arch=" + a.Parms[1]
|
url += "&arch=" + a.Parms[2]
|
||||||
}
|
}
|
||||||
// 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()
|
||||||
|
@ -37,7 +37,11 @@ func (a *Pkg) GetMsg() string {
|
||||||
return err.Error()
|
return err.Error()
|
||||||
}
|
}
|
||||||
// fmt.Println("pkg:", pkg)
|
// fmt.Println("pkg:", pkg)
|
||||||
result := pkg["results"].([]interface{})[0].(map[string]interface{})
|
resultSlipe := pkg["results"].([]interface{})
|
||||||
|
if len(resultSlipe) == 0 {
|
||||||
|
return "没有找到相关软件"
|
||||||
|
}
|
||||||
|
result := resultSlipe[0].(map[string]interface{})
|
||||||
|
|
||||||
fmt.Println("result:", result)
|
fmt.Println("result:", result)
|
||||||
if result != nil {
|
if result != nil {
|
||||||
|
|
Loading…
Reference in a new issue