mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-18 20:50:12 +08:00
Improve the judgment of robbery failure (#931)
* Improve the judgment of robbery failure 完善打劫失败判断,会返回更详细的提示信息。 打劫失败 - case1:受害者已经被打劫过了 tip:对方今天已经被打劫了,给人家的钱包留点后路吧 - case2:劫匪已经打劫过人了 tip:你今天已经成功打劫过了,贪心没有好果汁吃 - case3:受害者已经被打劫过了&&劫匪已经打劫过人了 tip:同case2 * Update README.md : remove go-cqhttp 去掉readme里go-cqhttp相关介绍
This commit is contained in:
parent
7a3589e26d
commit
18f77165ec
@ -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) 环境
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user