mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-20 06:20:08 +08:00
Update text.go
This commit is contained in:
parent
83199cf3aa
commit
ebd5555955
@ -26,7 +26,7 @@ var (
|
|||||||
// m 小作文保存锁
|
// m 小作文保存锁
|
||||||
m sync.Mutex
|
m sync.Mutex
|
||||||
// md5s 验证重复
|
// md5s 验证重复
|
||||||
md5s [][16]byte
|
md5s []*[16]byte
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -40,9 +40,10 @@ func init() {
|
|||||||
if err1 == nil {
|
if err1 == nil {
|
||||||
arrl := len(*Array)
|
arrl := len(*Array)
|
||||||
log.Printf("[Diana]读取%d条小作文", arrl)
|
log.Printf("[Diana]读取%d条小作文", arrl)
|
||||||
md5s = make([][16]byte, arrl)
|
md5s = make([]*[16]byte, arrl)
|
||||||
for i, t := range *Array {
|
for i, t := range *Array {
|
||||||
md5s[i] = md5.Sum(str2bytes(t))
|
m := md5.Sum(str2bytes(t))
|
||||||
|
md5s[i] = &m
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Printf("[Diana]读取小作文错误:%v", err1)
|
log.Printf("[Diana]读取小作文错误:%v", err1)
|
||||||
@ -92,19 +93,19 @@ func LoadText() error {
|
|||||||
// AddText 添加小作文
|
// AddText 添加小作文
|
||||||
func AddText(txt string) error {
|
func AddText(txt string) error {
|
||||||
sum := md5.Sum(str2bytes(txt))
|
sum := md5.Sum(str2bytes(txt))
|
||||||
if txt != "" && !isin(sum) {
|
if txt != "" && !isin(&sum) {
|
||||||
m.Lock()
|
m.Lock()
|
||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
compo.Array = append(compo.Array, txt)
|
compo.Array = append(compo.Array, txt)
|
||||||
md5s = append(md5s, sum)
|
md5s = append(md5s, &sum)
|
||||||
return savecompo()
|
return savecompo()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func isin(sum [16]byte) bool {
|
func isin(sum *[16]byte) bool {
|
||||||
for _, t := range md5s {
|
for _, t := range md5s {
|
||||||
if t == sum {
|
if *t == *sum {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user