@@ -84,16 +84,18 @@ func init() {
84
84
ctx .SendChain (message .Text ("你钱包没钱啦!" ))
85
85
return
86
86
}
87
- moneyToFavor := rand .Intn (math .Min (walletinfo , 100 ))
87
+ moneyToFavor := rand .Intn (math .Min (walletinfo , 100 )) + 1
88
88
// 计算钱对应的好感值
89
89
newFavor := 1
90
+ moodMax := 2
90
91
if favor > 50 {
91
92
newFavor = moneyToFavor % 10 // 礼物厌倦
92
93
} else {
94
+ moodMax = 5
93
95
newFavor += rand .Intn (moneyToFavor )
94
96
}
95
97
// 随机对方心情
96
- mood := rand .Intn (2 )
98
+ mood := rand .Intn (moodMax )
97
99
if mood == 0 {
98
100
newFavor = - newFavor
99
101
}
@@ -191,6 +193,68 @@ func init() {
191
193
ctx .SendChain (message .ImageBytes (data ))
192
194
cl ()
193
195
})
196
+
197
+ engine .OnFullMatch ("好感度数据整理" , zero .SuperUserPermission , getdb ).SetBlock (true ).Limit (ctxext .LimitByUser ).
198
+ Handle (func (ctx * zero.Ctx ) {
199
+ 民政局 .Lock ()
200
+ defer 民政局 .Unlock ()
201
+ count , err := 民政局 .db .Count ("favorability" )
202
+ if err != nil {
203
+ ctx .SendChain (message .Text ("[ERROR]: " , err ))
204
+ return
205
+ }
206
+ if count == 0 {
207
+ ctx .SendChain (message .Text ("[ERROR]: 不存在好感动数据." ))
208
+ return
209
+ }
210
+ favor := favorability {}
211
+ delInfo := make ([]string , 0 , count * 2 )
212
+ favorInfo := make (map [string ]int , count * 2 )
213
+ _ = 民政局 .db .FindFor ("favorability" , & favor , "group by Userinfo" , func () error {
214
+ delInfo = append (delInfo , favor .Userinfo )
215
+ // 解析旧数据
216
+ userList := strings .Split (favor .Userinfo , "+" )
217
+ if userList [0 ] > userList [1 ] {
218
+ favor .Userinfo = userList [0 ] + "+" + userList [1 ]
219
+ } else {
220
+ favor .Userinfo = userList [1 ] + "+" + userList [0 ]
221
+ }
222
+ // 判断是否是重复的
223
+ score , ok := favorInfo [favor .Userinfo ]
224
+ if ok {
225
+ if score < favor .Favor {
226
+ favorInfo [favor .Userinfo ] = favor .Favor
227
+ }
228
+ } else {
229
+ favorInfo [favor .Userinfo ] = favor .Favor
230
+ }
231
+ return nil
232
+ })
233
+ for _ , updateinfo := range delInfo {
234
+ // 删除旧数据
235
+ err = 民政局 .db .Del ("favorability" , "where Userinfo = '" + updateinfo + "'" )
236
+ if err != nil {
237
+ userList := strings .Split (favor .Userinfo , "+" )
238
+ uid1 , _ := strconv .ParseInt (userList [0 ], 10 , 64 )
239
+ uid2 , _ := strconv .ParseInt (userList [1 ], 10 , 64 )
240
+ ctx .SendChain (message .Text ("[ERROR]: 删除" , ctx .CardOrNickName (uid1 ), "和" , ctx .CardOrNickName (uid2 ), "的好感动时发生了错误。\n 错误信息:" , err ))
241
+ }
242
+ }
243
+ for userInfo , favor := range favorInfo {
244
+ favorInfo := favorability {
245
+ Userinfo : userInfo ,
246
+ Favor : favor ,
247
+ }
248
+ err = 民政局 .db .Insert ("favorability" , & favorInfo )
249
+ if err != nil {
250
+ userList := strings .Split (userInfo , "+" )
251
+ uid1 , _ := strconv .ParseInt (userList [0 ], 10 , 64 )
252
+ uid2 , _ := strconv .ParseInt (userList [1 ], 10 , 64 )
253
+ ctx .SendChain (message .Text ("[ERROR]: 更新" , ctx .CardOrNickName (uid1 ), "和" , ctx .CardOrNickName (uid2 ), "的好感动时发生了错误。\n 错误信息:" , err ))
254
+ }
255
+ }
256
+ ctx .SendChain (message .Text ("清理好了哦" ))
257
+ })
194
258
}
195
259
196
260
func (sql * 婚姻登记 ) 查好感度 (uid , target int64 ) (int , error ) {
@@ -201,9 +265,19 @@ func (sql *婚姻登记) 查好感度(uid, target int64) (int, error) {
201
265
return 0 , err
202
266
}
203
267
info := favorability {}
204
- uidstr := strconv .FormatInt (uid , 10 )
205
- targstr := strconv .FormatInt (target , 10 )
206
- _ = sql .db .Find ("favorability" , & info , "where Userinfo glob '*" + uidstr + "+" + targstr + "*'" )
268
+ if uid > target {
269
+ userinfo := strconv .FormatInt (uid , 10 ) + "+" + strconv .FormatInt (target , 10 )
270
+ err = sql .db .Find ("favorability" , & info , "where Userinfo is '" + userinfo + "'" )
271
+ if err != nil {
272
+ _ = sql .db .Find ("favorability" , & info , "where Userinfo glob '*" + userinfo + "*'" )
273
+ }
274
+ } else {
275
+ userinfo := strconv .FormatInt (target , 10 ) + "+" + strconv .FormatInt (uid , 10 )
276
+ err = sql .db .Find ("favorability" , & info , "where Userinfo is '" + userinfo + "'" )
277
+ if err != nil {
278
+ _ = sql .db .Find ("favorability" , & info , "where Userinfo glob '*" + userinfo + "*'" )
279
+ }
280
+ }
207
281
return info .Favor , nil
208
282
}
209
283
@@ -256,8 +330,19 @@ func (sql *婚姻登记) 更新好感度(uid, target int64, score int) (favor in
256
330
info := favorability {}
257
331
uidstr := strconv .FormatInt (uid , 10 )
258
332
targstr := strconv .FormatInt (target , 10 )
259
- _ = sql .db .Find ("favorability" , & info , "where Userinfo glob '*" + uidstr + "+" + targstr + "*'" )
260
- info .Userinfo = uidstr + "+" + targstr + "+" + uidstr
333
+ if uid > target {
334
+ info .Userinfo = uidstr + "+" + targstr
335
+ err = sql .db .Find ("favorability" , & info , "where Userinfo is '" + info .Userinfo + "'" )
336
+ } else {
337
+ info .Userinfo = targstr + "+" + uidstr
338
+ err = sql .db .Find ("favorability" , & info , "where Userinfo is '" + info .Userinfo + "'" )
339
+ }
340
+ if err != nil {
341
+ err = sql .db .Find ("favorability" , & info , "where Userinfo glob '*" + targstr + "+" + uidstr + "*'" )
342
+ if err == nil { // 如果旧数据存在就删除旧数据
343
+ err = 民政局 .db .Del ("favorability" , "where Userinfo = '" + info .Userinfo + "'" )
344
+ }
345
+ }
261
346
info .Favor += score
262
347
if info .Favor > 100 {
263
348
info .Favor = 100
0 commit comments