@@ -81,7 +81,7 @@ func init() {
8181 for {
8282 select {
8383 case <- timer .C :
84- ctx .SendChain (message .At (uid ), message .Text (" 超时, 已自动取消" ))
84+ ctx .SendChain (message .At (uid ), message .Text (" 超时, 已自动取消" ))
8585 return
8686 case r := <- recv :
8787 answer = r .Event .Message .String ()
@@ -109,6 +109,12 @@ func init() {
109109 ctx .SendChain (message .Text ("ERROR:" , err ))
110110 return
111111 }
112+ // 数据库操作成功之后,及时删除残留的缓存
113+ key := fmt .Sprintf ("%d_%d" , gid , uid )
114+ _ , ok := jjCount .Load (key )
115+ if ok {
116+ jjCount .Delete (key )
117+ }
112118 ctx .SendChain (message .Reply (ctx .Event .MessageID ), message .Text (sell ))
113119 })
114120 en .OnFullMatch ("牛牛背包" , zero .OnlyGroup ).SetBlock (true ).Handle (func (ctx * zero.Ctx ) {
@@ -165,7 +171,7 @@ func init() {
165171 for {
166172 select {
167173 case <- timer .C :
168- ctx .SendChain (message .At (uid ), message .Text (" 超时, 已自动取消" ))
174+ ctx .SendChain (message .At (uid ), message .Text (" 超时, 已自动取消" ))
169175 return
170176 case r := <- recv :
171177 answer = r .Event .Message .String ()
@@ -196,16 +202,16 @@ func init() {
196202 }
197203
198204 if time .Since (last .TimeLimit ) > time .Hour {
199- ctx .SendChain (message .Text ("时间已经过期了, 牛牛已被收回!" ))
205+ ctx .SendChain (message .Text ("时间已经过期了, 牛牛已被收回!" ))
200206 jjCount .Delete (fmt .Sprintf ("%d_%d" , gid , uid ))
201207 return
202208 }
203209
204210 if last .Count < 4 {
205- ctx .SendChain (message .Text ("你还没有被厥够4次呢, 不能赎牛牛" ))
211+ ctx .SendChain (message .Text ("你还没有被厥够4次呢, 不能赎牛牛" ))
206212 return
207213 }
208- ctx .SendChain (message .Text ("再次确认一下哦, 这次赎牛牛,牛牛长度将会变成" , last .Length , "cm\n 还需要嘛【是|否】" ))
214+ ctx .SendChain (message .Text ("再次确认一下哦, 这次赎牛牛,牛牛长度将会变成" , last .Length , "cm\n 还需要嘛【是|否】" ))
209215 recv , cancel := zero .NewFutureEvent ("message" , 999 , false , zero .CheckUser (uid ), zero .CheckGroup (gid ), zero .RegexRule (`^(是|否)$` )).Repeat ()
210216 defer cancel ()
211217 timer := time .NewTimer (2 * time .Minute )
@@ -222,11 +228,11 @@ func init() {
222228 return
223229 }
224230
225- if err := niu .Redeem (gid , uid , last .Length ); err = = nil {
231+ if err := niu .Redeem (gid , uid , last .Length ); err ! = nil {
226232 ctx .SendChain (message .Text ("ERROR:" , err ))
227233 return
228234 }
229-
235+ // 成功赎回,删除残留的缓存。
230236 jjCount .Delete (fmt .Sprintf ("%d_%d" , gid , uid ))
231237
232238 ctx .SendChain (message .At (uid ), message .Text (fmt .Sprintf ("恭喜你!成功赎回牛牛,当前长度为:%.2fcm" , last .Length )))
@@ -342,8 +348,9 @@ func init() {
342348 j := fmt .Sprintf ("%d_%d" , gid , adduser )
343349 count , ok := jjCount .Load (j )
344350 var c lastLength
345- // 按照最后一次被jj时的时间计算 ,超过60分钟则重置
351+ // 按照最后一次被 jj 时的时间计算 ,超过60分钟则重置
346352 if ! ok {
353+ // 第一次被 jj
347354 c = lastLength {
348355 TimeLimit : time .Now (),
349356 Count : 1 ,
@@ -355,6 +362,7 @@ func init() {
355362 Count : count .Count + 1 ,
356363 Length : count .Length ,
357364 }
365+ // 超时了,重置
358366 if time .Since (c .TimeLimit ) > time .Hour {
359367 c = lastLength {
360368 TimeLimit : time .Now (),
0 commit comments