Skip to content

Commit 0698d8e

Browse files
shudorclfumiama
andauthored
fix:修复了枝网查重无法使用的问题 (#175)
* 优化在两个命令中使用空格分隔的体验 - 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: 源文雨 <[email protected]>
1 parent 8e4c496 commit 0698d8e

File tree

3 files changed

+24
-36
lines changed

3 files changed

+24
-36
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ print("run[CQ:image,file="+j["img"]+"]")
148148
- [x] 退出群聊[群号]@Bot
149149
- [x] *入群欢迎
150150
- [x] *退群通知
151-
- [x] 设置欢迎语[欢迎~] 可选添加 [{at}] [{nickname}] [{avatar}]
151+
- [x] 设置欢迎语[欢迎~] 可选添加 [{at}] [{nickname}] [{avatar}] [{id}]
152152
- [x][MM][dd]日的[hh][mm]分时(用[url])提醒大家[xxx]
153153
- [x][MM][每周 | 周几][hh][mm]分时(用[url])提醒大家[xxx]
154154
- [x] 取消在[MM][dd]日的[hh][mm]分的提醒

plugin/diana/zhiwang.go

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package diana
33

44
import (
55
"bytes"
6-
"encoding/json"
6+
"io"
77
"math"
88
"time"
99

10+
"github.com/tidwall/gjson"
1011
"github.com/wdvxdr1123/ZeroBot/message"
1112

1213
"net/http"
@@ -15,17 +16,6 @@ import (
1516
zero "github.com/wdvxdr1123/ZeroBot"
1617
)
1718

18-
type zhiwang struct {
19-
Code int `json:"code"`
20-
Data struct {
21-
EndTime int `json:"end_time"`
22-
Rate float64 `json:"rate"`
23-
Related [][]interface{} `json:"related"`
24-
StartTime int `json:"start_time"`
25-
} `json:"data"`
26-
Message string `json:"message"`
27-
}
28-
2919
// 小作文查重: 回复要查的消息 查重
3020
func init() {
3121
engine.OnMessage(fullmatch("查重")).SetBlock(true).
@@ -34,37 +24,35 @@ func init() {
3424
if msg[0].Type == "reply" {
3525
msg := ctx.GetMessage(message.NewMessageID(msg[0].Data["id"])).Elements[0].Data["text"]
3626
zhiwangjson := zhiwangapi(msg)
37-
38-
if zhiwangjson == nil || zhiwangjson.Code != 0 {
27+
if zhiwangjson == nil || zhiwangjson.Get("code").Int() != 0 {
3928
ctx.SendChain(message.Text("api返回错误"))
4029
return
4130
}
4231

43-
if len(zhiwangjson.Data.Related) == 0 {
44-
ctx.SendChain(message.Text("枝网没搜到,查重率为0%,我的评价是:一眼真"))
32+
if zhiwangjson.Get("data.related.#").Int() == 0 {
33+
ctx.SendChain(message.Text("枝网没搜到,查重率为0%,鉴定为原创"))
4534
return
4635
}
47-
48-
related := zhiwangjson.Data.Related[0][1].(map[string]interface{})
36+
related := zhiwangjson.Get("data.related.0.reply").Map()
37+
rate := zhiwangjson.Get("data.related.0.rate").Float()
4938
ctx.SendChain(message.Text(
5039
"枝网文本复制检测报告(简洁)", "\n",
5140
"查重时间: ", time.Now().Format("2006-01-02 15:04:05"), "\n",
52-
"总文字复制比: ", math.Floor(zhiwangjson.Data.Rate*100), "%", "\n",
53-
"相似小作文:", "\n",
54-
related["content"].(string)[:102]+".....", "\n",
55-
"获赞数", related["like_num"], "\n",
56-
zhiwangjson.Data.Related[0][2].(string), "\n",
57-
"作者: ", related["m_name"], "\n",
58-
"发表时间: ", time.Unix(int64(related["ctime"].(float64)), 0).Format("2006-01-02 15:04:05"), "\n",
41+
"总文字复制比: ", math.Floor(rate*100), "%", "\n",
42+
"相似小作文", "\n",
43+
related["content"].String()[:102]+".....", "\n",
44+
"获赞数", related["like_num"].String(), "\n",
45+
zhiwangjson.Get("data.related.0.reply_url").String(), "\n",
46+
"作者: ", related["m_name"].String(), "\n",
47+
"发表时间: ", time.Unix(int64(related["ctime"].Float()), 0).Format("2006-01-02 15:04:05"), "\n",
5948
"查重结果仅作参考,请注意辨别是否为原创", "\n",
6049
"数据来源: https://asoulcnki.asia/",
6150
))
6251
}
6352
})
6453
}
6554

66-
// 发起api请求并把返回body交由json库解析
67-
func zhiwangapi(text string) *zhiwang {
55+
func zhiwangapi(text string) *gjson.Result {
6856
url := "https://asoulcnki.asia/v1/api/check"
6957
post := "{\n\"text\":\"" + text + "\"\n}"
7058
var jsonStr = []byte(post)
@@ -78,13 +66,13 @@ func zhiwangapi(text string) *zhiwang {
7866
if err != nil {
7967
return nil
8068
}
81-
defer resp.Body.Close()
82-
83-
result := &zhiwang{}
84-
if err1 := json.NewDecoder(resp.Body).Decode(result); err1 != nil {
69+
bodyBytes, err := io.ReadAll(resp.Body)
70+
if err != nil {
8571
return nil
8672
}
87-
return result
73+
resp.Body.Close()
74+
result := gjson.ParseBytes(bodyBytes)
75+
return &result
8876
}
8977

9078
func fullmatch(src ...string) zero.Rule {

plugin/setutime/setu_geter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func init() { // 插件主体
7676
}
7777
}()
7878

79-
engine.OnRegex(`^来份(.*)$`, ctxext.FirstValueInList(pool)).SetBlock(true).Limit(ctxext.LimitByUser).
79+
engine.OnRegex(`^来份(.+)$`, ctxext.FirstValueInList(pool)).SetBlock(true).Limit(ctxext.LimitByUser).
8080
Handle(func(ctx *zero.Ctx) {
8181
var imgtype = ctx.State["regex_matched"].([]string)[1]
8282
// 补充池子
@@ -96,7 +96,7 @@ func init() { // 插件主体
9696
}
9797
})
9898

99-
engine.OnRegex(`^添加(.*?)(\d+)$`, zero.SuperUserPermission).SetBlock(true).
99+
engine.OnRegex(`^添加(.+)\s?(\d+)$`, zero.SuperUserPermission).SetBlock(true).
100100
Handle(func(ctx *zero.Ctx) {
101101
var (
102102
imgtype = ctx.State["regex_matched"].([]string)[1]
@@ -110,7 +110,7 @@ func init() { // 插件主体
110110
ctx.SendChain(message.Text("成功向分类", imgtype, "添加图片", id))
111111
})
112112

113-
engine.OnRegex(`^删除(.*?)(\d+)$`, ctxext.FirstValueInList(pool), zero.SuperUserPermission).SetBlock(true).
113+
engine.OnRegex(`^删除(.+)\s?(\d+)$`, ctxext.FirstValueInList(pool), zero.SuperUserPermission).SetBlock(true).
114114
Handle(func(ctx *zero.Ctx) {
115115
var (
116116
imgtype = ctx.State["regex_matched"].([]string)[1]

0 commit comments

Comments
 (0)