mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 13:59:39 +08:00
更换百度一下为百度百科 (#627)
This commit is contained in:
parent
86b87c2b4e
commit
1734f1f7d4
@ -436,11 +436,11 @@ print("run[CQ:image,file="+j["img"]+"]")
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
<details>
|
<details>
|
||||||
<summary>百度一下</summary>
|
<summary>百度百科</summary>
|
||||||
|
|
||||||
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/baidu"`
|
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/baidu"`
|
||||||
|
|
||||||
- [x] 百度下[xxx]
|
- [x] 百度/百科[xxx]
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
<details>
|
<details>
|
||||||
|
|||||||
@ -1,27 +1,51 @@
|
|||||||
// Package baidu 百度一下
|
// Package baidu 百度百科
|
||||||
package baidu
|
package baidu
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/url"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
|
||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
|
||||||
|
|
||||||
|
"github.com/FloatTech/floatbox/web"
|
||||||
ctrl "github.com/FloatTech/zbpctrl"
|
ctrl "github.com/FloatTech/zbpctrl"
|
||||||
"github.com/FloatTech/zbputils/control"
|
"github.com/FloatTech/zbputils/control"
|
||||||
"github.com/FloatTech/zbputils/ctxext"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
const (
|
||||||
control.Register("baidu", &ctrl.Options[*zero.Ctx]{
|
api = "https://api.a20safe.com/api.php?api=21&key=7d06a110e9e20a684e02934549db1d3d&text=%s" // api地址
|
||||||
DisableOnDefault: false,
|
)
|
||||||
Brief: "不会百度吗",
|
|
||||||
Help: "- 百度下[xxx]",
|
type result struct {
|
||||||
}).OnPrefix("百度下").SetBlock(true).Limit(ctxext.LimitByGroup).
|
Code int `json:"code"`
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Msg string `json:"msg"`
|
||||||
txt := ctx.State["args"].(string)
|
Data []struct {
|
||||||
if txt != "" {
|
Content string `json:"content"`
|
||||||
ctx.SendChain(message.Text("https://buhuibaidu.me/?s=" + url.QueryEscape(txt)))
|
} `json:"data"`
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
func init() { // 主函数
|
||||||
|
en := control.Register("baidu", &ctrl.Options[*zero.Ctx]{
|
||||||
|
DisableOnDefault: false,
|
||||||
|
Help: "百度百科\n" +
|
||||||
|
"- 百度/百科[关键字]",
|
||||||
|
})
|
||||||
|
en.OnRegex(`^[百度|百科]\s*(.+)$`).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||||
|
es, err := web.GetData(fmt.Sprintf(api, ctx.State["regex_matched"].([]string)[1])) // 将网站返回结果赋值
|
||||||
|
if err != nil {
|
||||||
|
ctx.SendChain(message.Text("出现错误捏:", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var r result // r数组
|
||||||
|
err = json.Unmarshal(es, &r) // 填api返回结果,struct地址
|
||||||
|
if err != nil {
|
||||||
|
ctx.SendChain(message.Text("出现错误捏:", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if r.Code == 0 && len(r.Data) > 0 {
|
||||||
|
ctx.SendChain(message.Text(r.Data[0].Content)) // 输出提取后的结果
|
||||||
|
} else {
|
||||||
|
ctx.SendChain(message.Text("API访问错误"))
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user