From da289073e2c5397e4e3f22040ff493bc5d5b7713 Mon Sep 17 00:00:00 2001 From: Chendihe4975 Date: Sun, 12 Sep 2021 15:34:38 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=8B=BC=E9=9F=B3=E9=A6=96=E5=AD=97?= =?UTF-8?q?=E6=AF=8D=E7=BC=A9=E5=86=99=E9=87=8A=E4=B9=89=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 1 + plugin_nbnhhsh/nbnhhsh.go | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 plugin_nbnhhsh/nbnhhsh.go diff --git a/main.go b/main.go index 575a699c..73972edf 100644 --- a/main.go +++ b/main.go @@ -15,6 +15,7 @@ import ( // 实用类 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_github" // 搜索GitHub仓库 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_manager" // 群管 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin_nbnhhsh" // 拼音首字母缩写释义工具 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_runcode" // 在线运行代码 // 娱乐类 diff --git a/plugin_nbnhhsh/nbnhhsh.go b/plugin_nbnhhsh/nbnhhsh.go new file mode 100644 index 00000000..8e4df5ae --- /dev/null +++ b/plugin_nbnhhsh/nbnhhsh.go @@ -0,0 +1,39 @@ +package nbnhhsh + +import ( + "io/ioutil" + "net/http" + "net/url" + "strings" + + "github.com/tidwall/gjson" + zero "github.com/wdvxdr1123/ZeroBot" + "github.com/wdvxdr1123/ZeroBot/message" +) + +func init() { + zero.OnRegex(`^[??]{1,2} ?([a-z0-9]+)$`).SetBlock(false). + Handle(func(ctx *zero.Ctx) { + keyword := ctx.State["regex_matched"].([]string)[1] + ctx.SendChain(message.Text(keyword + ": " + strings.Join(getValue(keyword), ", "))) + }) +} + +func getValue(text string) []string { + urlValues := url.Values{} + urlValues.Add("text", text) + resp, _ := http.PostForm("https://lab.magiconch.com/api/nbnhhsh/guess", urlValues) + body, _ := ioutil.ReadAll(resp.Body) + json := gjson.ParseBytes(body) + res := make([]string, 0) + var jsonPath string + if json.Get("0.trans").Exists() { + jsonPath = "0.trans" + } else { + jsonPath = "0.inputting" + } + for _, value := range json.Get(jsonPath).Array() { + res = append(res, value.String()) + } + return res +} From c70dbd219cb844555e1aa0eb71c855cea3ec5413 Mon Sep 17 00:00:00 2001 From: Chendihe4975 Date: Sun, 12 Sep 2021 15:37:54 +0800 Subject: [PATCH 2/2] Update README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index d857a33f..30b701b2 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,8 @@ - [x] @Bot 任意文本(任意一句话回复) - **关键字搜图** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_image_finder"` - [x] 来张 [xxx] +- **拼音首字母释义工具** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_nbnhhsh"` + - [x] ?? [缩写] - **TODO...** ## 使用方法