feat(pkg): 优化pkg搜索匹配逻辑
This commit is contained in:
parent
637759c967
commit
174e55c279
3 changed files with 6 additions and 27 deletions
|
@ -96,20 +96,8 @@ func (a *AI) GetMsg() string {
|
||||||
return "未找到回复消息"
|
return "未找到回复消息"
|
||||||
}
|
}
|
||||||
file, picUrl, fileSizeStr := a.GetHisMsg(msgId)
|
file, picUrl, fileSizeStr := a.GetHisMsg(msgId)
|
||||||
println("file:", file, "picUrl:", picUrl, "fileSizeStr:", fileSizeStr)
|
// println("file:", file, "picUrl:", picUrl, "fileSizeStr:", fileSizeStr)
|
||||||
// 正则表达式匹配 file 和 file_size 的值
|
|
||||||
// re = regexp.MustCompile(`file=([^,]+),.*file_size=(\d+)`)
|
|
||||||
// matches = re.FindStringSubmatch(message)
|
|
||||||
// var file string
|
|
||||||
// var fileSizeStr string
|
|
||||||
// if len(matches) > 2 {
|
|
||||||
// file = matches[1]
|
|
||||||
// fileSizeStr = matches[2]
|
|
||||||
// } else {
|
|
||||||
// log.Println("未找到文件信息")
|
|
||||||
// return "未找到文件信息"
|
|
||||||
// }
|
|
||||||
// 将 fileSizeStr 转换为整数
|
|
||||||
if picUrl == "" {
|
if picUrl == "" {
|
||||||
log.Println("未找到文件信息")
|
log.Println("未找到文件信息")
|
||||||
return "未找到文件信息"
|
return "未找到文件信息"
|
||||||
|
|
|
@ -138,18 +138,7 @@ func (s *StdAns) GetHisMsg(id string) (string, string, string) {
|
||||||
return "", "", ""
|
return "", "", ""
|
||||||
}
|
}
|
||||||
if data["status"] == "ok" {
|
if data["status"] == "ok" {
|
||||||
// "message": [
|
|
||||||
// {
|
|
||||||
// "type": "image",
|
|
||||||
// "data": {
|
|
||||||
// "file": "NapCatOneBot-MsgFile-2-874769998-7483754018991870377-7409536985154972756",
|
|
||||||
// "sub_type": 1,
|
|
||||||
// "file_id": "NapCatOneBot-MsgFile-2-874769998-7483754018991870377-7409536985154972756",
|
|
||||||
// "url": "https://multimedia.nt.qq.com.cn/download?appid=1407&fileid=Cgk3OTQ1MDg5ODYSFL7bvc7L2hg8RHGXJQcDvMBVdYnBGOvXAyD_CiiUi5zw_KCIA1CAvaMB&spec=0&rkey=CAQSKAB6JWENi5LMzvLUe0XM_1cgokyjgML0etpRKmPhrFq1UBxRN8XOeWQ",
|
|
||||||
// "file_size": "60395"
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// ],
|
|
||||||
message := data["data"].(map[string]interface{})["message"].([]interface{})[0].(map[string]interface{})["data"].(map[string]interface{})
|
message := data["data"].(map[string]interface{})["message"].([]interface{})[0].(map[string]interface{})["data"].(map[string]interface{})
|
||||||
return message["file"].(string), message["url"].(string), message["file_size"].(string)
|
return message["file"].(string), message["url"].(string), message["file_size"].(string)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -75,7 +75,7 @@ func (a *Pkg) GetMsg() string {
|
||||||
}
|
}
|
||||||
var searchMap map[string]interface{}
|
var searchMap map[string]interface{}
|
||||||
var searchResult map[string]interface{}
|
var searchResult map[string]interface{}
|
||||||
if len(suggestions) == 1 {
|
if len(suggestions) == 1 || suggestions[0] == parms[1] {
|
||||||
searchUrl := "https://aur.archlinux.org/rpc/v5/info/" + suggestions[0]
|
searchUrl := "https://aur.archlinux.org/rpc/v5/info/" + suggestions[0]
|
||||||
_, body, errs = request.Get(searchUrl).End()
|
_, body, errs = request.Get(searchUrl).End()
|
||||||
|
|
||||||
|
@ -148,6 +148,8 @@ func (a *Pkg) GetMsg() string {
|
||||||
msg += OutOfDate
|
msg += OutOfDate
|
||||||
last_update := time.Unix(int64(searchResult["LastModified"].(float64)), 0).Format("2006-01-02 15:04:05")
|
last_update := time.Unix(int64(searchResult["LastModified"].(float64)), 0).Format("2006-01-02 15:04:05")
|
||||||
msg += "更新时间:" + last_update
|
msg += "更新时间:" + last_update
|
||||||
|
msg += "投票:" + fmt.Sprintf("%.0f", searchResult["NumVotes"].(float64)) + "\n"
|
||||||
|
msg += "AUR 链接:https://aur.archlinux.org/packages/" + searchResult["Name"].(string) + "\n"
|
||||||
|
|
||||||
// fmt.Println(msg)
|
// fmt.Println(msg)
|
||||||
return msg
|
return msg
|
||||||
|
|
Loading…
Reference in a new issue