Skip to content

Commit

Permalink
feat:qqwife 提示cd时间
Browse files Browse the repository at this point in the history
  • Loading branch information
Azusa-Yuan committed Oct 4, 2024
1 parent 4d9397b commit 7069810
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
8 changes: 4 additions & 4 deletions plugin/qqwife/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,20 +579,20 @@ func init() {
// 去qqwife登记
err = qqwife.SaveMarriageInfo(gid, gayOne, gayZero, ctx.CardOrNickName(gayOne), ctx.CardOrNickName(gayZero))
if err != nil {
ctx.SendChain(message.Text("[ERROR]:", err))
ctx.SendError(err)
return
}
_, err = qqwife.UpdateFavorability(uid, gayOne, 1)
if err != nil {
ctx.SendChain(message.Text("[ERROR]:", err))
ctx.SendError(err)
}
_, err = qqwife.UpdateFavorability(uid, gayZero, 1)
if err != nil {
ctx.SendChain(message.Text("[ERROR]:", err))
ctx.SendError(err)
}
_, err = qqwife.UpdateFavorability(gayOne, gayZero, 1)
if err != nil {
ctx.SendChain(message.Text("[ERROR]:", err))
ctx.SendError(err)
}
// 请大家吃席
go func() {
Expand Down
7 changes: 4 additions & 3 deletions plugin/qqwife/favor_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ func init() {
ctx.SendError(err)
return
}
ok, err := qqwife.JudgeCD(gid, uid, "买礼物", groupInfo.CDtime)
timeMin, err := qqwife.JudgeCD(gid, uid, "买礼物", groupInfo.CDtime)
if err != nil {
ctx.SendError(err)
return
}
if !ok {
ctx.SendChain(message.Text("舔狗,今天你已经送过礼物了。"))

if timeMin > 0 {
ctx.SendChain(message.Text(fmt.Sprintf("舔狗,今天你已经送过礼物了。等%d分钟再舔吧", timeMin)))
return
}
// 获取好感度
Expand Down
24 changes: 12 additions & 12 deletions plugin/qqwife/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ func checkSingleDog(gid int64, uid int64, fiancee int64) (res bool, msg string)
return
}
// JudgeCD
ok, err := qqwife.JudgeCD(gid, uid, "嫁娶", dbinfo.CDtime)
timeMin, err := qqwife.JudgeCD(gid, uid, "嫁娶", dbinfo.CDtime)

if err != nil {
msg = fmt.Sprint("[ERROR]:", err)
return
}

if !ok {
msg = "你的技能还在CD中..."
if timeMin > 0 {
msg = fmt.Sprintf("你的技能CD还有%d分钟", timeMin)
return
}

Expand Down Expand Up @@ -130,13 +130,13 @@ func checkMistress(ctx *zero.Ctx) (ok bool, targetInfo UserInfo) {
return
}
// JudgeCD
cdOK, err := qqwife.JudgeCD(gid, uid, "NTR", groupInfo.CDtime)
timeMin, err := qqwife.JudgeCD(gid, uid, "NTR", groupInfo.CDtime)
switch {
case err != nil:
ctx.SendChain(message.Text("[ERROR]:", err))
return
case !cdOK:
ctx.SendChain(message.Text("你的技能还在CD中..."))
case timeMin > 0:
ctx.SendChain(message.Text(fmt.Sprintf("黄毛小子在休息%d分钟吧", timeMin)))
return
}
// 获取用户信息
Expand Down Expand Up @@ -185,13 +185,13 @@ func checkDivorce(ctx *zero.Ctx) bool {
ctx.SendChain(message.Text("[ERROR]:", err))
return false
}
ok, err := qqwife.JudgeCD(gid, uid, "离婚", groupInfo.CDtime)
timeMin, err := qqwife.JudgeCD(gid, uid, "离婚", groupInfo.CDtime)
switch {
case err != nil:
ctx.SendChain(message.Text("[ERROR]:", err))
return false
case !ok:
ctx.SendChain(message.Text("你的技能还在CD中..."))
case timeMin > 0:
ctx.SendChain(message.Text(fmt.Sprintf("你的技能CD还有%d分钟", timeMin)))
return false
}
return true
Expand Down Expand Up @@ -240,13 +240,13 @@ func checkMatchmaker(ctx *zero.Ctx) bool {
ctx.SendChain(message.Text("[ERROR]:", err))
return false
}
ok, err := qqwife.JudgeCD(gid, uid, "做媒", groupInfo.CDtime)
timeMin, err := qqwife.JudgeCD(gid, uid, "做媒", groupInfo.CDtime)
switch {
case err != nil:
ctx.SendChain(message.Text("[ERROR]:", err))
return false
case !ok:
ctx.SendChain(message.Text("你的技能还在CD中..."))
case timeMin > 0:
ctx.SendChain(message.Text(fmt.Sprintf("你的技能CD还有%d分钟", timeMin)))
return false
}
qqwife.RLock()
Expand Down
14 changes: 8 additions & 6 deletions plugin/qqwife/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,24 +236,26 @@ func (sql *QQWife) GetAllInfo(gid int64) (list []UserInfo, err error) {
// }
// }

func (sql *QQWife) JudgeCD(gid, uid int64, mode string, cdtime float64) (ok bool, err error) {
func (sql *QQWife) JudgeCD(gid, uid int64, mode string, cdtime float64) (timeMin int, err error) {

cdinfo := CdSheet{}
res := sql.db.Where("gid = ? AND uid = ? AND mode_id = ?", gid, uid, mode).First(&cdinfo)
if res.RowsAffected == 0 {
// 没有记录即不用比较
return true, nil
return -1, nil
}

if time.Since(time.Unix(cdinfo.Time, 0)).Hours() > cdtime {
timeMin = int(60 * (cdtime - time.Since(time.Unix(cdinfo.Time, 0)).Hours()))

if timeMin < 0 {
// 如果CD已过就删除
err = sql.db.Delete(&cdinfo).Error
if err != nil {
return false, err
return
}
return true, nil
return
}
return false, nil
return
}

func (sql *QQWife) SaveCD(gid, uid int64, mode string) error {
Expand Down

0 comments on commit 7069810

Please sign in to comment.