Skip to content

Commit

Permalink
Improve the judgment of robbery failure
Browse files Browse the repository at this point in the history
完善打劫失败判断,会返回更详细的提示信息。
打劫失败
- case1:受害者已经被打劫过了
tip:对方今天已经被打劫了,给人家的钱包留点后路吧

- case2:劫匪已经打劫过人了
tip:你今天已经成功打劫过了,贪心没有好果汁吃

-  case3:受害者已经被打劫过了&&劫匪已经打劫过人了
tip:同case2
  • Loading branch information
vatebur committed Jul 17, 2024
1 parent 7a3589e commit 38f8c89
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions plugin/robbery/robbery.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,13 @@ func init() {
ctx.SendChain(message.Text("[ERROR]:", err))
return
}
if !ok {
ctx.SendChain(message.Text("你已经打劫过了/对方已经被打劫过了"))

if ok == 1 {
ctx.SendChain(message.Text("对方今天已经被打劫了,给人家留点后路吧"))
return
}
if ok >= 2 {
ctx.SendChain(message.Text("你今天已经成功打劫过了,贪心没有好果汁吃!"))
return
}

Expand Down Expand Up @@ -142,28 +147,42 @@ func init() {
})
}

func (sql *robberyRepo) getRecord(victimID, uid int64) (ok bool, err error) {
// ok==0 可以打劫;ok==1 程序错误 or 受害者进入CD;ok==2 用户进入CD; ok==3 用户和受害者都进入CD;
func (sql *robberyRepo) getRecord(victimID, uid int64) (ok int, err error) {
sql.Lock()
defer sql.Unlock()
// 创建群表格
err = sql.db.Create("criminal_record", &robberyRecord{})
if err != nil {
return false, err
return 1, err
}
// 拼接查询SQL
limitID := "where victim_id is " + strconv.FormatInt(victimID, 10) +
" or user_id is " + strconv.FormatInt(uid, 10)
if !sql.db.CanFind("criminal_record", limitID) {
// 没有记录即不用比较
return true, nil
return 0, nil
}
cdinfo := robberyRecord{}
_ = sql.db.Find("criminal_record", &cdinfo, limitID)
if time.Now().Format("2006/01/02") != cdinfo.Time {
// // 如果跨天了就删除
err = sql.db.Del("criminal_record", limitID)
return true, err
}
return false, nil

err = sql.db.FindFor("criminal_record", &cdinfo, limitID, func() error {
if time.Now().Format("2006/01/02") != cdinfo.Time {
// // 如果跨天了就删除
err = sql.db.Del("criminal_record", limitID)
return nil
}
// 俩个if是为了保证,重复打劫同一个人,ok == 3
if cdinfo.UserID == uid {
ok += 2
}
if cdinfo.VictimID == victimID {
// lint 不允许使用 ok += 1
ok++
}
return nil
})
return ok, err

}

func (sql *robberyRepo) insertRecord(vid int64, uid int64) error {
Expand Down

0 comments on commit 38f8c89

Please sign in to comment.