Skip to content

Commit f88d903

Browse files
committed
fix(job): cannot delete records
1 parent b554b70 commit f88d903

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

job/main.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func init() {
194194
})
195195
en.OnRegex(`^取消在"(.*)"触发的指令$`, zero.UserOrGrpAdmin, isfirstregmatchnotnil).SetBlock(true).Handle(func(ctx *zero.Ctx) {
196196
cron := ctx.State["regex_matched"].([]string)[1]
197-
err := rmcmd(ctx.Event.SelfID, ctx.Event.UserID, cron)
197+
err := rmcmd(ctx.Event.SelfID, ctx.Event.UserID, cron, zero.AdminPermission(ctx))
198198
if err != nil {
199199
ctx.SendChain(message.Text("ERROR: ", err))
200200
return
@@ -232,7 +232,7 @@ func init() {
232232
args := []any{}
233233
if ctx.Event.GroupID != 0 {
234234
grp := strconv.FormatInt(ctx.Event.GroupID, 36)
235-
q = "WHERE cron LIKE 'fm:%' OR cron LIKE 'sm:%' OR cron LIKE ? OR cron LIKE ? "
235+
q = "WHERE cron LIKE 'fm:%' OR cron LIKE 'sm:%' OR cron LIKE '?' OR cron LIKE '?' "
236236
args = []any{"_m:" + grp + ":%", "_p:" + grp + ":?:%"}
237237
lst = append(lst, "在本群的触发指令]\n")
238238
} else {
@@ -262,7 +262,7 @@ func init() {
262262
return
263263
}
264264
lst := make([]string, 0, n)
265-
err = db.FindFor(ids, c, "WHERE cron = ?", func() error {
265+
err = db.FindFor(ids, c, "WHERE cron = '?'", func() error {
266266
lst = append(lst, c.Cmd+"\n")
267267
return nil
268268
}, cron)
@@ -291,7 +291,7 @@ func init() {
291291
return
292292
}
293293
lst := make([]string, 0, n)
294-
err = db.FindFor(ids, c, "WHERE cron = ?", func() error {
294+
err = db.FindFor(ids, c, "WHERE cron = '?'", func() error {
295295
lst = append(lst, c.Cmd+"\n")
296296
return nil
297297
}, cron)
@@ -441,19 +441,19 @@ func superuserhandler(rsp []byte) (zero.Handler, error) {
441441
}, nil
442442
}
443443

444-
func rmcmd(bot, caller int64, cron string) error {
444+
func rmcmd(bot, caller int64, cron string, force bool) error {
445445
c := &cmd{}
446446
mu.Lock()
447447
defer mu.Unlock()
448448
bots := strconv.FormatInt(bot, 36)
449449
e := new(zero.Event)
450450
var delids []int64
451-
err := db.FindFor(bots, c, "WHERE cron = ? OR cron LIKE ?", func() error {
451+
err := db.FindFor(bots, c, "WHERE cron = '?' OR cron LIKE '?'", func() error {
452452
err := json.Unmarshal(binary.StringToBytes(c.Cmd), e)
453453
if err != nil {
454454
return err
455455
}
456-
if e.UserID != caller {
456+
if !force && e.UserID != caller {
457457
return nil
458458
}
459459
eid, ok := entries[c.ID]
@@ -480,7 +480,7 @@ func delcmd(bot int64, cron string) error {
480480
defer mu.Unlock()
481481
bots := strconv.FormatInt(bot, 36)
482482
var delids []int64
483-
err := db.FindFor(bots, c, "WHERE cron = ?", func() error {
483+
err := db.FindFor(bots, c, "WHERE cron = '?'", func() error {
484484
m, ok := matchers[c.ID]
485485
if ok {
486486
m.Delete()

job/regexqa.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func removeRegex(gid, uid int64, bots, pattern string) error {
8787
cr += strconv.FormatInt(gid, 36) + ":" + pattern
8888
c := &cmd{}
8989
var delids []int64
90-
_ = db.FindFor(bots, c, "WHERE cron = ?", func() error {
90+
_ = db.FindFor(bots, c, "WHERE cron = '?'", func() error {
9191
delids = append(delids, c.ID)
9292
return nil
9393
}, cr)
@@ -107,7 +107,7 @@ func removeInjectRegex(gid, uid int64, bots, pattern string) error {
107107
cr += strconv.FormatInt(gid, 36) + ":" + pattern
108108
c := &cmd{}
109109
var delids []int64
110-
_ = db.FindFor(bots, c, "WHERE cron = ?", func() error {
110+
_ = db.FindFor(bots, c, "WHERE cron = '?'", func() error {
111111
delids = append(delids, c.ID)
112112
return nil
113113
}, cr)

job/web.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ func Delete(req *DeleteReq) (err error) {
355355
return
356356
}
357357
}
358-
err = db.FindFor(bots, &c, "WHERE id in ?", func() error {
358+
err = db.FindFor(bots, &c, "WHERE id in '?'", func() error {
359359
switch {
360360
case len(c.Cron) >= 3 && (c.Cron[:3] == "fm:" || c.Cron[:3] == "sm:"):
361361
m, ok := matchers[c.ID]

0 commit comments

Comments
 (0)