From 8eb058fb26d86b28740a6020e0e8008454ee9547 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=8E=B2=E5=AE=9D=E5=9D=8F=E5=9D=8F=E5=9D=8F?=
<2758988938@qq.com>
Date: Wed, 19 Apr 2023 00:47:44 +0800
Subject: [PATCH] =?UTF-8?q?add=20=E7=BB=B4=E5=9F=BA=E7=99=BE=E7=A7=91=20(#?=
=?UTF-8?q?673)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* add 维基百科
* make happy
---
README.md | 4 ++--
plugin/baidu/search.go | 19 ++++++++++++++-----
2 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/README.md b/README.md
index cd4a0387c1..0344abe2d5 100644
--- a/README.md
+++ b/README.md
@@ -436,11 +436,11 @@ print("run[CQ:image,file="+j["img"]+"]")
- 百度百科
+ 百科
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/baidu"`
- - [x] 百度/百科[xxx]
+ - [x] 百度/百科/维基/wiki[xxx]
diff --git a/plugin/baidu/search.go b/plugin/baidu/search.go
index 887bdeac1f..4942d24d08 100644
--- a/plugin/baidu/search.go
+++ b/plugin/baidu/search.go
@@ -13,7 +13,9 @@ import (
)
const (
- api = "https://api.a20safe.com/api.php?api=21&key=7d06a110e9e20a684e02934549db1d3d&text=%s" // api地址
+ duURL = "https://api.a20safe.com/api.php?api=21&key=%s&text=%s" // api地址
+ wikiURL = "https://api.a20safe.com/api.php?api=23&key=%s&text=%s"
+ key = "7d06a110e9e20a684e02934549db1d3d"
)
type result struct {
@@ -27,11 +29,18 @@ type result struct {
func init() { // 主函数
en := control.Register("baidu", &ctrl.Options[*zero.Ctx]{
DisableOnDefault: false,
- Help: "百度百科\n" +
- "- 百度/百科[关键字]",
+ Help: "百科\n" +
+ "- 百度/百科/维基/wiki[关键字]",
})
- en.OnRegex(`^百[度科]\s*(.+)$`).SetBlock(true).Handle(func(ctx *zero.Ctx) {
- es, err := web.GetData(fmt.Sprintf(api, ctx.State["regex_matched"].([]string)[1])) // 将网站返回结果赋值
+ en.OnRegex(`^(百度|维基|百科|wiki)\s*(.+)$`).SetBlock(true).Handle(func(ctx *zero.Ctx) {
+ var es []byte
+ var err error
+ switch ctx.State["regex_matched"].([]string)[1] {
+ case "百度", "百科":
+ es, err = web.GetData(fmt.Sprintf(duURL, key, ctx.State["regex_matched"].([]string)[2])) // 将网站返回结果赋值
+ case "wiki", "维基":
+ es, err = web.GetData(fmt.Sprintf(wikiURL, key, ctx.State["regex_matched"].([]string)[2])) // 将网站返回结果赋值
+ }
if err != nil {
ctx.SendChain(message.Text("出现错误捏:", err))
return