Skip to content

Commit 42a4726

Browse files
authored
修复checkupdate报错问题 (#262)
* 修复checkupdate报错问题 * Update qqmapwife.go * Update qqmapwife.go
1 parent 5c4b535 commit 42a4726

File tree

1 file changed

+58
-32
lines changed

1 file changed

+58
-32
lines changed

plugin/qqwife/qqmapwife.go

Lines changed: 58 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,19 @@ type updateinfo struct {
5353

5454
}
5555

56-
func (sql *婚姻登记) checkupdate(gid int64) (updatetime string, number int, err error) {
56+
func (sql *婚姻登记) checkupdate(gid int64) (updatetime string, err error) {
5757
sql.dbmu.Lock()
5858
defer sql.dbmu.Unlock()
5959
err = sql.db.Create("updateinfo", &updateinfo{})
6060
if err != nil {
6161
return
6262
}
63-
number, err = sql.db.Count("updateinfo")
64-
switch { // 先判断数据库是否为空
65-
case err != nil:
66-
return
67-
case number <= 0:
68-
return
69-
}
7063
gidstr := strconv.FormatInt(gid, 10)
7164
dbinfo := updateinfo{}
7265
err = sql.db.Find("updateinfo", &dbinfo, "where gid is "+gidstr) // 获取表格更新的时间
7366
if err != nil {
74-
err = sql.db.Insert("updateinfo", &updateinfo{GID: gid})
67+
updatetime = time.Now().Format("2006/01/02")
68+
err = sql.db.Insert("updateinfo", &updateinfo{GID: gid, Updatetime: updatetime})
7569
return
7670
}
7771
updatetime = dbinfo.Updatetime
@@ -83,6 +77,16 @@ func (sql *婚姻登记) 重置(gid string) error {
8377
defer sql.dbmu.Unlock()
8478
if gid != "ALL" {
8579
err := sql.db.Drop(gid)
80+
if err != nil {
81+
err = sql.db.Create(gid, &userinfo{})
82+
return err
83+
}
84+
gidint, _ := strconv.ParseInt(gid, 10, 64)
85+
updateinfo := updateinfo{
86+
GID: gidint,
87+
Updatetime: time.Now().Format("2006/01/02"),
88+
}
89+
err = sql.db.Insert("updateinfo", &updateinfo)
8690
return err
8791
}
8892
grouplist, err := sql.db.ListTables()
@@ -94,6 +98,12 @@ func (sql *婚姻登记) 重置(gid string) error {
9498
if err != nil {
9599
continue
96100
}
101+
gidint, _ := strconv.ParseInt(gid, 10, 64)
102+
updateinfo := updateinfo{
103+
GID: gidint,
104+
Updatetime: time.Now().Format("2006/01/02"),
105+
}
106+
err = sql.db.Insert("updateinfo", &updateinfo)
97107
}
98108
return err
99109
}
@@ -141,10 +151,6 @@ func (sql *婚姻登记) 复婚(gid, uid, target int64, username, targetname str
141151
info.Updatetime = updatetime
142152
// 民政局登记数据
143153
err = sql.db.Insert(gidstr, &info)
144-
if err != nil {
145-
return err
146-
}
147-
err = sql.db.Insert("updateinfo", &updateinfo{GID: gid, Updatetime: updatetime})
148154
return err
149155
}
150156

@@ -244,10 +250,6 @@ func (sql *婚姻登记) 登记(gid, uid, target int64, username, targetname str
244250
}
245251
// 民政局登记数据
246252
err = sql.db.Insert(gidstr, &uidinfo)
247-
if err != nil {
248-
return err
249-
}
250-
err = sql.db.Insert("updateinfo", &updateinfo{GID: gid, Updatetime: updatetime})
251253
return err
252254
}
253255

@@ -305,7 +307,7 @@ func init() {
305307
engine.OnFullMatch("娶群友", zero.OnlyGroup, getdb).SetBlock(true).Limit(ctxext.LimitByUser).
306308
Handle(func(ctx *zero.Ctx) {
307309
gid := ctx.Event.GroupID
308-
updatetime, _, err := 民政局.checkupdate(gid)
310+
updatetime, err := 民政局.checkupdate(gid)
309311
switch {
310312
case err != nil:
311313
ctx.SendChain(message.Text("数据库发生问题力,请联系bot管理员\n[error]", err))
@@ -511,7 +513,21 @@ func init() {
511513
})
512514
engine.OnFullMatch("群老婆列表", zero.OnlyGroup, getdb).SetBlock(true).Limit(ctxext.LimitByUser).
513515
Handle(func(ctx *zero.Ctx) {
514-
list, number, err := 民政局.花名册(ctx.Event.GroupID)
516+
gid := ctx.Event.GroupID
517+
updatetime, err := 民政局.checkupdate(gid)
518+
switch {
519+
case err != nil:
520+
ctx.SendChain(message.Text("数据库发生问题力,请联系bot管理员\n[error]", err))
521+
return
522+
case time.Now().Format("2006/01/02") != updatetime:
523+
if err := 民政局.重置(strconv.FormatInt(gid, 10)); err != nil {
524+
ctx.SendChain(message.Text("数据库发生问题力,请联系bot管理员\n[error]", err))
525+
return
526+
}
527+
ctx.SendChain(message.Text("今天还没有人结婚哦"))
528+
return
529+
}
530+
list, number, err := 民政局.花名册(gid)
515531
if err != nil {
516532
ctx.SendChain(message.Text("数据库发生问题力,请联系bot管理员\n[error]", err))
517533
return
@@ -563,9 +579,22 @@ func init() {
563579
})
564580
engine.OnFullMatchGroup([]string{"闹离婚", "办离婚"}, zero.OnlyGroup, getdb).SetBlock(true).Limit(cdcheck, iscding2).
565581
Handle(func(ctx *zero.Ctx) {
566-
uid := ctx.Event.UserID
567582
gid := ctx.Event.GroupID
583+
updatetime, err := 民政局.checkupdate(gid)
584+
switch {
585+
case err != nil:
586+
ctx.SendChain(message.Text("数据库发生问题力,请联系bot管理员\n[error]", err))
587+
return
588+
case time.Now().Format("2006/01/02") != updatetime:
589+
if err := 民政局.重置(strconv.FormatInt(gid, 10)); err != nil {
590+
ctx.SendChain(message.Text("数据库发生问题力,请联系bot管理员\n[error]", err))
591+
return
592+
}
593+
ctx.SendChain(message.Text("今天你还没有结婚哦"))
594+
return
595+
}
568596
// 获取用户信息
597+
uid := ctx.Event.UserID
569598
info, uidstatus, err := 民政局.查户口(gid, uid)
570599
switch uidstatus {
571600
case 3:
@@ -638,26 +667,26 @@ func iscding(ctx *zero.Ctx) {
638667

639668
// 注入判断 是否为单身
640669
func checkdog(ctx *zero.Ctx) bool {
670+
//得先判断用户是否存在才行在,再重置
671+
fiancee, err := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
672+
if err != nil {
673+
ctx.SendChain(message.Text("额,你的target好像不存在?"))
674+
return false
675+
}
676+
//判断是否需要重置
641677
gid := ctx.Event.GroupID
642-
updatetime, number, err := 民政局.checkupdate(gid)
678+
updatetime, err := 民政局.checkupdate(gid)
643679
switch {
644680
case err != nil:
645681
ctx.SendChain(message.Text("数据库发生问题力,请联系bot管理员\n[error]", err))
646682
return false
647-
case number == 0: // 没有任何记录就说明全是单身
648-
return true
649683
case time.Now().Format("2006/01/02") != updatetime:
650684
if err := 民政局.重置(strconv.FormatInt(gid, 10)); err != nil {
651685
ctx.SendChain(message.Text("数据库发生问题力,请联系bot管理员\n[error]", err))
652686
return false
653687
}
654688
return true // 重置后也全是单身
655689
}
656-
fiancee, err := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
657-
if err != nil {
658-
ctx.SendChain(message.Text("额,你的target好像不存在?"))
659-
return false
660-
}
661690
uid := ctx.Event.UserID
662691
// 获取用户信息
663692
uidtarget, uidstatus, err1 := 民政局.查户口(gid, uid)
@@ -698,14 +727,11 @@ func checkdog(ctx *zero.Ctx) bool {
698727
// 注入判断 是否满足小三要求
699728
func checkcp(ctx *zero.Ctx) bool {
700729
gid := ctx.Event.GroupID
701-
updatetime, number, err := 民政局.checkupdate(gid)
730+
updatetime, err := 民政局.checkupdate(gid)
702731
switch {
703732
case err != nil:
704733
ctx.SendChain(message.Text("数据库发生问题力,请联系bot管理员\n[error]", err))
705734
return false
706-
case number == 0: // 没有任何记录就说明全是单身
707-
ctx.SendChain(message.Text("ta现在还是单身哦,快向ta表白吧!"))
708-
return false
709735
case time.Now().Format("2006/01/02") != updatetime:
710736
if err := 民政局.重置(strconv.FormatInt(gid, 10)); err != nil {
711737
ctx.SendChain(message.Text("数据库发生问题力,请联系bot管理员\n[error]", err))

0 commit comments

Comments
 (0)