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]