@@ -3,10 +3,11 @@ package diana
3
3
4
4
import (
5
5
"bytes"
6
- "encoding/json "
6
+ "io "
7
7
"math"
8
8
"time"
9
9
10
+ "github.com/tidwall/gjson"
10
11
"github.com/wdvxdr1123/ZeroBot/message"
11
12
12
13
"net/http"
@@ -15,17 +16,6 @@ import (
15
16
zero "github.com/wdvxdr1123/ZeroBot"
16
17
)
17
18
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
-
29
19
// 小作文查重: 回复要查的消息 查重
30
20
func init () {
31
21
engine .OnMessage (fullmatch ("查重" )).SetBlock (true ).
@@ -34,37 +24,35 @@ func init() {
34
24
if msg [0 ].Type == "reply" {
35
25
msg := ctx .GetMessage (message .NewMessageID (msg [0 ].Data ["id" ])).Elements [0 ].Data ["text" ]
36
26
zhiwangjson := zhiwangapi (msg )
37
-
38
- if zhiwangjson == nil || zhiwangjson .Code != 0 {
27
+ if zhiwangjson == nil || zhiwangjson .Get ("code" ).Int () != 0 {
39
28
ctx .SendChain (message .Text ("api返回错误" ))
40
29
return
41
30
}
42
31
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%,鉴定为原创 " ))
45
34
return
46
35
}
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 ( )
49
38
ctx .SendChain (message .Text (
50
39
"枝网文本复制检测报告(简洁)" , "\n " ,
51
40
"查重时间: " , 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 " ,
59
48
"查重结果仅作参考,请注意辨别是否为原创" , "\n " ,
60
49
"数据来源: https://asoulcnki.asia/" ,
61
50
))
62
51
}
63
52
})
64
53
}
65
54
66
- // 发起api请求并把返回body交由json库解析
67
- func zhiwangapi (text string ) * zhiwang {
55
+ func zhiwangapi (text string ) * gjson.Result {
68
56
url := "https://asoulcnki.asia/v1/api/check"
69
57
post := "{\n \" text\" :\" " + text + "\" \n }"
70
58
var jsonStr = []byte (post )
@@ -78,13 +66,13 @@ func zhiwangapi(text string) *zhiwang {
78
66
if err != nil {
79
67
return nil
80
68
}
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 {
85
71
return nil
86
72
}
87
- return result
73
+ resp .Body .Close ()
74
+ result := gjson .ParseBytes (bodyBytes )
75
+ return & result
88
76
}
89
77
90
78
func fullmatch (src ... string ) zero.Rule {
0 commit comments