From 0698d8e3b1dd95f15598ded97e5f5e703b1465d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8E=AB=E6=80=9D=E6=BD=8B?= <55676105+shudorcl@users.noreply.github.com> Date: Thu, 31 Mar 2022 19:36:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E4=BA=86=E6=9E=9D?= =?UTF-8?q?=E7=BD=91=E6=9F=A5=E9=87=8D=E6=97=A0=E6=B3=95=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=20(#175)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 优化在两个命令中使用空格分隔的体验 - fortune的设置底图功能 - b14的加密功能 * 优化四个插件中使用空格分隔的体验 - 加密 - 哔哩哔哩推送 - 藏头诗 - 运势 * 优化并修正了上一个commit - 加上了因为复制粘贴疏忽又没有注意测试遗漏的`?` - 调整藏头诗和加密的正则触发,使其不必多此一举 - 删去了未被发现的测试代码 * - 删去了遗漏的Trim * 优化了更多插件中使用空格的体验 - 优化了music bilibili image_finder 中使用空格的体验 - 补上了plugin_bilibili中未实现的vup开头触发 - 为plugin_bilibili_parse输出的消息加上一个换行符,优化排版 * 小调整 - 考虑到屌字既难打又有碍观瞻,改为正则匹配`[屌|弔|吊]图` - 增加了退群提醒的定制 * - 修复退群提醒本身忘记修改了的问题 * fix:修复了枝网查重无法使用的问题 * readme适配上次的欢迎语修改 * 删去调试语句 * Update setu_geter.go * Update zhiwang.go Co-authored-by: 源文雨 <41315874+fumiama@users.noreply.github.com> --- README.md | 2 +- plugin/diana/zhiwang.go | 52 ++++++++++++++--------------------- plugin/setutime/setu_geter.go | 6 ++-- 3 files changed, 24 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index d0e9a7a0..c2de1152 100644 --- a/README.md +++ b/README.md @@ -148,7 +148,7 @@ print("run[CQ:image,file="+j["img"]+"]") - [x] 退出群聊[群号]@Bot - [x] *入群欢迎 - [x] *退群通知 - - [x] 设置欢迎语[欢迎~] 可选添加 [{at}] [{nickname}] [{avatar}] + - [x] 设置欢迎语[欢迎~] 可选添加 [{at}] [{nickname}] [{avatar}] [{id}] - [x] 在[MM]月[dd]日的[hh]点[mm]分时(用[url])提醒大家[xxx] - [x] 在[MM]月[每周 | 周几]的[hh]点[mm]分时(用[url])提醒大家[xxx] - [x] 取消在[MM]月[dd]日的[hh]点[mm]分的提醒 diff --git a/plugin/diana/zhiwang.go b/plugin/diana/zhiwang.go index d4c274c4..1e680da6 100644 --- a/plugin/diana/zhiwang.go +++ b/plugin/diana/zhiwang.go @@ -3,10 +3,11 @@ package diana import ( "bytes" - "encoding/json" + "io" "math" "time" + "github.com/tidwall/gjson" "github.com/wdvxdr1123/ZeroBot/message" "net/http" @@ -15,17 +16,6 @@ import ( zero "github.com/wdvxdr1123/ZeroBot" ) -type zhiwang struct { - Code int `json:"code"` - Data struct { - EndTime int `json:"end_time"` - Rate float64 `json:"rate"` - Related [][]interface{} `json:"related"` - StartTime int `json:"start_time"` - } `json:"data"` - Message string `json:"message"` -} - // 小作文查重: 回复要查的消息 查重 func init() { engine.OnMessage(fullmatch("查重")).SetBlock(true). @@ -34,28 +24,27 @@ func init() { if msg[0].Type == "reply" { msg := ctx.GetMessage(message.NewMessageID(msg[0].Data["id"])).Elements[0].Data["text"] zhiwangjson := zhiwangapi(msg) - - if zhiwangjson == nil || zhiwangjson.Code != 0 { + if zhiwangjson == nil || zhiwangjson.Get("code").Int() != 0 { ctx.SendChain(message.Text("api返回错误")) return } - if len(zhiwangjson.Data.Related) == 0 { - ctx.SendChain(message.Text("枝网没搜到,查重率为0%,我的评价是:一眼真")) + if zhiwangjson.Get("data.related.#").Int() == 0 { + ctx.SendChain(message.Text("枝网没搜到,查重率为0%,鉴定为原创")) return } - - related := zhiwangjson.Data.Related[0][1].(map[string]interface{}) + related := zhiwangjson.Get("data.related.0.reply").Map() + rate := zhiwangjson.Get("data.related.0.rate").Float() ctx.SendChain(message.Text( "枝网文本复制检测报告(简洁)", "\n", "查重时间: ", time.Now().Format("2006-01-02 15:04:05"), "\n", - "总文字复制比: ", math.Floor(zhiwangjson.Data.Rate*100), "%", "\n", - "相似小作文:", "\n", - related["content"].(string)[:102]+".....", "\n", - "获赞数", related["like_num"], "\n", - zhiwangjson.Data.Related[0][2].(string), "\n", - "作者: ", related["m_name"], "\n", - "发表时间: ", time.Unix(int64(related["ctime"].(float64)), 0).Format("2006-01-02 15:04:05"), "\n", + "总文字复制比: ", math.Floor(rate*100), "%", "\n", + "相似小作文:", "\n", + related["content"].String()[:102]+".....", "\n", + "获赞数:", related["like_num"].String(), "\n", + zhiwangjson.Get("data.related.0.reply_url").String(), "\n", + "作者: ", related["m_name"].String(), "\n", + "发表时间: ", time.Unix(int64(related["ctime"].Float()), 0).Format("2006-01-02 15:04:05"), "\n", "查重结果仅作参考,请注意辨别是否为原创", "\n", "数据来源: https://asoulcnki.asia/", )) @@ -63,8 +52,7 @@ func init() { }) } -// 发起api请求并把返回body交由json库解析 -func zhiwangapi(text string) *zhiwang { +func zhiwangapi(text string) *gjson.Result { url := "https://asoulcnki.asia/v1/api/check" post := "{\n\"text\":\"" + text + "\"\n}" var jsonStr = []byte(post) @@ -78,13 +66,13 @@ func zhiwangapi(text string) *zhiwang { if err != nil { return nil } - defer resp.Body.Close() - - result := &zhiwang{} - if err1 := json.NewDecoder(resp.Body).Decode(result); err1 != nil { + bodyBytes, err := io.ReadAll(resp.Body) + if err != nil { return nil } - return result + resp.Body.Close() + result := gjson.ParseBytes(bodyBytes) + return &result } func fullmatch(src ...string) zero.Rule { diff --git a/plugin/setutime/setu_geter.go b/plugin/setutime/setu_geter.go index b8b8b71b..08252b02 100644 --- a/plugin/setutime/setu_geter.go +++ b/plugin/setutime/setu_geter.go @@ -76,7 +76,7 @@ func init() { // 插件主体 } }() - engine.OnRegex(`^来份(.*)$`, ctxext.FirstValueInList(pool)).SetBlock(true).Limit(ctxext.LimitByUser). + engine.OnRegex(`^来份(.+)$`, ctxext.FirstValueInList(pool)).SetBlock(true).Limit(ctxext.LimitByUser). Handle(func(ctx *zero.Ctx) { var imgtype = ctx.State["regex_matched"].([]string)[1] // 补充池子 @@ -96,7 +96,7 @@ func init() { // 插件主体 } }) - engine.OnRegex(`^添加(.*?)(\d+)$`, zero.SuperUserPermission).SetBlock(true). + engine.OnRegex(`^添加(.+)\s?(\d+)$`, zero.SuperUserPermission).SetBlock(true). Handle(func(ctx *zero.Ctx) { var ( imgtype = ctx.State["regex_matched"].([]string)[1] @@ -110,7 +110,7 @@ func init() { // 插件主体 ctx.SendChain(message.Text("成功向分类", imgtype, "添加图片", id)) }) - engine.OnRegex(`^删除(.*?)(\d+)$`, ctxext.FirstValueInList(pool), zero.SuperUserPermission).SetBlock(true). + engine.OnRegex(`^删除(.+)\s?(\d+)$`, ctxext.FirstValueInList(pool), zero.SuperUserPermission).SetBlock(true). Handle(func(ctx *zero.Ctx) { var ( imgtype = ctx.State["regex_matched"].([]string)[1]