diff --git a/plugin/manager/timer/msg.go b/plugin/manager/timer/msg.go index 64de291044..0633ba77c9 100644 --- a/plugin/manager/timer/msg.go +++ b/plugin/manager/timer/msg.go @@ -6,6 +6,9 @@ import ( ) func (t *Timer) sendmsg(grp int64, ctx *zero.Ctx) { + if ctx == nil { + return + } ctx.Event = new(zero.Event) ctx.Event.GroupID = grp if t.URL == "" { diff --git a/plugin/manager/timer/timer.go b/plugin/manager/timer/timer.go index 43a7254017..d42a1e0bf1 100644 --- a/plugin/manager/timer/timer.go +++ b/plugin/manager/timer/timer.go @@ -77,7 +77,13 @@ func (c *Clock) RegisterTimer(ts *Timer, save, isinit bool) bool { if isinit { process.GlobalInitMutex.Unlock() } - eid, err := c.cron.AddFunc(ts.Cron, func() { ts.sendmsg(ts.GrpID, ctx) }) + eid, err := c.cron.AddFunc(ts.Cron, func() { + bot := ctx + if ts.SelfID != 0 { + bot = zero.GetBot(ts.SelfID) + } + ts.sendmsg(ts.GrpID, bot) + }) if err == nil { c.entmu.Lock() c.entries[key] = eid