From f4b41efc75cd84d50fb8d1d78c4d418725fc22e1 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: Mon, 28 Nov 2022 11:13:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96qqwife=E4=BB=A3=E7=A0=81,?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BB=A3=E7=A0=81=E5=8F=AF=E8=AF=BB=E6=80=A7?= =?UTF-8?q?=20(#508)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 + plugin/qqwife/command.go | 801 ++++++++---------------- plugin/qqwife/favorSystem.go | 272 ++++++++ plugin/qqwife/function.go | 1136 +++++++++++++++------------------- 4 files changed, 1025 insertions(+), 1186 deletions(-) create mode 100644 plugin/qqwife/favorSystem.go diff --git a/README.md b/README.md index 6dd1281dd8..84bc6a3333 100644 --- a/README.md +++ b/README.md @@ -1066,6 +1066,8 @@ print("run[CQ:image,file="+j["img"]+"]") - [x] 群老婆列表 + - [x] 查好感度[对方Q号|@对方QQ] + - [x] 好感度列表 - [x] 重置花名册 diff --git a/plugin/qqwife/command.go b/plugin/qqwife/command.go index 2d8c174b9b..4cdcba8910 100644 --- a/plugin/qqwife/command.go +++ b/plugin/qqwife/command.go @@ -5,6 +5,7 @@ import ( "math/rand" "sort" "strconv" + "sync" "time" "github.com/FloatTech/floatbox/math" @@ -24,46 +25,45 @@ import ( "github.com/FloatTech/floatbox/file" "github.com/FloatTech/floatbox/img/writer" "github.com/FloatTech/zbputils/img/text" - // 货币系统 - "github.com/FloatTech/AnimeAPI/wallet" ) // nolint: asciicheck -// nolint: asciicheck +//nolint: asciicheck +type 婚姻登记 struct { + db *sql.Sqlite + sync.RWMutex +} + +// 群设置 +type updateinfo struct { + GID int64 + Updatetime string // 登记时间 + CanMatch int // 嫁婚开关 + CanNtr int // Ntr开关 + CDtime float64 // CD时间 +} + +// 结婚证信息 +type userinfo struct { + User int64 // 用户身份证 + Target int64 // 对象身份证号 + Username string // 户主名称 + Targetname string // 对象名称 + Updatetime string // 登记时间 + +} + var ( + // nolint: asciicheck + //nolint: asciicheck 民政局 = &婚姻登记{ db: &sql.Sqlite{}, } - sendtext = [...][]string{ - { // 表白成功 - "是个勇敢的孩子(*/ω\*) 今天的运气都降临在你的身边~\n\n", - "(´・ω・`)对方答应了你 并表示愿意当今天的CP\n\n", - }, - { // 表白失败 - "今天的运气有一点背哦~明天再试试叭", - "_(:з」∠)_下次还有机会 咱抱抱你w", - "今天失败了惹. 摸摸头~咱明天还有机会", - }, - { // ntr成功 - "因为你的个人魅力~~今天他就是你的了w\n\n", - }, - { // 离婚失败 - "打是情,骂是爱,不打不亲不相爱。答应我不要分手。", - "床头打架床尾和,夫妻没有隔夜仇。安啦安啦,不要闹变扭。", - }, - { // 离婚成功 - "离婚成功力\n话说你不考虑当个1?", - "离婚成功力\n天涯何处无芳草,何必单恋一枝花?不如再摘一支(bushi", - }, - } -) - -func init() { - engine := control.Register("qqwife", &ctrl.Options[*zero.Ctx]{ + engine = control.Register("qqwife", &ctrl.Options[*zero.Ctx]{ DisableOnDefault: false, Brief: "一群一天一夫一妻制群老婆", - Help: "- 娶群友\n- 群老婆列表\n- [允许|禁止]自由恋爱\n- [允许|禁止]牛头人\n- 设置CD为xx小时 →(默认12小时)\n- 重置花名册\n- 重置所有花名册(用于清除所有群数据及其设置)\n" + + Help: "- 娶群友\n- 群老婆列表\n- [允许|禁止]自由恋爱\n- [允许|禁止]牛头人\n- 设置CD为xx小时 →(默认12小时)\n- 重置花名册\n- 重置所有花名册(用于清除所有群数据及其设置)\n- 查好感度[对方Q号|@对方QQ]\n- 好感度列表\n" + "--------------------------------\n以下指令存在CD,不跨天刷新,前两个受指令开关\n--------------------------------\n" + "- (娶|嫁)@对方QQ\n自由选择对象, 自由恋爱(好感度越高成功率越高,保底30%概率)\n" + "- 当[对方Q号|@对方QQ]的小三\n我和你才是真爱, 为了你我愿意付出一切(好感度越高成功率越高,保底10%概率)\n" + @@ -84,106 +84,71 @@ func init() { ) }), )) - getdb := fcext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool { + getdb = fcext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool { 民政局.db.DBPath = engine.DataFolder() + "结婚登记表.db" err := 民政局.db.Open(time.Hour * 24) - if err != nil { - ctx.SendChain(message.Text("[qqwife]数据库发生问题力\n", err)) - return false - } - return true - }) - // 技能CD设置 - engine.OnRegex(`^设置CD为(\d+)小时`, zero.OnlyGroup, zero.AdminPermission, getdb).SetBlock(true).Limit(ctxext.LimitByUser). - Handle(func(ctx *zero.Ctx) { - cdTime, err := strconv.ParseFloat(ctx.State["regex_matched"].([]string)[1], 64) + if err == nil { + // 创建群配置表 + err = 民政局.db.Create("updateinfo", &updateinfo{}) if err != nil { - ctx.SendChain(message.Text("[qqwife]请设置纯数字\n", err)) - return + ctx.SendChain(message.Text("[ERROR]:", err)) + return false } - gid := ctx.Event.GroupID - err = 民政局.setCDtime(gid, cdTime) + // 创建CD表 + err = 民政局.db.Create("cdsheet", &cdsheet{}) if err != nil { - ctx.SendChain(message.Text("[qqwife]设置CD时长失败\n", err)) - return + ctx.SendChain(message.Text("[ERROR]:", err)) + return false } - ctx.SendChain(message.Text("设置成功")) - }) - engine.OnRegex(`^(允许|禁止)(自由恋爱|牛头人)$`, zero.OnlyGroup, zero.AdminPermission, getdb).SetBlock(true). - Handle(func(ctx *zero.Ctx) { - status := ctx.State["regex_matched"].([]string)[1] - mode := ctx.State["regex_matched"].([]string)[2] - gid := ctx.Event.GroupID - statusBool := 1 - if status == "禁止" { - statusBool = 0 - } - err := 民政局.修改模式(gid, mode, statusBool) - if err != nil { - ctx.SendChain(message.Text("[qqwife]群状态查询失败\n", err)) - return - } - ctx.SendChain(message.Text("设置成功")) - }) - // 好感度系统 - engine.OnRegex(`^查好感度\s?\[CQ:at,qq=(\d+)\]`, zero.OnlyGroup, getdb).SetBlock(true).Limit(ctxext.LimitByUser). - Handle(func(ctx *zero.Ctx) { - fiancee, err := strconv.ParseInt(ctx.State["regex_matched"].([]string)[1], 10, 64) + // 创建好感度表 + err = 民政局.db.Create("favorability", &favorability{}) if err != nil { - ctx.SendChain(message.Text("[qqwife]你对象好像不存在?\n", err)) - return - } - uid := ctx.Event.UserID - favor, err := 民政局.getFavorability(uid, fiancee) - if err != nil { - ctx.SendChain(message.Text("[qqwife]好感度库发生问题力\n", err)) - return + ctx.SendChain(message.Text("[ERROR]:", err)) + return false } - // 输出结果 - ctx.SendChain( - message.At(uid), - message.Text("\n当前你们好感度为", favor), - ) - }) + return true + } + ctx.SendChain(message.Text("[ERROR]:", err)) + return false + }) +) + +func init() { engine.OnFullMatch("娶群友", zero.OnlyGroup, getdb).SetBlock(true).Limit(ctxext.LimitByUser). Handle(func(ctx *zero.Ctx) { gid := ctx.Event.GroupID - _, err := 民政局.开门时间(gid) + err := 民政局.开门时间(gid) if err != nil { - ctx.SendChain(message.Text("[qqwife]数据库发生问题力\n", err)) + ctx.SendChain(message.Text("[ERROR]:", err)) return } uid := ctx.Event.UserID - targetinfo, status, err := 民政局.查户口(gid, uid) + userInfo, _ := 民政局.查户口(gid, uid) switch { - case status == "错": - ctx.SendChain(message.Text("[qqwife]数据库发生问题力\n", err)) - return - case (status == "攻" && targetinfo.Target == 0) || - (status == "受" && targetinfo.User == 0): // 如果是单身贵族 + case userInfo != (userinfo{}) && (userInfo.Target == 0 || userInfo.User == 0): // 如果是单身贵族 ctx.SendChain(message.Text("今天你是单身贵族噢")) return - case status == "攻": // 娶过别人 + case userInfo.User == uid: // 娶过别人 ctx.SendChain( message.At(uid), - message.Text("\n今天你在", targetinfo.Updatetime, "娶了群友"), - message.Image("http://q4.qlogo.cn/g?b=qq&nk="+strconv.FormatInt(targetinfo.Target, 10)+"&s=640").Add("cache", 0), + message.Text("\n今天你在", userInfo.Updatetime, "娶了群友"), + message.Image("http://q4.qlogo.cn/g?b=qq&nk="+strconv.FormatInt(userInfo.Target, 10)+"&s=640").Add("cache", 0), message.Text( "\n", - "[", targetinfo.Targetname, "]", - "(", targetinfo.Target, ")哒", + "[", userInfo.Targetname, "]", + "(", userInfo.Target, ")哒", ), ) return - case status == "受": // 嫁给别人 + case userInfo.Target == uid: // 嫁给别人 ctx.SendChain( message.At(uid), - message.Text("\n今天你在", targetinfo.Updatetime, "被群友"), - message.Image("http://q4.qlogo.cn/g?b=qq&nk="+strconv.FormatInt(targetinfo.User, 10)+"&s=640").Add("cache", 0), + message.Text("\n今天你在", userInfo.Updatetime, "被群友"), + message.Image("http://q4.qlogo.cn/g?b=qq&nk="+strconv.FormatInt(userInfo.User, 10)+"&s=640").Add("cache", 0), message.Text( "\n", - "[", targetinfo.Username, "]", - "(", targetinfo.User, ")娶了", + "[", userInfo.Username, "]", + "(", userInfo.User, ")娶了", ), ) return @@ -198,12 +163,8 @@ func init() { qqgrouplist := make([]int64, 0, len(temp)) for k := 0; k < len(temp); k++ { usr := temp[k].Get("user_id").Int() - _, status, err := 民政局.查户口(gid, usr) - if status == "错" { - ctx.SendChain(message.Text("[qqwife]花名册数据读取有误,请重试\n", err)) - return - } - if status != "单" { + usrInfo, _ := 民政局.查户口(gid, usr) + if usrInfo != (userinfo{}) { continue } qqgrouplist = append(qqgrouplist, usr) @@ -216,181 +177,33 @@ func init() { // 随机抽娶 fiancee := qqgrouplist[rand.Intn(len(qqgrouplist))] if fiancee == uid { // 如果是自己 - ctx.SendChain(message.Text("呜...没娶到,你可以再尝试一次")) - return - } - // 去民政局办证 - err = 民政局.登记(gid, uid, fiancee, ctx.CardOrNickName(uid), ctx.CardOrNickName(fiancee)) - if err != nil { - ctx.SendChain(message.Text("[qqwife]数据库发生问题力\n", err)) - return - } - favor, err := 民政局.setFavorability(uid, fiancee, 1+rand.Intn(5)) - if err != nil { - ctx.SendChain(message.Text("[qqwife]好感度库发生问题力\n", err)) - } - // 请大家吃席 - ctx.SendChain( - message.At(uid), - message.Text("今天你的群老婆是"), - message.Image("http://q4.qlogo.cn/g?b=qq&nk="+strconv.FormatInt(fiancee, 10)+"&s=640").Add("cache", 0), - message.Text( - "\n", - "[", ctx.CardOrNickName(fiancee), "]", - "(", fiancee, ")哒\n当前你们好感度为", favor, - ), - ) - }) - // 单身技能 - engine.OnRegex(`^(娶|嫁)\[CQ:at,qq=(\d+)\]`, zero.OnlyGroup, getdb, checkdog).SetBlock(true).Limit(ctxext.LimitByUser). - Handle(func(ctx *zero.Ctx) { - gid := ctx.Event.GroupID - uid := ctx.Event.UserID - choice := ctx.State["regex_matched"].([]string)[1] - fiancee, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64) - // 写入CD - err := 民政局.writeCDtime(gid, uid, 1) - if err != nil { - ctx.SendChain(message.At(uid), message.Text("[qqwife]你的技能CD记录失败\n", err)) - } - if uid == fiancee { // 如果是自己 - switch rand.Intn(3) { + switch rand.Intn(10) { case 1: err := 民政局.登记(gid, uid, 0, "", "") if err != nil { - ctx.SendChain(message.Text("[qqwife]数据库发生问题力\n", err)) + ctx.SendChain(message.Text("[ERROR]:", err)) return } ctx.SendChain(message.Text("今日获得成就:单身贵族")) default: - ctx.SendChain(message.Text("今日获得成就:自恋狂")) - } - return - } - favor, err := 民政局.getFavorability(uid, fiancee) - if err != nil { - ctx.SendChain(message.Text("[qqwife]好感度库发生问题力\n", err)) - return - } - if favor < 30 { - favor = 30 // 保底30%概率 - } - if rand.Intn(101) >= favor { - ctx.SendChain(message.Text(sendtext[1][rand.Intn(len(sendtext[1]))])) - return - } - // 去民政局登记 - var choicetext string - switch choice { - case "娶": - err := 民政局.登记(gid, uid, fiancee, ctx.CardOrNickName(uid), ctx.CardOrNickName(fiancee)) - if err != nil { - ctx.SendChain(message.Text("[qqwife]结婚登记失败力\n", err)) - return - } - choicetext = "\n今天你的群老婆是" - default: - err := 民政局.登记(gid, fiancee, uid, ctx.CardOrNickName(fiancee), ctx.CardOrNickName(uid)) - if err != nil { - ctx.SendChain(message.Text("[qqwife]结婚登记失败力\n", err)) - return - } - choicetext = "\n今天你的群老公是" - } - // 请大家吃席 - ctx.SendChain( - message.Text(sendtext[0][rand.Intn(len(sendtext[0]))]), - message.At(uid), - message.Text(choicetext), - message.Image("http://q4.qlogo.cn/g?b=qq&nk="+strconv.FormatInt(fiancee, 10)+"&s=640").Add("cache", 0), - message.Text( - "\n", - "[", ctx.CardOrNickName(fiancee), "]", - "(", fiancee, ")哒", - ), - ) - }) - // NTR技能 - engine.OnRegex(`^当(\[CQ:at,qq=(\d+)\]\s?|(\d+))的小三`, zero.OnlyGroup, getdb, checkcp).SetBlock(true).Limit(ctxext.LimitByUser). - Handle(func(ctx *zero.Ctx) { - gid := ctx.Event.GroupID - uid := ctx.Event.UserID - fid := ctx.State["regex_matched"].([]string) - fiancee, _ := strconv.ParseInt(fid[2]+fid[3], 10, 64) - // 写入CD - err := 民政局.writeCDtime(gid, uid, 2) - if err != nil { - ctx.SendChain(message.At(uid), message.Text("[qqwife]你的技能CD记录失败\n", err)) - } - if fiancee == uid { - ctx.SendChain(message.Text("今日获得成就:自我攻略")) - return - } - favor, err := 民政局.getFavorability(uid, fiancee) - if err != nil { - ctx.SendChain(message.Text("[qqwife]好感度库发生问题力\n", err)) - return - } - if favor < 30 { - favor = 30 // 保底10%概率 - } - if rand.Intn(101) >= favor/3 { - ctx.SendChain(message.Text("失败了!可惜")) - return - } - // 判断target是老公还是老婆 - var choicetext string - userAID := uid //攻的 - var userBID int64 //被牛的 - userCID := fiancee //受的 - fianceeinfo, gender, err := 民政局.查户口(gid, userCID) - switch gender { - case "单": - ctx.SendChain(message.Text("ta现在还是单身哦,快向ta表白吧!")) - return - case "错": - ctx.SendChain(message.Text("[qqwife]对象状态查询失败\n", err)) - return - case "攻": - err = 民政局.离婚休妻(gid, fianceeinfo.Target) - if err != nil { - ctx.SendChain(message.Text("ta不想和原来的对象分手...\n[error]", err)) + ctx.SendChain(message.Text("呜...没娶到,你可以再尝试一次")) return } - userAID = fiancee - userCID = uid - userBID = fianceeinfo.Target - choicetext = "老公" - case "受": - err = 民政局.离婚休夫(gid, fianceeinfo.User) - if err != nil { - ctx.SendChain(message.Text("ta不想和原来的对象分手...\n[error]", err)) - return - } - userBID = fianceeinfo.User - choicetext = "老婆" - default: - ctx.SendChain(message.Text("数据库发生问题力")) - return } - err = 民政局.登记(gid, userAID, userCID, ctx.CardOrNickName(userAID), ctx.CardOrNickName(userCID)) + // 去民政局办证 + err = 民政局.登记(gid, uid, fiancee, ctx.CardOrNickName(uid), ctx.CardOrNickName(fiancee)) if err != nil { - ctx.SendChain(message.Text("[qqwife]复婚登记失败力\n", err)) + ctx.SendChain(message.Text("[ERROR]:", err)) return } - favor, err = 民政局.setFavorability(userAID, userCID, -5) - if err != nil { - ctx.SendChain(message.Text("[qqwife]好感度库发生问题力\n", err)) - } - _, err = 民政局.setFavorability(userAID, userBID, 5) + favor, err := 民政局.更新好感度(uid, fiancee, 1+rand.Intn(5)) if err != nil { - ctx.SendChain(message.Text("[qqwife]好感度库发生问题力\n", err)) + ctx.SendChain(message.Text("[ERROR]:", err)) } - // 输出结果 + // 请大家吃席 ctx.SendChain( - message.Text(sendtext[2][rand.Intn(len(sendtext[2]))]), message.At(uid), - message.Text("今天你的群"+choicetext+"是"), + message.Text("今天你的群老婆是"), message.Image("http://q4.qlogo.cn/g?b=qq&nk="+strconv.FormatInt(fiancee, 10)+"&s=640").Add("cache", 0), message.Text( "\n", @@ -399,210 +212,20 @@ func init() { ), ) }) - // 做媒技能 - engine.OnRegex(`^做媒\s?\[CQ:at,qq=(\d+)\]\s?\[CQ:at,qq=(\d+)\]`, zero.OnlyGroup, zero.AdminPermission, getdb, checkCondition).SetBlock(true).Limit(ctxext.LimitByUser). - Handle(func(ctx *zero.Ctx) { - gid := ctx.Event.GroupID - uid := ctx.Event.UserID - gayOne, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[1], 10, 64) - gayZero, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64) - // 写入CD - err := 民政局.writeCDtime(gid, uid, 3) - if err != nil { - ctx.SendChain(message.At(uid), message.Text("[qqwife]你的技能CD记录失败\n", err)) - } - favor, err := 民政局.getFavorability(gayOne, gayZero) - if err != nil { - ctx.SendChain(message.Text("[qqwife]好感度库发生问题力\n", err)) - return - } - if favor < 30 { - favor = 30 // 保底30%概率 - } - if rand.Intn(101) >= favor { - _, err = 民政局.setFavorability(uid, gayOne, -1) - if err != nil { - ctx.SendChain(message.Text("[qqwife]好感度库发生问题力\n", err)) - } - _, err = 民政局.setFavorability(uid, gayZero, -1) - if err != nil { - ctx.SendChain(message.Text("[qqwife]好感度库发生问题力\n", err)) - } - ctx.SendChain(message.Text(sendtext[1][rand.Intn(len(sendtext[1]))])) - return - } - // 去民政局登记 - err = 民政局.登记(gid, gayOne, gayZero, ctx.CardOrNickName(gayOne), ctx.CardOrNickName(gayZero)) - if err != nil { - ctx.SendChain(message.Text("[qqwife]结婚登记失败力\n", err)) - return - } - _, err = 民政局.setFavorability(uid, gayOne, 1) - if err != nil { - ctx.SendChain(message.Text("[qqwife]好感度库发生问题力\n", err)) - } - _, err = 民政局.setFavorability(uid, gayZero, 1) - if err != nil { - ctx.SendChain(message.Text("[qqwife]好感度库发生问题力\n", err)) - } - _, err = 民政局.setFavorability(gayOne, gayZero, 1) - if err != nil { - ctx.SendChain(message.Text("[qqwife]好感度库发生问题力\n", err)) - } - // 请大家吃席 - ctx.SendChain( - message.At(uid), - message.Text("恭喜你成功撮合了一对CP\n\n"), - message.At(gayOne), - message.Text("今天你的群老婆是"), - message.Image("http://q4.qlogo.cn/g?b=qq&nk="+strconv.FormatInt(gayZero, 10)+"&s=640").Add("cache", 0), - message.Text( - "\n", - "[", ctx.CardOrNickName(gayZero), "]", - "(", gayZero, ")哒", - ), - ) - }) - // 礼物系统 - engine.OnRegex(`^买礼物给\s?(\[CQ:at,qq=(\d+)\]|(\d+))`, getdb).SetBlock(true).Limit(ctxext.LimitByUser). - Handle(func(ctx *zero.Ctx) { - gid := ctx.Event.GroupID - uid := ctx.Event.UserID - fiancee := ctx.State["regex_matched"].([]string) - gay, _ := strconv.ParseInt(fiancee[2]+fiancee[3], 10, 64) - if gay == uid { - ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.At(uid), message.Text("[qqwife]你想给自己买什么礼物呢?"))) - return - } - // 获取CD - cdTime, err := 民政局.getCDtime(gid) - if err != nil { - ctx.SendChain(message.Text("[qqwife]获取该群技能CD错误(将以CD12H计算)\n", err)) - } - ok, err := 民政局.compareCDtime(gid, uid, 5, cdTime) - if err != nil { - ctx.SendChain(message.Text("[qqwife]查询用户CD状态失败,请重试\n", err)) - return - } - if !ok { - ctx.SendChain(message.Text("舔狗,今天你已经送过礼物了。")) - return - } - // 获取好感度 - favor, err := 民政局.getFavorability(uid, gay) - if err != nil { - ctx.SendChain(message.Text("[qqwife]好感度库发生问题力\n", err)) - return - } - // 对接小熊饼干 - walletinfo := wallet.GetWalletOf(uid) - if walletinfo < 1 { - ctx.SendChain(message.Text("你钱包没钱啦!")) - return - } - moneyToFavor := rand.Intn(math.Min(walletinfo, 100)) + 1 - // 计算钱对应的好感值 - newFavor := 1 - if favor > 50 { - newFavor = moneyToFavor % 10 // 礼物厌倦 - } else { - newFavor += rand.Intn(moneyToFavor) - } - // 随机对方心情 - mood := rand.Intn(2) - if mood == 0 { - newFavor = -newFavor - } - // 记录结果 - err = wallet.InsertWalletOf(uid, -moneyToFavor) - if err != nil { - ctx.SendChain(message.Text("[qqwife]钱包坏掉力:\n", err)) - return - } - lastfavor, err := 民政局.setFavorability(uid, gay, newFavor) - if err != nil { - ctx.SendChain(message.Text("[qqwife]好感度数据库发生问题力\n", err)) - return - } - // 写入CD - err = 民政局.writeCDtime(gid, uid, 5) - if err != nil { - ctx.SendChain(message.At(uid), message.Text("[qqwife]你的技能CD记录失败\n", err)) - } - // 输出结果 - if mood == 0 { - ctx.SendChain(message.Text("你花了", moneyToFavor, "ATRI币买了一件女装送给了ta,ta很不喜欢,你们的好感度降低至", lastfavor)) - } else { - ctx.SendChain(message.Text("你花了", moneyToFavor, "ATRI币买了一件女装送给了ta,ta很喜欢,你们的好感度升至", lastfavor)) - } - }) - engine.OnFullMatchGroup([]string{"闹离婚", "办离婚"}, zero.OnlyGroup, getdb, checkdivorce).Limit(ctxext.LimitByUser).SetBlock(true). - Handle(func(ctx *zero.Ctx) { - gid := ctx.Event.GroupID - uid := ctx.Event.UserID - // 写入CD - err := 民政局.writeCDtime(gid, uid, 4) - if err != nil { - ctx.SendChain(message.At(uid), message.Text("[qqwife]你的技能CD记录失败\n", err)) - } - info, uidstatus, err := 民政局.查户口(gid, uid) - mun := 2 - var fiancee int64 - switch uidstatus { - case "错": - ctx.SendChain(message.Text("[qqwife]用户状态查询失败\n", err)) - return - case "攻": - mun = 1 - fiancee = info.Target - case "受": - mun = 0 - fiancee = info.User - } - favor, err := 民政局.getFavorability(uid, fiancee) - if err != nil { - ctx.SendChain(message.Text("[qqwife]好感度库发生问题力\n", err)) - return - } - if favor < 20 { - favor = 10 - } - if rand.Intn(101) > 100-favor { - ctx.SendChain(message.Text(sendtext[3][rand.Intn(len(sendtext[3]))])) - return - } - switch mun { - case 1: - err = 民政局.离婚休妻(gid, fiancee) - case 0: - err = 民政局.离婚休夫(gid, fiancee) - default: - ctx.SendChain(message.Text("[qqwife]数据库发生问题力\n", err)) - return - } - if err != nil { - ctx.SendChain(message.Text("[qqwife]数据库发生问题力\n", err)) - return - } - ctx.SendChain(message.Text(sendtext[4][mun])) - }) engine.OnFullMatch("群老婆列表", zero.OnlyGroup, getdb).SetBlock(true).Limit(ctxext.LimitByUser). Handle(func(ctx *zero.Ctx) { gid := ctx.Event.GroupID - ok, err := 民政局.开门时间(gid) + err := 民政局.开门时间(gid) if err != nil { - ctx.SendChain(message.Text("[qqwife]数据库发生问题力\n", err)) - return - } - if ok { - ctx.SendChain(message.Text("今天还没有人结婚哦")) + ctx.SendChain(message.Text("[ERROR]:", err)) return } - list, number, err := 民政局.花名册(gid) + list, err := 民政局.花名册(gid) if err != nil { - ctx.SendChain(message.Text("[qqwife]数据库发生问题力\n", err)) + ctx.SendChain(message.Text("[ERROR]:", err)) return } + number := len(list) if number <= 0 { ctx.SendChain(message.Text("今天还没有人结婚哦")) return @@ -648,103 +271,193 @@ func init() { ctx.SendChain(message.ImageBytes(data)) cl() }) - engine.OnFullMatch("好感度列表", zero.OnlyGroup, getdb).SetBlock(true).Limit(ctxext.LimitByUser). - Handle(func(ctx *zero.Ctx) { - uid := ctx.Event.UserID - fianceeInfo, err := 民政局.getGroupFavorability(uid) - if err != nil { - ctx.SendChain(message.Text("[qqwife]ERROR: ", err)) - return - } - /***********设置图片的大小和底色***********/ - number := len(fianceeInfo) - if number > 10 { - number = 10 - } - fontSize := 50.0 - canvas := gg.NewContext(1150, int(170+(50+70)*float64(number))) - canvas.SetRGB(1, 1, 1) // 白色 - canvas.Clear() - /***********下载字体***********/ - _, err = file.GetLazyData(text.BoldFontFile, control.Md5File, true) - if err != nil { - ctx.SendChain(message.Text("[qqwife]ERROR: ", err)) - } - /***********设置字体颜色为黑色***********/ - canvas.SetRGB(0, 0, 0) - /***********设置字体大小,并获取字体高度用来定位***********/ - if err = canvas.LoadFontFace(text.BoldFontFile, fontSize*2); err != nil { - ctx.SendChain(message.Text("[qqwife]ERROR: ", err)) - return - } - sl, h := canvas.MeasureString("你的好感度排行列表") - /***********绘制标题***********/ - canvas.DrawString("你的好感度排行列表", (1100-sl)/2, 100) // 放置在中间位置 - canvas.DrawString("————————————————————", 0, 160) - /***********设置字体大小,并获取字体高度用来定位***********/ - if err = canvas.LoadFontFace(text.BoldFontFile, fontSize); err != nil { - ctx.SendChain(message.Text("[qqwife]ERROR: ", err)) - return - } - i := 0 - for _, info := range fianceeInfo { - if i > 9 { - break - } - if info.Userinfo == "" { - continue - } - fianceID, err := strconv.ParseInt(info.Userinfo, 10, 64) - if err != nil { - ctx.SendChain(message.Text("[qqwife]ERROR: ", err)) - return - } - if fianceID == 0 { - continue - } - userName := ctx.CardOrNickName(fianceID) - canvas.SetRGB255(0, 0, 0) - canvas.DrawString(userName+"("+info.Userinfo+")", 10, float64(180+(50+70)*i)) - canvas.DrawString(strconv.Itoa(info.Favor), 1020, float64(180+60+(50+70)*i)) - canvas.DrawRectangle(10, float64(180+60+(50+70)*i)-h/2, 1000, 50) - canvas.SetRGB255(150, 150, 150) - canvas.Fill() - canvas.SetRGB255(0, 0, 0) - canvas.DrawRectangle(10, float64(180+60+(50+70)*i)-h/2, float64(info.Favor)*10, 50) - canvas.SetRGB255(231, 27, 100) - canvas.Fill() - i++ - } - data, cl := writer.ToBytes(canvas.Image()) - ctx.SendChain(message.ImageBytes(data)) - cl() - }) engine.OnRegex(`^重置(所有|本群|/d+)?花名册$`, zero.SuperUserPermission, getdb).SetBlock(true).Limit(ctxext.LimitByUser). Handle(func(ctx *zero.Ctx) { - cmd := "0" + var err error switch ctx.State["regex_matched"].([]string)[1] { - case "": - if ctx.Event.GroupID == 0 { - ctx.SendChain(message.Text("该功能只能在群组使用或者指定群组")) - return - } - cmd = strconv.FormatInt(ctx.Event.GroupID, 10) case "所有": - break - case "本群": + err = 民政局.清理花名册() + case "本群", "": if ctx.Event.GroupID == 0 { ctx.SendChain(message.Text("该功能只能在群组使用或者指定群组")) return } - cmd = strconv.FormatInt(ctx.Event.GroupID, 10) + err = 民政局.清理花名册("group" + strconv.FormatInt(ctx.Event.GroupID, 10)) default: - cmd = ctx.State["regex_matched"].([]string)[1] + cmd := ctx.State["regex_matched"].([]string)[1] + gid, _ := strconv.ParseInt(cmd, 10, 64) //判断是否为群号 + if gid == 0 { + ctx.SendChain(message.Text("请输入正确的群号")) + return + } + err = 民政局.清理花名册("group" + cmd) } - err := 民政局.清理花名册(cmd) if err != nil { - ctx.SendChain(message.Text("[qqwife]数据库发生问题力\n", err)) + ctx.SendChain(message.Text("[ERROR]:", err)) return } ctx.SendChain(message.Text("重置成功")) }) } + +// nolint: asciicheck +//nolint: asciicheck +func (sql *婚姻登记) 查看设置(gid int64) (dbinfo updateinfo, err error) { + sql.Lock() + defer sql.Unlock() + // 创建群表哥 + err = sql.db.Create("updateinfo", &updateinfo{}) + if err != nil { + return + } + if !sql.db.CanFind("updateinfo", "where gid is "+strconv.FormatInt(gid, 10)) { + // 没有记录 + return updateinfo{ + GID: gid, + CanMatch: 1, + CanNtr: 1, + CDtime: 12, + }, nil + } + _ = sql.db.Find("updateinfo", &dbinfo, "where gid is "+strconv.FormatInt(gid, 10)) + return +} + +// nolint: asciicheck +//nolint: asciicheck +func (sql *婚姻登记) 更新设置(dbinfo updateinfo) error { + sql.Lock() + defer sql.Unlock() + return sql.db.Insert("updateinfo", &dbinfo) +} + +// nolint: asciicheck +//nolint: asciicheck +func (sql *婚姻登记) 开门时间(gid int64) error { + grouInfo, err := sql.查看设置(gid) + if err != nil { + return err + } + sql.Lock() + defer sql.Unlock() + dbinfo := updateinfo{} + _ = sql.db.Find("updateinfo", &dbinfo, "where gid is "+strconv.FormatInt(gid, 10)) + if time.Now().Format("2006/01/02") != dbinfo.Updatetime { + // 如果跨天了就删除 + _ = sql.db.Drop("group" + strconv.FormatInt(gid, 10)) + // 更新数据时间 + grouInfo.Updatetime = time.Now().Format("2006/01/02") + return sql.db.Insert("updateinfo", &grouInfo) + } + return nil +} + +// nolint: asciicheck +//nolint: asciicheck +func (sql *婚姻登记) 查户口(gid, uid int64) (info userinfo, err error) { + sql.Lock() + defer sql.Unlock() + gidstr := "group" + strconv.FormatInt(gid, 10) + // 创建群表哥 + err = sql.db.Create(gidstr, &userinfo{}) + if err != nil { + return + } + uidstr := strconv.FormatInt(uid, 10) + err = sql.db.Find(gidstr, &info, "where user = "+uidstr) + if err != nil { + err = sql.db.Find(gidstr, &info, "where target = "+uidstr) + } + return +} + +// nolint: asciicheck +//nolint: asciicheck +// 民政局登记数据 +func (sql *婚姻登记) 登记(gid, uid, target int64, username, targetname string) error { + sql.Lock() + defer sql.Unlock() + gidstr := "group" + strconv.FormatInt(gid, 10) + uidinfo := userinfo{ + User: uid, + Username: username, + Target: target, + Targetname: targetname, + Updatetime: time.Now().Format("15:04:05"), + } + return sql.db.Insert(gidstr, &uidinfo) +} + +// nolint: asciicheck +//nolint: asciicheck +func (sql *婚姻登记) 花名册(gid int64) (list [][4]string, err error) { + sql.Lock() + defer sql.Unlock() + gidstr := "group" + strconv.FormatInt(gid, 10) + number, _ := sql.db.Count(gidstr) + if number <= 0 { + return + } + var info userinfo + err = sql.db.FindFor(gidstr, &info, "GROUP BY user", func() error { + if info.Target == 0 { + return nil + } + dbinfo := [4]string{ + info.Username, + strconv.FormatInt(info.User, 10), + info.Targetname, + strconv.FormatInt(info.Target, 10), + } + list = append(list, dbinfo) + return nil + }) + return +} + +func slicename(name string, canvas *gg.Context) (resultname string) { + usermane := []rune(name) // 将每个字符单独放置 + widthlen := 0 + numberlen := 0 + for i, v := range usermane { + width, _ := canvas.MeasureString(string(v)) // 获取单个字符的宽度 + widthlen += int(width) + if widthlen > 350 { + break // 总宽度不能超过350 + } + numberlen = i + } + if widthlen > 350 { + resultname = string(usermane[:numberlen-1]) + "......" // 名字切片 + } else { + resultname = name + } + return +} + +// nolint: asciicheck +//nolint: asciicheck +func (sql *婚姻登记) 清理花名册(gid ...string) error { + sql.Lock() + defer sql.Unlock() + switch gid { + case nil: + grouplist, err := sql.db.ListTables() + if err == nil { + for _, listName := range grouplist { + if listName == "favorability" { + continue + + } + err = sql.db.Drop(listName) + } + } + return err + default: + err := sql.db.Drop(gid[0]) + if err == nil { + err = sql.db.Del("cdsheet", "where GroupID is "+gid[0]) + } + return err + } +} diff --git a/plugin/qqwife/favorSystem.go b/plugin/qqwife/favorSystem.go new file mode 100644 index 0000000000..9ec5fe7b23 --- /dev/null +++ b/plugin/qqwife/favorSystem.go @@ -0,0 +1,272 @@ +package qqwife + +import ( + "errors" + "math/rand" + "sort" + "strconv" + "strings" + + "github.com/FloatTech/floatbox/math" + control "github.com/FloatTech/zbputils/control" + "github.com/FloatTech/zbputils/ctxext" + zero "github.com/wdvxdr1123/ZeroBot" + "github.com/wdvxdr1123/ZeroBot/message" + // 画图 + "github.com/Coloured-glaze/gg" + "github.com/FloatTech/floatbox/file" + "github.com/FloatTech/floatbox/img/writer" + "github.com/FloatTech/zbputils/img/text" + + // 货币系统 + "github.com/FloatTech/AnimeAPI/wallet" +) + +// 好感度系统 +type favorability struct { + Userinfo string // 记录用户 + Favor int // 好感度 +} + +func init() { + // 好感度系统 + engine.OnRegex(`^查好感度\s*(\[CQ:at,qq=)?(\d+)`, zero.OnlyGroup, getdb).SetBlock(true).Limit(ctxext.LimitByUser). + Handle(func(ctx *zero.Ctx) { + fiancee, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64) + uid := ctx.Event.UserID + favor, err := 民政局.查好感度(uid, fiancee) + if err != nil { + ctx.SendChain(message.Text("[ERROR]:", err)) + return + } + // 输出结果 + ctx.SendChain( + message.At(uid), + message.Text("\n当前你们好感度为", favor), + ) + }) + // 礼物系统 + engine.OnRegex(`^买礼物给\s?(\[CQ:at,qq=(\d+)\]|(\d+))`, getdb).SetBlock(true).Limit(ctxext.LimitByUser). + Handle(func(ctx *zero.Ctx) { + gid := ctx.Event.GroupID + uid := ctx.Event.UserID + fiancee := ctx.State["regex_matched"].([]string) + gay, _ := strconv.ParseInt(fiancee[2]+fiancee[3], 10, 64) + if gay == uid { + ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.At(uid), message.Text("你想给自己买什么礼物呢?"))) + return + } + // 获取CD + groupInfo, err := 民政局.查看设置(gid) + if err != nil { + ctx.SendChain(message.Text("[ERROR]:", err)) + return + } + ok, err := 民政局.判断CD(gid, uid, "买礼物", groupInfo.CDtime) + if err != nil { + ctx.SendChain(message.Text("[ERROR]:", err)) + return + } + if !ok { + ctx.SendChain(message.Text("舔狗,今天你已经送过礼物了。")) + return + } + // 获取好感度 + favor, err := 民政局.查好感度(uid, gay) + if err != nil { + ctx.SendChain(message.Text("[ERROR]:好感度库发生问题力\n", err)) + return + } + // 对接小熊饼干 + walletinfo := wallet.GetWalletOf(uid) + if walletinfo < 1 { + ctx.SendChain(message.Text("你钱包没钱啦!")) + return + } + moneyToFavor := rand.Intn(math.Min(walletinfo, 100)) + // 计算钱对应的好感值 + newFavor := 1 + if favor > 50 { + newFavor = moneyToFavor % 10 // 礼物厌倦 + } else { + newFavor += rand.Intn(moneyToFavor) + } + // 随机对方心情 + mood := rand.Intn(2) + if mood == 0 { + newFavor = -newFavor + } + // 记录结果 + err = wallet.InsertWalletOf(uid, -moneyToFavor) + if err != nil { + ctx.SendChain(message.Text("[ERROR]:钱包坏掉力:\n", err)) + return + } + lastfavor, err := 民政局.更新好感度(uid, gay, newFavor) + if err != nil { + ctx.SendChain(message.Text("[ERROR]:好感度数据库发生问题力\n", err)) + return + } + // 写入CD + err = 民政局.记录CD(gid, uid, "买礼物") + if err != nil { + ctx.SendChain(message.At(uid), message.Text("[ERROR]:你的技能CD记录失败\n", err)) + } + // 输出结果 + if mood == 0 { + ctx.SendChain(message.Text("你花了", moneyToFavor, "ATRI币买了一件女装送给了ta,ta很不喜欢,你们的好感度降低至", lastfavor)) + } else { + ctx.SendChain(message.Text("你花了", moneyToFavor, "ATRI币买了一件女装送给了ta,ta很喜欢,你们的好感度升至", lastfavor)) + } + }) + engine.OnFullMatch("好感度列表", zero.OnlyGroup, getdb).SetBlock(true).Limit(ctxext.LimitByUser). + Handle(func(ctx *zero.Ctx) { + uid := ctx.Event.UserID + fianceeInfo, err := 民政局.getGroupFavorability(uid) + if err != nil { + ctx.SendChain(message.Text("[ERROR]:ERROR: ", err)) + return + } + /***********设置图片的大小和底色***********/ + number := len(fianceeInfo) + if number > 10 { + number = 10 + } + fontSize := 50.0 + canvas := gg.NewContext(1150, int(170+(50+70)*float64(number))) + canvas.SetRGB(1, 1, 1) // 白色 + canvas.Clear() + /***********下载字体***********/ + _, err = file.GetLazyData(text.BoldFontFile, control.Md5File, true) + if err != nil { + ctx.SendChain(message.Text("[ERROR]:ERROR: ", err)) + } + /***********设置字体颜色为黑色***********/ + canvas.SetRGB(0, 0, 0) + /***********设置字体大小,并获取字体高度用来定位***********/ + if err = canvas.LoadFontFace(text.BoldFontFile, fontSize*2); err != nil { + ctx.SendChain(message.Text("[ERROR]:ERROR: ", err)) + return + } + sl, h := canvas.MeasureString("你的好感度排行列表") + /***********绘制标题***********/ + canvas.DrawString("你的好感度排行列表", (1100-sl)/2, 100) // 放置在中间位置 + canvas.DrawString("————————————————————", 0, 160) + /***********设置字体大小,并获取字体高度用来定位***********/ + if err = canvas.LoadFontFace(text.BoldFontFile, fontSize); err != nil { + ctx.SendChain(message.Text("[ERROR]:ERROR: ", err)) + return + } + i := 0 + for _, info := range fianceeInfo { + if i > 9 { + break + } + if info.Userinfo == "" { + continue + } + fianceID, err := strconv.ParseInt(info.Userinfo, 10, 64) + if err != nil { + ctx.SendChain(message.Text("[ERROR]:ERROR: ", err)) + return + } + if fianceID == 0 { + continue + } + userName := ctx.CardOrNickName(fianceID) + canvas.SetRGB255(0, 0, 0) + canvas.DrawString(userName+"("+info.Userinfo+")", 10, float64(180+(50+70)*i)) + canvas.DrawString(strconv.Itoa(info.Favor), 1020, float64(180+60+(50+70)*i)) + canvas.DrawRectangle(10, float64(180+60+(50+70)*i)-h/2, 1000, 50) + canvas.SetRGB255(150, 150, 150) + canvas.Fill() + canvas.SetRGB255(0, 0, 0) + canvas.DrawRectangle(10, float64(180+60+(50+70)*i)-h/2, float64(info.Favor)*10, 50) + canvas.SetRGB255(231, 27, 100) + canvas.Fill() + i++ + } + data, cl := writer.ToBytes(canvas.Image()) + ctx.SendChain(message.ImageBytes(data)) + cl() + }) +} + +// nolint: asciicheck +//nolint: asciicheck +func (sql *婚姻登记) 查好感度(uid, target int64) (int, error) { + sql.Lock() + defer sql.Unlock() + err := sql.db.Create("favorability", &favorability{}) + if err != nil { + 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+"*'") + return info.Favor, nil +} + +// 获取好感度数据组 +type favorList []favorability + +func (s favorList) Len() int { + return len(s) +} +func (s favorList) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} +func (s favorList) Less(i, j int) bool { + return s[i].Favor > s[j].Favor +} +func (sql *婚姻登记) getGroupFavorability(uid int64) (list favorList, err error) { + uidStr := strconv.FormatInt(uid, 10) + sql.RLock() + defer sql.RUnlock() + info := favorability{} + err = sql.db.FindFor("favorability", &info, "where Userinfo glob '*"+uidStr+"*'", func() error { + var target string + userList := strings.Split(info.Userinfo, "+") + switch { + case len(userList) == 0: + return errors.New("好感度系统数据存在错误") + case userList[0] == uidStr: + target = userList[1] + default: + target = userList[0] + } + list = append(list, favorability{ + Userinfo: target, + Favor: info.Favor, + }) + return nil + }) + sort.Sort(list) + return +} + +// nolint: asciicheck +//nolint: asciicheck +// 设置好感度 正增负减 +func (sql *婚姻登记) 更新好感度(uid, target int64, score int) (favor int, err error) { + sql.Lock() + defer sql.Unlock() + err = sql.db.Create("favorability", &favorability{}) + if err != nil { + return + } + 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 + info.Favor += score + if info.Favor > 100 { + info.Favor = 100 + } else if info.Favor < 0 { + info.Favor = 0 + } + err = sql.db.Insert("favorability", &info) + return info.Favor, err +} diff --git a/plugin/qqwife/function.go b/plugin/qqwife/function.go index a35d8a1b74..2d74b5d0eb 100644 --- a/plugin/qqwife/function.go +++ b/plugin/qqwife/function.go @@ -2,259 +2,405 @@ package qqwife import ( "errors" - "sort" + "math/rand" "strconv" - "strings" - "sync" "time" - sql "github.com/FloatTech/sqlite" + "github.com/FloatTech/zbputils/ctxext" zero "github.com/wdvxdr1123/ZeroBot" "github.com/wdvxdr1123/ZeroBot/message" - - // 画图 - "github.com/Coloured-glaze/gg" ) -// nolint: asciicheck -// nolint: asciicheck -type 婚姻登记 struct { - db *sql.Sqlite - sync.RWMutex -} - -// 结婚证信息 -type userinfo struct { - User int64 // 用户身份证 - Target int64 // 对象身份证号 - Username string // 户主名称 - Targetname string // 对象名称 - Updatetime string // 登记时间 - -} - -// 民政局的当前时间 -type updateinfo struct { - GID int64 - Updatetime string // 登记时间 - CanMatch int // 订婚开关 - CanNtr int // Ntr技能开关 - CDtime float64 // CD时间 -} - -// 好感度系统 -type favorability struct { - Userinfo string // 记录用户 - Favor int // 好感度 -} - // 技能CD记录表 type cdsheet struct { - Time int64 // 时间 - GroupID int64 // 群号 - UserID int64 // 用户 - ModeID int64 // 技能类型 + Time int64 // 时间 + GroupID int64 // 群号 + UserID int64 // 用户 + Model string // 技能类型 } -func (sql *婚姻登记) 开门时间(gid int64) (ok bool, err error) { - sql.Lock() - defer sql.Unlock() - ok = false - err = sql.db.Create("updateinfo", &updateinfo{}) - if err != nil { - return - } - gidstr := strconv.FormatInt(gid, 10) - dbinfo := updateinfo{} - // 获取表格更新的时间 - err = sql.db.Find("updateinfo", &dbinfo, "where gid is "+gidstr) - if err != nil { - // 如果没有登记过就记录 - err = sql.db.Insert("updateinfo", &updateinfo{ - GID: gid, - Updatetime: time.Now().Format("2006/01/02"), - CanMatch: 1, - CanNtr: 1, - CDtime: 12, - }) - if err == nil { - ok = true - } - return +var sendtext = [...][]string{ + { // 表白成功 + "是个勇敢的孩子(*/ω\*) 今天的运气都降临在你的身边~\n\n", + "(´・ω・`)对方答应了你 并表示愿意当今天的CP\n\n", + }, + { // 表白失败 + "今天的运气有一点背哦~明天再试试叭", + "_(:з」∠)_下次还有机会 咱抱抱你w", + "今天失败了惹. 摸摸头~咱明天还有机会", + }, + { // ntr成功 + "因为你的个人魅力~~今天他就是你的了w\n\n", + }, + { // 离婚失败 + "打是情,骂是爱,不打不亲不相爱。答应我不要分手。", + "床头打架床尾和,夫妻没有隔夜仇。安啦安啦,不要闹变扭。", + }, + { // 离婚成功 + "离婚成功力\n话说你不考虑当个1?", + "离婚成功力\n天涯何处无芳草,何必单恋一枝花?不如再摘一支(bushi", + }, } - if time.Now().Format("2006/01/02") == dbinfo.Updatetime { - return - } - // 开门了就拿新的花名册 - err = sql.db.Drop("group" + gidstr) - if err != nil { - if err = sql.db.Create("group"+gidstr, &userinfo{}); err != nil { - return - } - } - dbinfo.Updatetime = time.Now().Format("2006/01/02") - err = sql.db.Insert("updateinfo", &dbinfo) - if err == nil { - ok = true - } - return -} -func (sql *婚姻登记) 营业模式(gid int64) (canMatch, canNtr int, err error) { - sql.Lock() - defer sql.Unlock() - err = sql.db.Create("updateinfo", &updateinfo{}) - if err != nil { - if err = sql.db.Drop("updateinfo"); err == nil { - err = sql.db.Create("updateinfo", &updateinfo{}) - } - if err != nil { - return - } - } - gidstr := strconv.FormatInt(gid, 10) - dbinfo := updateinfo{} - err = sql.db.Find("updateinfo", &dbinfo, "where gid is "+gidstr) - if err != nil { - canMatch = 1 - canNtr = 1 - err = sql.db.Insert("updateinfo", &updateinfo{ - GID: gid, - CanMatch: canMatch, - CanNtr: canNtr, - CDtime: 12, +func init() { + engine.OnRegex(`^设置CD为(\d+)小时`, zero.OnlyGroup, zero.AdminPermission, getdb).SetBlock(true).Limit(ctxext.LimitByUser). + Handle(func(ctx *zero.Ctx) { + cdTime, err := strconv.ParseFloat(ctx.State["regex_matched"].([]string)[1], 64) + if err != nil { + ctx.SendChain(message.Text("[qqwife]请设置纯数字\n", err)) + return + } + groupInfo, err := 民政局.查看设置(ctx.Event.GroupID) + if err != nil { + ctx.SendChain(message.Text("[ERROR]:", err)) + return + } + groupInfo.CDtime = cdTime + err = 民政局.更新设置(groupInfo) + if err != nil { + ctx.SendChain(message.Text("[qqwife]设置CD时长失败\n", err)) + return + } + ctx.SendChain(message.Text("设置成功")) }) - return - } - canMatch = dbinfo.CanMatch - canNtr = dbinfo.CanNtr - return -} - -func (sql *婚姻登记) 修改模式(gid int64, mode string, stauts int) (err error) { - sql.Lock() - defer sql.Unlock() - err = sql.db.Create("updateinfo", &updateinfo{}) - if err != nil { - if err = sql.db.Drop("updateinfo"); err == nil { - err = sql.db.Create("updateinfo", &updateinfo{}) - } - if err != nil { - return - } - } - gidstr := strconv.FormatInt(gid, 10) - dbinfo := updateinfo{} - err = sql.db.Find("updateinfo", &dbinfo, "where gid is "+gidstr) - switch mode { - case "自由恋爱": - dbinfo.CanMatch = stauts - case "牛头人": - dbinfo.CanNtr = stauts - default: - return errors.New("错误:修改内容不匹配!") - } - if err != nil { - dbinfo.GID = gid - switch mode { - case "自由恋爱": - dbinfo.CanNtr = 1 - case "牛头人": - dbinfo.CanMatch = 1 - } - dbinfo.CDtime = 12 - err = sql.db.Insert("updateinfo", &dbinfo) - return - } - err = sql.db.Insert("updateinfo", &dbinfo) - return -} - -func (sql *婚姻登记) 清理花名册(gid string) error { - sql.Lock() - defer sql.Unlock() - grouplist, err := sql.db.ListTables() - if err != nil { - return err - } - if gid != "0" { - grouplist = []string{"group" + gid} - } - for _, gid := range grouplist { - if gid == "favorability" { - continue - } - err = sql.db.Drop(gid) - if err != nil || gid == "updateinfo" { - continue - } - gidint, _ := strconv.ParseInt(gid, 10, 64) - upinfo := updateinfo{ - GID: gidint, - Updatetime: time.Now().Format("2006/01/02"), - CanMatch: 1, - CanNtr: 1, - CDtime: 12, - } - err = sql.db.Create("updateinfo", &updateinfo{}) - if err != nil { - if err = sql.db.Drop("updateinfo"); err == nil { - err = sql.db.Create("updateinfo", &updateinfo{}) + engine.OnRegex(`^(允许|禁止)(自由恋爱|牛头人)$`, zero.OnlyGroup, zero.AdminPermission, getdb).SetBlock(true). + Handle(func(ctx *zero.Ctx) { + status := ctx.State["regex_matched"].([]string)[1] + mode := ctx.State["regex_matched"].([]string)[2] + groupInfo, err := 民政局.查看设置(ctx.Event.GroupID) + switch { + case err != nil: + ctx.SendChain(message.Text("[ERROR]:", err)) + return + case mode == "自由恋爱": + if status == "允许" { + groupInfo.CanMatch = 1 + } else { + groupInfo.CanMatch = 0 + } + case mode == "牛头人": + if status == "允许" { + groupInfo.CanNtr = 1 + } else { + groupInfo.CanNtr = 0 + } } + err = 民政局.更新设置(groupInfo) if err != nil { - return err + ctx.SendChain(message.Text("[ERROR]:", err)) + return } - } - err = sql.db.Insert("updateinfo", &upinfo) - } - return err + ctx.SendChain(message.Text("设置成功")) + }) + // 单身技能 + engine.OnRegex(`^(娶|嫁)\[CQ:at,qq=(\d+)\]`, zero.OnlyGroup, getdb, checkSingleDog).SetBlock(true).Limit(ctxext.LimitByUser). + Handle(func(ctx *zero.Ctx) { + gid := ctx.Event.GroupID + uid := ctx.Event.UserID + choice := ctx.State["regex_matched"].([]string)[1] + fiancee, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64) + // 写入CD + err := 民政局.记录CD(gid, uid, "嫁娶") + if err != nil { + ctx.SendChain(message.At(uid), message.Text("[qqwife]你的技能CD记录失败\n", err)) + } + if uid == fiancee { // 如果是自己 + switch rand.Intn(3) { + case 1: + err := 民政局.登记(gid, uid, 0, "", "") + if err != nil { + ctx.SendChain(message.Text("[ERROR]:", err)) + return + } + ctx.SendChain(message.Text("今日获得成就:单身贵族")) + default: + ctx.SendChain(message.Text("今日获得成就:自恋狂")) + } + return + } + favor, err := 民政局.查好感度(uid, fiancee) + if err != nil { + ctx.SendChain(message.Text("[ERROR]:", err)) + return + } + if favor < 30 { + favor = 30 // 保底30%概率 + } + if rand.Intn(101) >= favor { + ctx.SendChain(message.Text(sendtext[1][rand.Intn(len(sendtext[1]))])) + return + } + // 去民政局登记 + var choicetext string + switch choice { + case "娶": + err := 民政局.登记(gid, uid, fiancee, ctx.CardOrNickName(uid), ctx.CardOrNickName(fiancee)) + if err != nil { + ctx.SendChain(message.Text("[ERROR]:", err)) + return + } + choicetext = "\n今天你的群老婆是" + default: + err := 民政局.登记(gid, fiancee, uid, ctx.CardOrNickName(fiancee), ctx.CardOrNickName(uid)) + if err != nil { + ctx.SendChain(message.Text("[ERROR]:", err)) + return + } + choicetext = "\n今天你的群老公是" + } + // 请大家吃席 + ctx.SendChain( + message.Text(sendtext[0][rand.Intn(len(sendtext[0]))]), + message.At(uid), + message.Text(choicetext), + message.Image("http://q4.qlogo.cn/g?b=qq&nk="+strconv.FormatInt(fiancee, 10)+"&s=640").Add("cache", 0), + message.Text( + "\n", + "[", ctx.CardOrNickName(fiancee), "]", + "(", fiancee, ")哒", + ), + ) + }) + // NTR技能 + engine.OnRegex(`^当(\[CQ:at,qq=(\d+)\]\s?|(\d+))的小三`, zero.OnlyGroup, getdb, checkMistress).SetBlock(true).Limit(ctxext.LimitByUser). + Handle(func(ctx *zero.Ctx) { + gid := ctx.Event.GroupID + uid := ctx.Event.UserID + fid := ctx.State["regex_matched"].([]string) + fiancee, _ := strconv.ParseInt(fid[2]+fid[3], 10, 64) + // 写入CD + err := 民政局.记录CD(gid, uid, "NTR") + if err != nil { + ctx.SendChain(message.At(uid), message.Text("[qqwife]你的技能CD记录失败\n", err)) + } + if fiancee == uid { + ctx.SendChain(message.Text("今日获得成就:自我攻略")) + return + } + favor, err := 民政局.查好感度(uid, fiancee) + if err != nil { + ctx.SendChain(message.Text("[ERROR]:", err)) + return + } + if favor < 30 { + favor = 30 // 保底10%概率 + } + if rand.Intn(101) >= favor/3 { + ctx.SendChain(message.Text("失败了!可惜")) + return + } + // 判断target是老公还是老婆 + var choicetext string + var ntrID = uid + var targetID = fiancee + var greenID int64 //被牛的 + fianceeInfo, err := 民政局.查户口(gid, fiancee) + switch { + case err != nil: + ctx.SendChain(message.Text("[ERROR]:", err)) + return + case fianceeInfo.User == fiancee: // 是1 + err = 民政局.离婚休妻(gid, fianceeInfo.Target) + if err != nil { + ctx.SendChain(message.Text("ta不想和原来的对象分手...\n[error]", err)) + return + } + ntrID = fiancee + targetID = ctx.Event.UserID + greenID = fianceeInfo.Target + choicetext = "老公" + case fianceeInfo.Target == fiancee: // 是0 + err = 民政局.离婚休夫(gid, fianceeInfo.User) + if err != nil { + ctx.SendChain(message.Text("ta不想和原来的对象分手...\n[error]", err)) + return + } + greenID = fianceeInfo.Target + choicetext = "老婆" + default: + ctx.SendChain(message.Text("数据库发生问题力")) + return + } + err = 民政局.登记(gid, ntrID, targetID, ctx.CardOrNickName(ntrID), ctx.CardOrNickName(targetID)) + if err != nil { + ctx.SendChain(message.Text("[qqwife]复婚登记失败力\n", err)) + return + } + favor, err = 民政局.更新好感度(uid, fiancee, -5) + if err != nil { + ctx.SendChain(message.Text("[ERROR]:", err)) + } + _, err = 民政局.更新好感度(uid, greenID, 5) + if err != nil { + ctx.SendChain(message.Text("[ERROR]:", err)) + } + // 输出结果 + ctx.SendChain( + message.Text(sendtext[2][rand.Intn(len(sendtext[2]))]), + message.At(uid), + message.Text("今天你的群"+choicetext+"是"), + message.Image("http://q4.qlogo.cn/g?b=qq&nk="+strconv.FormatInt(fiancee, 10)+"&s=640").Add("cache", 0), + message.Text( + "\n", + "[", ctx.CardOrNickName(fiancee), "]", + "(", fiancee, ")哒\n当前你们好感度为", favor, + ), + ) + }) + // 做媒技能 + engine.OnRegex(`^做媒\s?\[CQ:at,qq=(\d+)\]\s?\[CQ:at,qq=(\d+)\]`, zero.OnlyGroup, zero.AdminPermission, getdb, checkMatchmaker).SetBlock(true).Limit(ctxext.LimitByUser). + Handle(func(ctx *zero.Ctx) { + gid := ctx.Event.GroupID + uid := ctx.Event.UserID + gayOne, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[1], 10, 64) + gayZero, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64) + // 写入CD + err := 民政局.记录CD(gid, uid, "做媒") + if err != nil { + ctx.SendChain(message.At(uid), message.Text("[qqwife]你的技能CD记录失败\n", err)) + } + favor, err := 民政局.查好感度(gayOne, gayZero) + if err != nil { + ctx.SendChain(message.Text("[ERROR]:", err)) + return + } + if favor < 30 { + favor = 30 // 保底30%概率 + } + if rand.Intn(101) >= favor { + _, err = 民政局.更新好感度(uid, gayOne, -1) + if err != nil { + ctx.SendChain(message.Text("[ERROR]:", err)) + } + _, err = 民政局.更新好感度(uid, gayZero, -1) + if err != nil { + ctx.SendChain(message.Text("[ERROR]:", err)) + } + ctx.SendChain(message.Text(sendtext[1][rand.Intn(len(sendtext[1]))])) + return + } + // 去民政局登记 + err = 民政局.登记(gid, gayOne, gayZero, ctx.CardOrNickName(gayOne), ctx.CardOrNickName(gayZero)) + if err != nil { + ctx.SendChain(message.Text("[ERROR]:", err)) + return + } + _, err = 民政局.更新好感度(uid, gayOne, 1) + if err != nil { + ctx.SendChain(message.Text("[ERROR]:", err)) + } + _, err = 民政局.更新好感度(uid, gayZero, 1) + if err != nil { + ctx.SendChain(message.Text("[ERROR]:", err)) + } + _, err = 民政局.更新好感度(gayOne, gayZero, 1) + if err != nil { + ctx.SendChain(message.Text("[ERROR]:", err)) + } + // 请大家吃席 + ctx.SendChain( + message.At(uid), + message.Text("恭喜你成功撮合了一对CP\n\n"), + message.At(gayOne), + message.Text("今天你的群老婆是"), + message.Image("http://q4.qlogo.cn/g?b=qq&nk="+strconv.FormatInt(gayZero, 10)+"&s=640").Add("cache", 0), + message.Text( + "\n", + "[", ctx.CardOrNickName(gayZero), "]", + "(", gayZero, ")哒", + ), + ) + }) + engine.OnFullMatchGroup([]string{"闹离婚", "办离婚"}, zero.OnlyGroup, getdb, checkDivorce).Limit(ctxext.LimitByUser).SetBlock(true). + Handle(func(ctx *zero.Ctx) { + gid := ctx.Event.GroupID + uid := ctx.Event.UserID + // 写入CD + err := 民政局.记录CD(gid, uid, "离婚") + if err != nil { + ctx.SendChain(message.At(uid), message.Text("[qqwife]你的技能CD记录失败\n", err)) + } + mun := -1 + var fiancee int64 + userInfo, _ := 民政局.查户口(gid, uid) + switch { + case userInfo.User == uid: + mun = 1 + fiancee = userInfo.Target + case userInfo.Target == uid: + mun = 0 + fiancee = userInfo.User + } + favor, err := 民政局.查好感度(uid, fiancee) + if err != nil { + ctx.SendChain(message.Text("[ERROR]:", err)) + return + } + if favor < 20 { + favor = 10 + } + if rand.Intn(101) > 110-favor { + ctx.SendChain(message.Text(sendtext[3][rand.Intn(len(sendtext[3]))])) + return + } + switch mun { + case 1: + err = 民政局.离婚休妻(gid, fiancee) + case 0: + err = 民政局.离婚休夫(gid, fiancee) + default: + err = errors.New("用户数据查找发生错误") + } + if err != nil { + ctx.SendChain(message.Text("[ERROR]:", err)) + return + } + ctx.SendChain(message.Text(sendtext[4][mun])) + }) } -func (sql *婚姻登记) 查户口(gid, uid int64) (info userinfo, status string, err error) { +// nolint: asciicheck +//nolint: asciicheck +func (sql *婚姻登记) 判断CD(gid, uid int64, model string, cdtime float64) (ok bool, err error) { sql.Lock() defer sql.Unlock() - gidstr := "group" + strconv.FormatInt(gid, 10) - uidstr := strconv.FormatInt(uid, 10) - status = "单" - err = sql.db.Create(gidstr, &userinfo{}) + // 创建群表格 + err = sql.db.Create("cdsheet", &cdsheet{}) if err != nil { - status = "错" return } - err = sql.db.Find(gidstr, &info, "where user = "+uidstr) - if err == nil { - status = "攻" - return + limitID := "where GroupID is " + strconv.FormatInt(gid, 10) + + " and UserID is " + strconv.FormatInt(uid, 10) + + " and Model is '" + model + "'" + if !sql.db.CanFind("cdsheet", limitID) { + // 没有记录即不用比较 + return true, nil } - err = sql.db.Find(gidstr, &info, "where target = "+uidstr) - if err == nil { - status = "受" + cdinfo := cdsheet{} + _ = sql.db.Find("cdsheet", &cdinfo, limitID) + if time.Since(time.Unix(cdinfo.Time, 0)).Hours() > cdtime { + // 如果CD已过就删除 + err = sql.db.Del("cdsheet", limitID) + return true, err } - return + return false, nil } -func (sql *婚姻登记) 登记(gid, uid, target int64, username, targetname string) error { +// nolint: asciicheck +//nolint: asciicheck +func (sql *婚姻登记) 记录CD(gid, uid int64, mode string) error { sql.Lock() defer sql.Unlock() - gidstr := "group" + strconv.FormatInt(gid, 10) - err := sql.db.Create(gidstr, &userinfo{}) - if err != nil { - return err - } - updatetime := time.Now().Format("15:04:05") - // 填写夫妻信息 - uidinfo := userinfo{ - User: uid, - Username: username, - Target: target, - Targetname: targetname, - Updatetime: updatetime, - } - // 民政局登记数据 - err = sql.db.Insert(gidstr, &uidinfo) - return err + return sql.db.Insert("cdsheet", &cdsheet{ + Time: time.Now().Unix(), + GroupID: gid, + UserID: uid, + Model: mode, + }) } +// nolint: asciicheck +//nolint: asciicheck func (sql *婚姻登记) 离婚休妻(gid, wife int64) error { sql.Lock() defer sql.Unlock() @@ -263,6 +409,8 @@ func (sql *婚姻登记) 离婚休妻(gid, wife int64) error { return sql.db.Del(gidstr, "where target = "+wifestr) } +// nolint: asciicheck +//nolint: asciicheck func (sql *婚姻登记) 离婚休夫(gid, husband int64) error { sql.Lock() defer sql.Unlock() @@ -271,477 +419,172 @@ func (sql *婚姻登记) 离婚休夫(gid, husband int64) error { return sql.db.Del(gidstr, "where user = "+husbandstr) } -func (sql *婚姻登记) 花名册(gid int64) (list [][4]string, number int, err error) { - sql.Lock() - defer sql.Unlock() - gidstr := "group" + strconv.FormatInt(gid, 10) - err = sql.db.Create(gidstr, &userinfo{}) - if err != nil { - return - } - number, err = sql.db.Count(gidstr) - if err != nil || number <= 0 { - return - } - var info userinfo - list = make([][4]string, 0, number) - err = sql.db.FindFor(gidstr, &info, "GROUP BY user", func() error { - if info.Target == 0 { - return nil - } - dbinfo := [4]string{ - info.Username, - strconv.FormatInt(info.User, 10), - info.Targetname, - strconv.FormatInt(info.Target, 10), - } - list = append(list, dbinfo) - return nil - }) - number = len(list) - return -} - -func slicename(name string, canvas *gg.Context) (resultname string) { - usermane := []rune(name) // 将每个字符单独放置 - widthlen := 0 - numberlen := 0 - for i, v := range usermane { - width, _ := canvas.MeasureString(string(v)) // 获取单个字符的宽度 - widthlen += int(width) - if widthlen > 350 { - break // 总宽度不能超过350 - } - numberlen = i - } - if widthlen > 350 { - resultname = string(usermane[:numberlen-1]) + "......" // 名字切片 - } else { - resultname = name - } - return -} - -// 获取好感度 -func (sql *婚姻登记) getFavorability(uid, target int64) (favor int, err error) { - sql.Lock() - defer sql.Unlock() - err = sql.db.Create("favorability", &favorability{}) - if err != nil { - return - } - info := favorability{} - uidstr := strconv.FormatInt(uid, 10) - targstr := strconv.FormatInt(target, 10) - err = sql.db.Find("favorability", &info, "where Userinfo glob '*"+uidstr+"+"+targstr+"*'") - if err != nil { - err = sql.db.Insert("favorability", &favorability{ - Userinfo: uidstr + "+" + targstr + "+" + uidstr, - Favor: 0, - }) - return - } - favor = info.Favor - return -} - -// 获取好感度数据组 -type favorList []favorability - -func (s favorList) Len() int { - return len(s) -} -func (s favorList) Swap(i, j int) { - s[i], s[j] = s[j], s[i] -} -func (s favorList) Less(i, j int) bool { - return s[i].Favor > s[j].Favor -} -func (sql *婚姻登记) getGroupFavorability(uid int64) (list favorList, err error) { - uidStr := strconv.FormatInt(uid, 10) - sql.RLock() - defer sql.RUnlock() - info := favorability{} - err = sql.db.FindFor("favorability", &info, "where Userinfo glob '*"+uidStr+"*'", func() error { - var target string - userList := strings.Split(info.Userinfo, "+") - switch { - case len(userList) == 0: - return errors.New("好感度系统数据存在错误") - case userList[0] == uidStr: - target = userList[1] - default: - target = userList[0] - } - list = append(list, favorability{ - Userinfo: target, - Favor: info.Favor, - }) - return nil - }) - sort.Sort(list) - return -} - -// 设置好感度 正增负减 -func (sql *婚姻登记) setFavorability(uid, target int64, score int) (favor int, err error) { - sql.Lock() - defer sql.Unlock() - err = sql.db.Create("favorability", &favorability{}) - if err != nil { - return - } - info := favorability{} - uidstr := strconv.FormatInt(uid, 10) - targstr := strconv.FormatInt(target, 10) - err = sql.db.Find("favorability", &info, "where Userinfo glob '*"+uidstr+"+"+targstr+"*'") - if err != nil { - err = sql.db.Insert("favorability", &favorability{ - Userinfo: uidstr + "+" + targstr + "+" + uidstr, - Favor: score, - }) - if err == nil { - err = sql.db.Find("favorability", &info, "where Userinfo glob '*"+uidstr+"+"+targstr+"*'") - } - return info.Favor, err - } - info.Favor += score - if info.Favor > 100 { - info.Favor = 100 - } else if info.Favor < 0 { - info.Favor = 0 - } - err = sql.db.Insert("favorability", &info) - return info.Favor, err -} - -// 获取技能时长 -func (sql *婚姻登记) getCDtime(gid int64) (skillCD float64, err error) { - sql.Lock() - defer sql.Unlock() - skillCD = 12 - err = sql.db.Create("updateinfo", &updateinfo{}) - if err != nil { - if err = sql.db.Drop("updateinfo"); err == nil { - err = sql.db.Create("updateinfo", &updateinfo{}) - } - if err != nil { - return - } - } - gidstr := strconv.FormatInt(gid, 10) - dbinfo := updateinfo{} - err = sql.db.Find("updateinfo", &dbinfo, "where gid is "+gidstr) - if err != nil { - // 如果没有登记过就记录 - err = sql.db.Insert("updateinfo", &updateinfo{ - GID: gid, - CanMatch: 1, - CanNtr: 1, - CDtime: 12, - }) - return - } - return dbinfo.CDtime, nil -} - -// 设置技能时长 -func (sql *婚姻登记) setCDtime(gid int64, cdTime float64) (err error) { - sql.Lock() - defer sql.Unlock() - err = sql.db.Create("updateinfo", &updateinfo{}) - if err != nil { - if err = sql.db.Drop("updateinfo"); err == nil { - err = sql.db.Create("updateinfo", &updateinfo{}) - } - if err != nil { - return - } - } - gidstr := strconv.FormatInt(gid, 10) - dbinfo := updateinfo{} - err = sql.db.Find("updateinfo", &dbinfo, "where gid is "+gidstr) - if err != nil { - // 如果没有登记过就记录 - err = sql.db.Insert("updateinfo", &updateinfo{ - GID: gid, - CanMatch: 1, - CanNtr: 1, - CDtime: cdTime, - }) - return - } - dbinfo.CDtime = cdTime - err = sql.db.Insert("updateinfo", &dbinfo) - return -} - -// 记录CD -func (sql *婚姻登记) writeCDtime(gid, uid, mun int64) error { - sql.Lock() - defer sql.Unlock() - err := sql.db.Create("cdsheet", &cdsheet{}) - if err != nil { - if err = sql.db.Drop("cdsheet"); err == nil { - err = sql.db.Create("cdsheet", &cdsheet{}) - } - if err != nil { - return err - } - } - err = sql.db.Insert("cdsheet", &cdsheet{ - Time: time.Now().Unix(), - GroupID: gid, - UserID: uid, - ModeID: mun, - }) - return err -} - -// 判断CD是否过时 -func (sql *婚姻登记) compareCDtime(gid, uid, mun int64, cdtime float64) (ok bool, err error) { - sql.Lock() - defer sql.Unlock() - ok = false - err = sql.db.Create("cdsheet", &cdsheet{}) - if err != nil { - if err = sql.db.Drop("cdsheet"); err == nil { - err = sql.db.Create("cdsheet", &cdsheet{}) - } - if err != nil { - return - } - } - limitID := "where GroupID is " + strconv.FormatInt(gid, 10) + - " and UserID is " + strconv.FormatInt(uid, 10) + - " and ModeID is " + strconv.FormatInt(mun, 10) - exist := sql.db.CanFind("cdsheet", limitID) - if !exist { - return true, nil - } - cdinfo := cdsheet{} - err = sql.db.Find("cdsheet", &cdinfo, limitID) - if err != nil { - return - } - getTime := time.Unix(cdinfo.Time, 0) - if time.Since(getTime).Hours() > cdtime { - // 如果CD已过就删除 - err = sql.db.Del("cdsheet", limitID) - return true, err - } - return -} - -// 注入判断 是否为单身 -func checkdog(ctx *zero.Ctx) bool { +// 注入判断 是否单身条件 +func checkSingleDog(ctx *zero.Ctx) bool { gid := ctx.Event.GroupID uid := ctx.Event.UserID - // 获取CD - cdTime, err := 民政局.getCDtime(gid) - if err != nil { - ctx.SendChain(message.Text("[qqwife]获取该群技能CD错误(将以CD12H计算)\n", err)) - } - ok, err := 民政局.compareCDtime(gid, uid, 1, cdTime) + fiancee, err := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64) if err != nil { - ctx.SendChain(message.Text("[qqwife]查询用户CD状态失败,请重试\n", err)) + ctx.SendChain(message.Text("额,你的target好像不存在?")) return false } - if !ok { - ctx.SendChain(message.Text("你的技能还在CD中...")) + // 判断是否需要重置 + err = 民政局.开门时间(gid) + if err != nil { + ctx.SendChain(message.Text("[ERROR]:", err)) return false } // 判断是否符合条件 - stauts, _, err := 民政局.营业模式(gid) + groupInfo, err := 民政局.查看设置(gid) if err != nil { - ctx.SendChain(message.Text("[qqwife]", err)) + ctx.SendChain(message.Text("[ERROR]:", err)) return false } - if stauts == 0 { + if groupInfo.CanMatch == 0 { ctx.SendChain(message.Text("你群包分配,别在娶妻上面下功夫,好好水群")) return false } - // 得先判断用户是否存在才行在,再重置 - fiancee, err := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64) - if err != nil { - ctx.SendChain(message.Text("额,你的target好像不存在?")) - return false - } - // 判断是否需要重置 - ok, err = 民政局.开门时间(gid) - if err != nil { - ctx.SendChain(message.Text("[qqwife]群状态查询失败\n", err)) - return false - } - if ok { - return true // 重置后也全是单身 - } // 获取用户信息 - uidtarget, uidstatus, err := 民政局.查户口(gid, uid) + userInfo, _ := 民政局.查户口(gid, uid) switch { - case uidstatus == "错": - ctx.SendChain(message.Text("[qqwife]用户状态查询失败\n", err)) - return false - case uidstatus != "单" && (uidtarget.Target == 0 || uidtarget.User == 0): // 如果是单身贵族 + case userInfo != (userinfo{}) && (userInfo.Target == 0 || userInfo.User == 0): // 如果是单身贵族 ctx.SendChain(message.Text("今天的你是单身贵族噢")) return false - case (uidstatus == "攻" && uidtarget.Target == fiancee) || - (uidstatus == "受" && uidtarget.User == fiancee): + case userInfo.Target == fiancee || userInfo.User == fiancee: ctx.SendChain(message.Text("笨蛋!你们已经在一起了!")) return false - case uidstatus == "攻": // 如果如为攻 + case userInfo.User == uid: // 如果如为攻 ctx.SendChain(message.Text("笨蛋~你家里还有个吃白饭的w")) return false - case uidstatus == "受": // 如果为受 - ctx.SendChain(message.Text("该是0就是0,当0有什么不好")) + case userInfo.Target == uid: // 如果为受 + ctx.SendChain(message.Text("该是0就是0,当0有什么不好")) return false } - fianceeinfo, fianceestatus, err := 民政局.查户口(gid, fiancee) + fianceeInfo, _ := 民政局.查户口(gid, fiancee) switch { - case fianceestatus == "错": - ctx.SendChain(message.Text("[qqwife]对象状态查询失败\n", err)) - case fianceestatus == "单": // 如果为单身狗 - return true - case fianceestatus != "单" && (fianceeinfo.Target == 0 || fianceeinfo.User == 0): // 如果是单身贵族 + case fianceeInfo != (userinfo{}) && (fianceeInfo.Target == 0 || fianceeInfo.User == 0): // 如果是单身贵族 ctx.SendChain(message.Text("今天的ta是单身贵族噢")) - case fianceestatus == "攻": // 如果如为攻 + return false + case fianceeInfo.User == uid: // 如果如为攻 ctx.SendChain(message.Text("他有别的女人了,你该放下了")) - case fianceestatus == "受": // 如果为受 - ctx.SendChain(message.Text("ta被别人娶了,你来晚力")) + return false + case fianceeInfo.Target == uid: // 如果为受 + ctx.SendChain(message.Text("ta被别人娶了,你来晚力")) + return false } - return false + // 判断CD + ok, err := 民政局.判断CD(gid, uid, "嫁娶", groupInfo.CDtime) + switch { + case err != nil: + ctx.SendChain(message.Text("[ERROR]:", err)) + return false + case !ok: + ctx.SendChain(message.Text("你的技能还在CD中...")) + return false + } + return true } // 注入判断 是否满足小三要求 -func checkcp(ctx *zero.Ctx) bool { +func checkMistress(ctx *zero.Ctx) bool { gid := ctx.Event.GroupID uid := ctx.Event.UserID - // 获取CD - cdTime, err := 民政局.getCDtime(gid) - if err != nil { - ctx.SendChain(message.Text("[qqwife]获取该群技能CD错误(将以CD12H计算)\n", err)) - } - ok, err := 民政局.compareCDtime(gid, uid, 2, cdTime) + fiancee, err := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64) if err != nil { - ctx.SendChain(message.Text("[qqwife]查询用户CD状态失败,请重试\n", err)) + ctx.SendChain(message.Text("额,你的target好像不存在?")) return false } - if !ok { - ctx.SendChain(message.Text("你的技能还在CD中...")) + // 判断是否需要重置 + err = 民政局.开门时间(gid) + if err != nil { + ctx.SendChain(message.Text("[ERROR]:", err)) return false } // 判断是否符合条件 - _, stauts, err := 民政局.营业模式(gid) + groupInfo, err := 民政局.查看设置(gid) if err != nil { - ctx.SendChain(message.Text("[qqwife]", err)) + ctx.SendChain(message.Text("[ERROR]:", err)) return false } - if stauts == 0 { + if groupInfo.CanNtr == 0 { ctx.SendChain(message.Text("你群发布了牛头人禁止令,放弃吧")) return false } - // 得先判断用户是否存在才行在,再重置 - fiancee, err := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64) - if err != nil { - ctx.SendChain(message.Text("额,你的target好像不存在?")) + // 获取用户信息 + fianceeInfo, _ := 民政局.查户口(gid, fiancee) + switch { + case fianceeInfo == (userinfo{}): // 如果是空数据 + ctx.SendChain(message.Text("ta现在还是单身哦,快向ta表白吧!")) return false - } - // 判断是否需要重置 - ok, err = 民政局.开门时间(gid) - if err != nil { - ctx.SendChain(message.Text("[qqwife]群状态查询失败\n", err)) + case fianceeInfo.Target == 0 || fianceeInfo.User == 0: // 如果是单身贵族 + ctx.SendChain(message.Text("今天的ta是单身贵族噢")) return false } - if ok { - ctx.SendChain(message.Text("ta现在还是单身哦,快向ta表白吧!")) - return false // 重置后也全是单身 - } - fianceeinfo, fianceestatus, err := 民政局.查户口(gid, fiancee) + // 获取用户信息 + userInfo, _ := 民政局.查户口(gid, uid) switch { - case fianceestatus == "错": - ctx.SendChain(message.Text("[qqwife]对象状态查询失败\n", err)) + case userInfo != (userinfo{}) && (userInfo.Target == 0 || userInfo.User == 0): // 如果是单身贵族 + ctx.SendChain(message.Text("今天的你是单身贵族噢")) return false - case fianceestatus == "单": // 如果为单身狗 - if fiancee == uid { - return true - } - ctx.SendChain(message.Text("ta现在还是单身哦,快向ta表白吧!")) + case userInfo.Target == fiancee || userInfo.User == fiancee: + ctx.SendChain(message.Text("笨蛋!你们已经在一起了!")) return false - case fianceestatus != "单" && (fianceeinfo.Target == 0 || fianceeinfo.User == 0): // 如果是单身贵族 - ctx.SendChain(message.Text("今天的ta是单身贵族噢")) + case userInfo.User == uid: // 如果如为攻 + ctx.SendChain(message.Text("打灭,不给纳小妾!")) return false - case (fianceestatus == "攻" && fianceeinfo.Target == fiancee) || - (fianceestatus == "受" && fianceeinfo.User == fiancee): - ctx.SendChain(message.Text("笨蛋!你们已经在一起了!")) + case userInfo.Target == uid: // 如果为受 + ctx.SendChain(message.Text("该是0就是0,当0有什么不好")) return false } - // 获取用户信息 - uidtarget, uidstatus, err := 民政局.查户口(gid, uid) + // 判断CD + ok, err := 民政局.判断CD(gid, uid, "NTR", groupInfo.CDtime) switch { - case uidstatus == "错": - ctx.SendChain(message.Text("[qqwife]用户状态查询失败\n", err)) - case uidstatus == "单": // 如果为单身狗 - return true - case uidstatus != "单" && (uidtarget.Target == 0 || uidtarget.User == 0): // 如果是单身贵族 - ctx.SendChain(message.Text("今天的你是单身贵族噢")) - case uidstatus == "攻": // 如果如为攻 - ctx.SendChain(message.Text("打灭,不给纳小妾!")) - case uidstatus == "受": // 如果为受 - ctx.SendChain(message.Text("该是0就是0,当0有什么不好")) + case err != nil: + ctx.SendChain(message.Text("[ERROR]:", err)) + return false + case !ok: + ctx.SendChain(message.Text("你的技能还在CD中...")) + return false } - return false + return true } -// 注入判断 是否满足离婚要求 -func checkdivorce(ctx *zero.Ctx) bool { +func checkDivorce(ctx *zero.Ctx) bool { gid := ctx.Event.GroupID uid := ctx.Event.UserID - // 获取CD - cdTime, err := 民政局.getCDtime(gid) - if err != nil { - ctx.SendChain(message.Text("[qqwife]获取该群技能CD错误(将以CD12H计算)\n", err)) - } - ok, err := 民政局.compareCDtime(gid, uid, 4, cdTime) + // 判断是否需要重置 + err := 民政局.开门时间(gid) if err != nil { - ctx.SendChain(message.Text("[qqwife]查询用户CD状态失败,请重试\n", err)) - return false - } - if !ok { - ctx.SendChain(message.Text("你的技能还在CD中...")) + ctx.SendChain(message.Text("[ERROR]:", err)) return false } // 判断是否符合条件 - _, uidstatus, err := 民政局.查户口(gid, uid) - switch uidstatus { - case "错": - ctx.SendChain(message.Text("[qqwife]数据库发生问题力\n", err)) - return false - case "单": + userInfo, _ := 民政局.查户口(gid, uid) + if userInfo == (userinfo{}) { // 如果空数据 ctx.SendChain(message.Text("今天你还没结婚哦")) return false } - return true -} - -// 注入判断 是否满足做媒要求 -func checkCondition(ctx *zero.Ctx) bool { - gid := ctx.Event.GroupID - uid := ctx.Event.UserID // 获取CD - cdTime, err := 民政局.getCDtime(gid) - if err != nil { - ctx.SendChain(message.Text("[qqwife]获取该群技能CD错误(将以CD12H计算)\n", err)) - } - ok, err := 民政局.compareCDtime(gid, uid, 3, cdTime) + groupInfo, err := 民政局.查看设置(gid) if err != nil { - ctx.SendChain(message.Text("[qqwife]查询用户CD状态失败,请重试\n", err)) + ctx.SendChain(message.Text("[ERROR]:", err)) return false } - if !ok { + ok, err := 民政局.判断CD(gid, uid, "离婚", groupInfo.CDtime) + switch { + case err != nil: + ctx.SendChain(message.Text("[ERROR]:", err)) + return false + case !ok: ctx.SendChain(message.Text("你的技能还在CD中...")) return false } - // 得先判断用户是否存在才行在,再重置 + return true +} + +func checkMatchmaker(ctx *zero.Ctx) bool { + gid := ctx.Event.GroupID + uid := ctx.Event.UserID gayOne, err := strconv.ParseInt(ctx.State["regex_matched"].([]string)[1], 10, 64) if err != nil { ctx.SendChain(message.Text("额,攻方好像不存在?")) @@ -757,45 +600,54 @@ func checkCondition(ctx *zero.Ctx) bool { return false } if gayOne == gayZero { - ctx.SendChain(message.Text("你这个媒人XP很怪咧,不能这样噢")) + ctx.SendChain(message.Text("你这个媒人XP很怪咧,不能这样噢")) return false } // 判断是否需要重置 - ok, err = 民政局.开门时间(gid) + err = 民政局.开门时间(gid) if err != nil { - ctx.SendChain(message.Text("[qqwife]群状态查询失败\n", err)) + ctx.SendChain(message.Text("[ERROR]:", err)) return false } - if ok { - return true // 重置后也全是单身 - } - fianceeinfo, fianceestatus, err := 民政局.查户口(gid, gayOne) + gayOneInfo, _ := 民政局.查户口(gid, gayOne) switch { - case fianceestatus == "错": - ctx.SendChain(message.Text("[qqwife]对象状态查询失败\n", err)) - return false - case fianceestatus != "单" && (fianceeinfo.Target == 0 || fianceeinfo.User == 0): // 如果是单身贵族 + case gayOneInfo != (userinfo{}) && (gayOneInfo.Target == 0 || gayOneInfo.User == 0): // 如果是单身贵族 ctx.SendChain(message.Text("今天的攻方是单身贵族噢")) return false - case (fianceestatus == "攻" && fianceeinfo.Target == gayZero) || - (fianceestatus == "受" && fianceeinfo.User == gayZero): - ctx.SendChain(message.Text("笨蛋!ta们已经在一起了!")) + case gayOneInfo.Target == gayZero || gayOneInfo.User == gayZero: + ctx.SendChain(message.Text("笨蛋!ta们已经在一起了!")) return false - case fianceestatus != "单": + case gayOneInfo != (userinfo{}): // 如果不是单身 ctx.SendChain(message.Text("攻方不是单身,不允许给这种人做媒!")) return false } // 获取用户信息 - uidtarget, uidstatus, err := 民政局.查户口(gid, gayZero) + gayZeroInfo, _ := 民政局.查户口(gid, gayZero) switch { - case uidstatus == "错": - ctx.SendChain(message.Text("[qqwife]用户状态查询失败\n", err)) - case uidstatus == "单": // 如果为单身狗 - return true - case uidstatus != "单" && (uidtarget.Target == 0 || uidtarget.User == 0): // 如果是单身贵族 - ctx.SendChain(message.Text("今天的你是单身贵族噢")) - case uidstatus != "单": - ctx.SendChain(message.Text("受方不是单身,不允许给这种人做媒!")) + case gayOneInfo != (userinfo{}) && (gayZeroInfo.Target == 0 || gayZeroInfo.User == 0): // 如果是单身贵族 + ctx.SendChain(message.Text("今天的攻方是单身贵族噢")) + return false + case gayZeroInfo.Target == gayZero || gayZeroInfo.User == gayZero: + ctx.SendChain(message.Text("笨蛋!ta们已经在一起了!")) + return false + case gayZeroInfo != (userinfo{}): // 如果不是单身 + ctx.SendChain(message.Text("攻方不是单身,不允许给这种人做媒!")) + return false + } + // 获取CD + groupInfo, err := 民政局.查看设置(gid) + if err != nil { + ctx.SendChain(message.Text("[ERROR]:", err)) + return false + } + ok, err := 民政局.判断CD(gid, uid, "做媒", groupInfo.CDtime) + switch { + case err != nil: + ctx.SendChain(message.Text("[ERROR]:", err)) + return false + case !ok: + ctx.SendChain(message.Text("你的技能还在CD中...")) + return false } return false }