mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 05:30:07 +08:00
✨ 增加github搜索返回图片
This commit is contained in:
parent
f49026e307
commit
444a5c7bef
@ -14,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
func init() { // 插件主体
|
||||
zero.OnRegex(`^>github\s(.*)$`).SetBlock(true).FirstPriority().
|
||||
zero.OnRegex(`^>github\s(-.{1,10} )?(.*)$`).SetBlock(true).FirstPriority().
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
// 发送请求
|
||||
header := http.Header{
|
||||
@ -22,7 +22,7 @@ func init() { // 插件主体
|
||||
}
|
||||
api, _ := url.Parse("https://api.github.com/search/repositories")
|
||||
api.RawQuery = url.Values{
|
||||
"q": []string{ctx.State["regex_matched"].([]string)[1]},
|
||||
"q": []string{ctx.State["regex_matched"].([]string)[2]},
|
||||
}.Encode()
|
||||
body, err := netGet(api.String(), header)
|
||||
if err != nil {
|
||||
@ -36,8 +36,13 @@ func init() { // 插件主体
|
||||
}
|
||||
repo := info.Get("items.0")
|
||||
// 发送结果
|
||||
ctx.SendChain(
|
||||
message.Text(
|
||||
switch ctx.State["regex_matched"].([]string)[1] {
|
||||
case "-pic ": // 图片模式
|
||||
ctx.SendChain(message.Image(
|
||||
"https://opengraph.githubassets.com/0/"+repo.Get("full_name").Str,
|
||||
).Add("cache", 0))
|
||||
default:
|
||||
ctx.SendChain(message.Text(
|
||||
repo.Get("full_name").Str, "\n",
|
||||
"Description: ",
|
||||
repo.Get("description").Str, "\n",
|
||||
@ -51,8 +56,8 @@ func init() { // 插件主体
|
||||
repo.Get("pushed_at").Str, "\n",
|
||||
"Jump: ",
|
||||
repo.Get("html_url").Str, "\n",
|
||||
),
|
||||
)
|
||||
))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user