@@ -81,7 +81,7 @@ func init() {
81
81
for {
82
82
select {
83
83
case <- timer .C :
84
- ctx .SendChain (message .At (uid ), message .Text (" 超时, 已自动取消" ))
84
+ ctx .SendChain (message .At (uid ), message .Text (" 超时, 已自动取消" ))
85
85
return
86
86
case r := <- recv :
87
87
answer = r .Event .Message .String ()
@@ -109,6 +109,12 @@ func init() {
109
109
ctx .SendChain (message .Text ("ERROR:" , err ))
110
110
return
111
111
}
112
+ // 数据库操作成功之后,及时删除残留的缓存
113
+ key := fmt .Sprintf ("%d_%d" , gid , uid )
114
+ _ , ok := jjCount .Load (key )
115
+ if ok {
116
+ jjCount .Delete (key )
117
+ }
112
118
ctx .SendChain (message .Reply (ctx .Event .MessageID ), message .Text (sell ))
113
119
})
114
120
en .OnFullMatch ("牛牛背包" , zero .OnlyGroup ).SetBlock (true ).Handle (func (ctx * zero.Ctx ) {
@@ -165,7 +171,7 @@ func init() {
165
171
for {
166
172
select {
167
173
case <- timer .C :
168
- ctx .SendChain (message .At (uid ), message .Text (" 超时, 已自动取消" ))
174
+ ctx .SendChain (message .At (uid ), message .Text (" 超时, 已自动取消" ))
169
175
return
170
176
case r := <- recv :
171
177
answer = r .Event .Message .String ()
@@ -196,16 +202,16 @@ func init() {
196
202
}
197
203
198
204
if time .Since (last .TimeLimit ) > time .Hour {
199
- ctx .SendChain (message .Text ("时间已经过期了, 牛牛已被收回!" ))
205
+ ctx .SendChain (message .Text ("时间已经过期了, 牛牛已被收回!" ))
200
206
jjCount .Delete (fmt .Sprintf ("%d_%d" , gid , uid ))
201
207
return
202
208
}
203
209
204
210
if last .Count < 4 {
205
- ctx .SendChain (message .Text ("你还没有被厥够4次呢, 不能赎牛牛" ))
211
+ ctx .SendChain (message .Text ("你还没有被厥够4次呢, 不能赎牛牛" ))
206
212
return
207
213
}
208
- ctx .SendChain (message .Text ("再次确认一下哦, 这次赎牛牛,牛牛长度将会变成" , last .Length , "cm\n 还需要嘛【是|否】" ))
214
+ ctx .SendChain (message .Text ("再次确认一下哦, 这次赎牛牛,牛牛长度将会变成" , last .Length , "cm\n 还需要嘛【是|否】" ))
209
215
recv , cancel := zero .NewFutureEvent ("message" , 999 , false , zero .CheckUser (uid ), zero .CheckGroup (gid ), zero .RegexRule (`^(是|否)$` )).Repeat ()
210
216
defer cancel ()
211
217
timer := time .NewTimer (2 * time .Minute )
@@ -222,11 +228,11 @@ func init() {
222
228
return
223
229
}
224
230
225
- if err := niu .Redeem (gid , uid , last .Length ); err = = nil {
231
+ if err := niu .Redeem (gid , uid , last .Length ); err ! = nil {
226
232
ctx .SendChain (message .Text ("ERROR:" , err ))
227
233
return
228
234
}
229
-
235
+ // 成功赎回,删除残留的缓存。
230
236
jjCount .Delete (fmt .Sprintf ("%d_%d" , gid , uid ))
231
237
232
238
ctx .SendChain (message .At (uid ), message .Text (fmt .Sprintf ("恭喜你!成功赎回牛牛,当前长度为:%.2fcm" , last .Length )))
@@ -342,8 +348,9 @@ func init() {
342
348
j := fmt .Sprintf ("%d_%d" , gid , adduser )
343
349
count , ok := jjCount .Load (j )
344
350
var c lastLength
345
- // 按照最后一次被jj时的时间计算 ,超过60分钟则重置
351
+ // 按照最后一次被 jj 时的时间计算 ,超过60分钟则重置
346
352
if ! ok {
353
+ // 第一次被 jj
347
354
c = lastLength {
348
355
TimeLimit : time .Now (),
349
356
Count : 1 ,
@@ -355,6 +362,7 @@ func init() {
355
362
Count : count .Count + 1 ,
356
363
Length : count .Length ,
357
364
}
365
+ // 超时了,重置
358
366
if time .Since (c .TimeLimit ) > time .Hour {
359
367
c = lastLength {
360
368
TimeLimit : time .Now (),
0 commit comments