From faf00dfea73c1b8b090051dd144c304243350cba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B9=E6=9F=B3=E7=85=9C?= <101934327+fangliuyu@users.noreply.github.com> Date: Tue, 31 Jan 2023 16:23:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=A5=BD=E6=84=9F=E5=BA=A6?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F,=E4=BF=AE=E5=A4=8D=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E4=BA=BA=E5=90=8D=E9=97=AE=E9=A2=98=20(#568)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/qqwife/command.go | 2 +- plugin/qqwife/favorSystem.go | 99 +++++++++++++++++++++++++++++++++--- 2 files changed, 93 insertions(+), 8 deletions(-) diff --git a/plugin/qqwife/command.go b/plugin/qqwife/command.go index bec08cb0b5..249aa6234e 100644 --- a/plugin/qqwife/command.go +++ b/plugin/qqwife/command.go @@ -60,7 +60,7 @@ var ( engine = control.Register("qqwife", &ctrl.Options[*zero.Ctx]{ DisableOnDefault: false, Brief: "一群一天一夫一妻制群老婆", - Help: "- 娶群友\n- 群老婆列表\n- [允许|禁止]自由恋爱\n- [允许|禁止]牛头人\n- 设置CD为xx小时 →(默认12小时)\n- 重置花名册\n- 重置所有花名册(用于清除所有群数据及其设置)\n- 查好感度[对方Q号|@对方QQ]\n- 好感度列表\n" + + Help: "- 娶群友\n- 群老婆列表\n- [允许|禁止]自由恋爱\n- [允许|禁止]牛头人\n- 设置CD为xx小时 →(默认12小时)\n- 重置花名册\n- 重置所有花名册(用于清除所有群数据及其设置)\n- 查好感度[对方Q号|@对方QQ]\n- 好感度列表\n- 好感度数据整理 (当好感动列表出现重复名字时使用)\n" + "--------------------------------\n以下指令存在CD,不跨天刷新,前两个受指令开关\n--------------------------------\n" + "- (娶|嫁)@对方QQ\n自由选择对象, 自由恋爱(好感度越高成功率越高,保底30%概率)\n" + "- 当[对方Q号|@对方QQ]的小三\n我和你才是真爱, 为了你我愿意付出一切(好感度越高成功率越高,保底10%概率)\n" + diff --git a/plugin/qqwife/favorSystem.go b/plugin/qqwife/favorSystem.go index 3922566f8b..c98cea60ae 100644 --- a/plugin/qqwife/favorSystem.go +++ b/plugin/qqwife/favorSystem.go @@ -84,16 +84,18 @@ func init() { ctx.SendChain(message.Text("你钱包没钱啦!")) return } - moneyToFavor := rand.Intn(math.Min(walletinfo, 100)) + moneyToFavor := rand.Intn(math.Min(walletinfo, 100)) + 1 // 计算钱对应的好感值 newFavor := 1 + moodMax := 2 if favor > 50 { newFavor = moneyToFavor % 10 // 礼物厌倦 } else { + moodMax = 5 newFavor += rand.Intn(moneyToFavor) } // 随机对方心情 - mood := rand.Intn(2) + mood := rand.Intn(moodMax) if mood == 0 { newFavor = -newFavor } @@ -191,6 +193,68 @@ func init() { ctx.SendChain(message.ImageBytes(data)) cl() }) + + engine.OnFullMatch("好感度数据整理", zero.SuperUserPermission, getdb).SetBlock(true).Limit(ctxext.LimitByUser). + Handle(func(ctx *zero.Ctx) { + 民政局.Lock() + defer 民政局.Unlock() + count, err := 民政局.db.Count("favorability") + if err != nil { + ctx.SendChain(message.Text("[ERROR]: ", err)) + return + } + if count == 0 { + ctx.SendChain(message.Text("[ERROR]: 不存在好感动数据.")) + return + } + favor := favorability{} + delInfo := make([]string, 0, count*2) + favorInfo := make(map[string]int, count*2) + _ = 民政局.db.FindFor("favorability", &favor, "group by Userinfo", func() error { + delInfo = append(delInfo, favor.Userinfo) + // 解析旧数据 + userList := strings.Split(favor.Userinfo, "+") + if userList[0] > userList[1] { + favor.Userinfo = userList[0] + "+" + userList[1] + } else { + favor.Userinfo = userList[1] + "+" + userList[0] + } + // 判断是否是重复的 + score, ok := favorInfo[favor.Userinfo] + if ok { + if score < favor.Favor { + favorInfo[favor.Userinfo] = favor.Favor + } + } else { + favorInfo[favor.Userinfo] = favor.Favor + } + return nil + }) + for _, updateinfo := range delInfo { + // 删除旧数据 + err = 民政局.db.Del("favorability", "where Userinfo = '"+updateinfo+"'") + if err != nil { + userList := strings.Split(favor.Userinfo, "+") + uid1, _ := strconv.ParseInt(userList[0], 10, 64) + uid2, _ := strconv.ParseInt(userList[1], 10, 64) + ctx.SendChain(message.Text("[ERROR]: 删除", ctx.CardOrNickName(uid1), "和", ctx.CardOrNickName(uid2), "的好感动时发生了错误。\n错误信息:", err)) + } + } + for userInfo, favor := range favorInfo { + favorInfo := favorability{ + Userinfo: userInfo, + Favor: favor, + } + err = 民政局.db.Insert("favorability", &favorInfo) + if err != nil { + userList := strings.Split(userInfo, "+") + uid1, _ := strconv.ParseInt(userList[0], 10, 64) + uid2, _ := strconv.ParseInt(userList[1], 10, 64) + ctx.SendChain(message.Text("[ERROR]: 更新", ctx.CardOrNickName(uid1), "和", ctx.CardOrNickName(uid2), "的好感动时发生了错误。\n错误信息:", err)) + } + } + ctx.SendChain(message.Text("清理好了哦")) + }) } func (sql *婚姻登记) 查好感度(uid, target int64) (int, error) { @@ -201,9 +265,19 @@ func (sql *婚姻登记) 查好感度(uid, target int64) (int, error) { return 0, err } info := favorability{} - uidstr := strconv.FormatInt(uid, 10) - targstr := strconv.FormatInt(target, 10) - _ = sql.db.Find("favorability", &info, "where Userinfo glob '*"+uidstr+"+"+targstr+"*'") + if uid > target { + userinfo := strconv.FormatInt(uid, 10) + "+" + strconv.FormatInt(target, 10) + err = sql.db.Find("favorability", &info, "where Userinfo is '"+userinfo+"'") + if err != nil { + _ = sql.db.Find("favorability", &info, "where Userinfo glob '*"+userinfo+"*'") + } + } else { + userinfo := strconv.FormatInt(target, 10) + "+" + strconv.FormatInt(uid, 10) + err = sql.db.Find("favorability", &info, "where Userinfo is '"+userinfo+"'") + if err != nil { + _ = sql.db.Find("favorability", &info, "where Userinfo glob '*"+userinfo+"*'") + } + } return info.Favor, nil } @@ -256,8 +330,19 @@ func (sql *婚姻登记) 更新好感度(uid, target int64, score int) (favor in info := favorability{} uidstr := strconv.FormatInt(uid, 10) targstr := strconv.FormatInt(target, 10) - _ = sql.db.Find("favorability", &info, "where Userinfo glob '*"+uidstr+"+"+targstr+"*'") - info.Userinfo = uidstr + "+" + targstr + "+" + uidstr + if uid > target { + info.Userinfo = uidstr + "+" + targstr + err = sql.db.Find("favorability", &info, "where Userinfo is '"+info.Userinfo+"'") + } else { + info.Userinfo = targstr + "+" + uidstr + err = sql.db.Find("favorability", &info, "where Userinfo is '"+info.Userinfo+"'") + } + if err != nil { + err = sql.db.Find("favorability", &info, "where Userinfo glob '*"+targstr+"+"+uidstr+"*'") + if err == nil { // 如果旧数据存在就删除旧数据 + err = 民政局.db.Del("favorability", "where Userinfo = '"+info.Userinfo+"'") + } + } info.Favor += score if info.Favor > 100 { info.Favor = 100