Skip to content

Commit

Permalink
Improve the judgment of robbery failure (#931)
Browse files Browse the repository at this point in the history
* Improve the judgment of robbery failure

完善打劫失败判断,会返回更详细的提示信息。
打劫失败
- case1:受害者已经被打劫过了
tip:对方今天已经被打劫了,给人家的钱包留点后路吧

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

-  case3:受害者已经被打劫过了&&劫匪已经打劫过人了
tip:同case2

* Update README.md : remove go-cqhttp

去掉readme里go-cqhttp相关介绍
  • Loading branch information
vatebur authored Jul 18, 2024
1 parent 7a3589e commit 18f7716
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1547,8 +1547,7 @@ print("run[CQ:image,file="+j["img"]+"]")

### 1. 使用稳定版/测试版 (推荐)

可以前往[Release](https://github.com/FloatTech/ZeroBot-Plugin/releases)页面下载对应系统版本可执行文件,编译时开启了全部插件。您还可以选择 [gocqzbp](https://github.com/FloatTech/gocqzbp)[Release](https://github.com/FloatTech/gocqzbp/releases)[Package](https://github.com/FloatTech/gocqzbp/pkgs/container/gocqzbp),它是 [Mrs4s/go-cqhttp](https://github.com/Mrs4s/go-cqhttp) 与本插件的合体。

可以前往[Release](https://github.com/FloatTech/ZeroBot-Plugin/releases)页面下载对应系统版本可执行文件,编译时开启了全部插件。
### 2. 本地直接运行

1. 下载安装最新 [Go](https://studygolang.com/dl) 环境
Expand Down
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 18f7716

Please sign in to comment.