Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

更换百度一下为百度百科 #627

Merged
merged 36 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ee96e9b
readme
lianhong2758 Feb 6, 2023
eb5a98d
1
lianhong2758 Feb 6, 2023
8747f61
1
lianhong2758 Feb 6, 2023
836722d
kokomi插件
lianhong2758 Feb 6, 2023
e0606ca
change
lianhong2758 Feb 6, 2023
6815399
1
lianhong2758 Feb 6, 2023
982e3ce
1
lianhong2758 Feb 6, 2023
bb9c6b8
change
lianhong2758 Feb 6, 2023
512b4de
change
lianhong2758 Feb 6, 2023
7bb1050
Merge branch 'master' of github.com:lianhong2758/ZeroBot-Plugin
lianhong2758 Feb 7, 2023
aab4372
修复api失效
lianhong2758 Feb 7, 2023
0186e6a
改了,
lianhong2758 Feb 7, 2023
551f00f
1
lianhong2758 Feb 7, 2023
abf1b72
0
lianhong2758 Feb 7, 2023
4f08fda
Merge branch 'master' of github.com:lianhong2758/ZeroBot-Plugin
lianhong2758 Feb 19, 2023
b073ce0
加快自检速度
lianhong2758 Feb 19, 2023
1a337ba
1
lianhong2758 Feb 19, 2023
a6df63b
2
lianhong2758 Feb 19, 2023
03b6cf4
3
lianhong2758 Feb 19, 2023
1dd8631
4
lianhong2758 Feb 19, 2023
856a5f5
Merge branch 'master' of github.com:lianhong2758/ZeroBot-Plugin
lianhong2758 Feb 19, 2023
92959c4
1
lianhong2758 Feb 19, 2023
9480c88
1
lianhong2758 Feb 19, 2023
74ea439
Merge branch 'master' of github.com:lianhong2758/ZeroBot-Plugin
lianhong2758 Feb 28, 2023
6a6c364
Merge branch 'master' of github.com:lianhong2758/ZeroBot-Plugin
lianhong2758 Feb 28, 2023
84846b0
Merge branch 'master' of github.com:lianhong2758/ZeroBot-Plugin
lianhong2758 Mar 2, 2023
e1c2c0d
Merge branch 'master' of github.com:lianhong2758/ZeroBot-Plugin
lianhong2758 Mar 17, 2023
a287850
fix jiami
lianhong2758 Mar 17, 2023
c8c6060
1
lianhong2758 Mar 17, 2023
201c6f2
百度百科
lianhong2758 Mar 18, 2023
83ae8b5
1
lianhong2758 Mar 18, 2023
4b373be
fix
lianhong2758 Mar 18, 2023
aff23f6
Merge branch 'FloatTech:master' into master
lianhong2758 Mar 18, 2023
f8a71e0
fix
lianhong2758 Mar 18, 2023
f4c45f2
Merge branch 'master' of github.com:lianhong2758/ZeroBot-Plugin
lianhong2758 Mar 18, 2023
eacab9a
fix many bad goods
lianhong2758 Mar 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,11 @@ print("run[CQ:image,file="+j["img"]+"]")

</details>
<details>
<summary>百度一下</summary>
<summary>百度百科</summary>

`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/baidu"`

- [x] 百度下[xxx]
- [x] 百度/百科[xxx]

</details>
<details>
Expand Down
56 changes: 40 additions & 16 deletions plugin/baidu/search.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,51 @@
// Package baidu 百度一下
// Package baidu 百度百科
package baidu

import (
"net/url"
"encoding/json"
"fmt"

"github.com/FloatTech/floatbox/web"
ctrl "github.com/FloatTech/zbpctrl"
"github.com/FloatTech/zbputils/control"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
)

ctrl "github.com/FloatTech/zbpctrl"
"github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/ctxext"
const (
api = "https://api.a20safe.com/api.php?api=21&key=7d06a110e9e20a684e02934549db1d3d&text=%s" // api地址
)

func init() {
control.Register("baidu", &ctrl.Options[*zero.Ctx]{
type result struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data []struct {
Content string `json:"content"`
} `json:"data"`
}

func init() { // 主函数
en := control.Register("baidu", &ctrl.Options[*zero.Ctx]{
DisableOnDefault: false,
Brief: "不会百度吗",
Help: "- 百度下[xxx]",
}).OnPrefix("百度下").SetBlock(true).Limit(ctxext.LimitByGroup).
Handle(func(ctx *zero.Ctx) {
txt := ctx.State["args"].(string)
if txt != "" {
ctx.SendChain(message.Text("https://buhuibaidu.me/?s=" + url.QueryEscape(txt)))
}
})
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))
fumiama marked this conversation as resolved.
Show resolved Hide resolved
return
}
var r result // r数组
err = json.Unmarshal(es, &r) // 填api返回结果,struct地址
if err != nil {
ctx.SendChain(message.Text("出现错误捏:", err))
fumiama marked this conversation as resolved.
Show resolved Hide resolved
return
}
if r.Code == 0 && len(r.Data) > 0 {
ctx.SendChain(message.Text(r.Data[0].Content)) // 输出提取后的结果
fumiama marked this conversation as resolved.
Show resolved Hide resolved
} else {
ctx.SendChain(message.Text("API访问错误"))
}
})
}