4
4
"MiniBot/utils/path"
5
5
zero "ZeroBot"
6
6
"encoding/json"
7
+ "fmt"
7
8
"math/rand/v2"
8
9
"os"
9
10
"path/filepath"
@@ -12,6 +13,7 @@ import (
12
13
"ZeroBot/message"
13
14
14
15
"github.com/rs/zerolog/log"
16
+ "github.com/xrash/smetrics"
15
17
)
16
18
17
19
var (
21
23
[病情查重 小作文] 对一篇小作文进行查重
22
24
`
23
25
24
- // [<回复一个小作文> 病情查重] 同上
26
+ // [<回复一个小作文> 病情查重] 同上
27
+ pluginName = "asill"
25
28
)
26
29
27
30
type asillData struct {
@@ -46,11 +49,11 @@ func init() {
46
49
}
47
50
48
51
engine := zero .NewTemplate (& zero.MetaData {
49
- Name : "asill" ,
52
+ Name : pluginName ,
50
53
Help : help ,
51
54
})
52
55
53
- engine .OnPrefix (`发病` ).SetBlock (true ).Handle (func (ctx * zero.Ctx ) {
56
+ engine .OnPrefix ("发病" ).SetBlock (true ).Handle (func (ctx * zero.Ctx ) {
54
57
name := ctx .NickName ()
55
58
n := rand .IntN (len (data ))
56
59
asilldata := data [n ]
@@ -60,13 +63,47 @@ func init() {
60
63
ctx .SendChain (message .Reply (ctx .Event .MessageID ), message .Text (asillText ))
61
64
})
62
65
63
- // engine.OnPrefix(` 病情查重` ).SetBlock(true).Handle(func(ctx *zero.Ctx) {
64
- // name := ctx.NickName( )
65
- // n := rand.IntN(len(data))
66
- // asilldata := data[n]
67
- // asillText := asilldata.Text
68
- // asillText = strings.Replace(asillText, asilldata.Person, name, -1)
66
+ engine .OnPrefix (" 病情查重" ).SetBlock (true ).Handle (func (ctx * zero.Ctx ) {
67
+ msg := ctx .State [ "args" ].( string )
68
+ if ctx . Event . Message [ 0 ]. Type == "reply" {
69
+ replyMsg := ctx . GetMessage ( ctx . Event . Message [ 0 ]. Data [ "id" ])
70
+ msg = replyMsg . Elements . ExtractPlainText ()
71
+ }
69
72
70
- // ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(asillText))
71
- // })
73
+ for _ , unit := range data {
74
+ rate := smetrics .Jaro (unit .Text , msg )
75
+ if rate > 0.6 {
76
+ ctx .SendChain (message .Text (fmt .Sprintf ("在本文库中,总文字复制比:%f \n 相似小作文:\n %s" , 100 * rate , unit .Text )))
77
+ return
78
+ }
79
+ }
80
+ ctx .SendChain (message .Text ("文库内没有相似的小作文" ))
81
+ })
82
+
83
+ engine .OnPrefix ("病情加重" , zero .SuperUserPermission ).SetBlock (true ).Handle (
84
+ func (ctx * zero.Ctx ) {
85
+ msg := ctx .State ["args" ].(string )
86
+ msgs := strings .Split (msg , "/" )
87
+ if len (msgs ) != 2 {
88
+ ctx .SendChain (message .Text ("请发送[病情加重 对象/小作文](必须带“/”)~" ))
89
+ return
90
+ }
91
+ keyWord := msgs [0 ]
92
+ data = append (data , asillData {
93
+ Person : keyWord ,
94
+ Text : msgs [1 ],
95
+ })
96
+ rawdata , err = json .MarshalIndent (data , "" , " " )
97
+ if err != nil {
98
+ ctx .SendError (err )
99
+ return
100
+ }
101
+ err := os .WriteFile (dataPath , rawdata , 0555 )
102
+ if err != nil {
103
+ ctx .SendError (err )
104
+ return
105
+ }
106
+ ctx .SendChain (message .Text ("病情已添加" ))
107
+ },
108
+ )
72
109
}
0 commit comments