Skip to content

Commit 8eb058f

Browse files
authored
add 维基百科 (#673)
* add 维基百科 * make happy
1 parent 33e5b02 commit 8eb058f

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,11 @@ print("run[CQ:image,file="+j["img"]+"]")
436436

437437
</details>
438438
<details>
439-
<summary>百度百科</summary>
439+
<summary>百科</summary>
440440

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

443-
- [x] 百度/百科[xxx]
443+
- [x] 百度/百科/维基/wiki[xxx]
444444

445445
</details>
446446
<details>

plugin/baidu/search.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import (
1313
)
1414

1515
const (
16-
api = "https://api.a20safe.com/api.php?api=21&key=7d06a110e9e20a684e02934549db1d3d&text=%s" // api地址
16+
duURL = "https://api.a20safe.com/api.php?api=21&key=%s&text=%s" // api地址
17+
wikiURL = "https://api.a20safe.com/api.php?api=23&key=%s&text=%s"
18+
key = "7d06a110e9e20a684e02934549db1d3d"
1719
)
1820

1921
type result struct {
@@ -27,11 +29,18 @@ type result struct {
2729
func init() { // 主函数
2830
en := control.Register("baidu", &ctrl.Options[*zero.Ctx]{
2931
DisableOnDefault: false,
30-
Help: "百度百科\n" +
31-
"- 百度/百科[关键字]",
32+
Help: "百科\n" +
33+
"- 百度/百科/维基/wiki[关键字]",
3234
})
33-
en.OnRegex(`^百[度科]\s*(.+)$`).SetBlock(true).Handle(func(ctx *zero.Ctx) {
34-
es, err := web.GetData(fmt.Sprintf(api, ctx.State["regex_matched"].([]string)[1])) // 将网站返回结果赋值
35+
en.OnRegex(`^(百度|维基|百科|wiki)\s*(.+)$`).SetBlock(true).Handle(func(ctx *zero.Ctx) {
36+
var es []byte
37+
var err error
38+
switch ctx.State["regex_matched"].([]string)[1] {
39+
case "百度", "百科":
40+
es, err = web.GetData(fmt.Sprintf(duURL, key, ctx.State["regex_matched"].([]string)[2])) // 将网站返回结果赋值
41+
case "wiki", "维基":
42+
es, err = web.GetData(fmt.Sprintf(wikiURL, key, ctx.State["regex_matched"].([]string)[2])) // 将网站返回结果赋值
43+
}
3544
if err != nil {
3645
ctx.SendChain(message.Text("出现错误捏:", err))
3746
return

0 commit comments

Comments
 (0)