feat(mner): 增加mner插件
fix(ai): 修复ai获取图片bug
This commit is contained in:
parent
8443f5f5a0
commit
637759c967
3 changed files with 63 additions and 3 deletions
|
@ -96,7 +96,7 @@ 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)
|
||||||
// 正则表达式匹配 file 和 file_size 的值
|
// 正则表达式匹配 file 和 file_size 的值
|
||||||
// re = regexp.MustCompile(`file=([^,]+),.*file_size=(\d+)`)
|
// re = regexp.MustCompile(`file=([^,]+),.*file_size=(\d+)`)
|
||||||
// matches = re.FindStringSubmatch(message)
|
// matches = re.FindStringSubmatch(message)
|
||||||
|
|
|
@ -150,8 +150,8 @@ func (s *StdAns) GetHisMsg(id string) (string, string, string) {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// ],
|
// ],
|
||||||
message := data["data"].(map[string]interface{})["message"].(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_id"].(string)
|
return message["file"].(string), message["url"].(string), message["file_size"].(string)
|
||||||
} else {
|
} else {
|
||||||
// fmt.Println("响应返回:", body)
|
// fmt.Println("响应返回:", body)
|
||||||
return "", "", ""
|
return "", "", ""
|
||||||
|
|
60
workers/mner.go
Normal file
60
workers/mner.go
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
package workers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/parnurzeal/gorequest"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterWorkerFactory("mner", func(parms []string, uid, gid, role, mid, rawMsg string) Worker {
|
||||||
|
return &Mner{
|
||||||
|
StdAns: NewStdAns(parms, uid, gid, role, mid, rawMsg),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
type Mner struct {
|
||||||
|
*StdAns
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Mner) GetMsg() string {
|
||||||
|
if len(a.Parms) < 2 {
|
||||||
|
return "请输入AUR的维护者 如:/mner user 查询 user 用户维护的包"
|
||||||
|
}
|
||||||
|
user := a.Parms[1]
|
||||||
|
url := "https://aur.archlinux.org/rpc/v5/search/" + user + "?by=maintainer"
|
||||||
|
request := gorequest.New()
|
||||||
|
_, body, errs := request.Get(url).End()
|
||||||
|
if len(errs) > 0 {
|
||||||
|
return "服务器网络错误!"
|
||||||
|
}
|
||||||
|
var result map[string]interface{}
|
||||||
|
err := json.Unmarshal([]byte(body), &result)
|
||||||
|
if err != nil {
|
||||||
|
return err.Error()
|
||||||
|
}
|
||||||
|
results := result["results"].([]interface{})
|
||||||
|
if len(results) == 0 {
|
||||||
|
return "未找到该维护者维护的包"
|
||||||
|
}
|
||||||
|
msg := "该维护者 " + a.Parms[1] + " 共维护了 " + strconv.FormatInt(int64(result["resultcount"].(float64)), 10) + " 个包:\n"
|
||||||
|
|
||||||
|
// 将结果按NumVotes排序
|
||||||
|
sort.Slice(results, func(i, j int) bool {
|
||||||
|
return results[i].(map[string]interface{})["NumVotes"].(float64) > results[j].(map[string]interface{})["NumVotes"].(float64)
|
||||||
|
})
|
||||||
|
|
||||||
|
// 只显示NumVotes最大的5个包
|
||||||
|
for i, v := range results {
|
||||||
|
if i >= 5 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
pkg := v.(map[string]interface{})
|
||||||
|
msg += fmt.Sprintf("包名:%s\n版本:%s\n描述:%s\n票数:%d\n\n", pkg["Name"], pkg["Version"], pkg["Description"], int(pkg["NumVotes"].(float64)))
|
||||||
|
}
|
||||||
|
return msg
|
||||||
|
}
|
Loading…
Reference in a new issue