mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 13:59:39 +08:00
fix #161
This commit is contained in:
parent
6e2b10b788
commit
2250adf854
@ -281,7 +281,7 @@ func init() { // 插件主体
|
||||
dateStrs := ctx.State["regex_matched"].([]string)
|
||||
ts := timer.GetFilledTimer(dateStrs, ctx.Event.SelfID, ctx.Event.GroupID, false)
|
||||
if ts.En() {
|
||||
go clock.RegisterTimer(ts, true)
|
||||
go clock.RegisterTimer(ts, true, false)
|
||||
ctx.SendChain(message.Text("记住了~"))
|
||||
} else {
|
||||
ctx.SendChain(message.Text("参数非法:" + ts.Alert))
|
||||
@ -304,7 +304,7 @@ func init() { // 插件主体
|
||||
}
|
||||
logrus.Debugln("[manager] cron:", dateStrs[1])
|
||||
ts := timer.GetFilledCronTimer(dateStrs[1], alert, url, ctx.Event.SelfID, ctx.Event.GroupID)
|
||||
if clock.RegisterTimer(ts, true) {
|
||||
if clock.RegisterTimer(ts, true, false) {
|
||||
ctx.SendChain(message.Text("记住了~"))
|
||||
} else {
|
||||
ctx.SendChain(message.Text("参数非法:" + ts.Alert))
|
||||
|
||||
@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
sql "github.com/FloatTech/sqlite"
|
||||
"github.com/FloatTech/zbputils/process"
|
||||
"github.com/fumiama/cron"
|
||||
"github.com/sirupsen/logrus"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
@ -47,7 +48,7 @@ func NewClock(db *sql.Sqlite) (c Clock) {
|
||||
}
|
||||
|
||||
// RegisterTimer 注册计时器
|
||||
func (c *Clock) RegisterTimer(ts *Timer, save bool) bool {
|
||||
func (c *Clock) RegisterTimer(ts *Timer, save, isinit bool) bool {
|
||||
var key uint32
|
||||
if save {
|
||||
key = ts.GetTimerID()
|
||||
@ -62,6 +63,9 @@ func (c *Clock) RegisterTimer(ts *Timer, save bool) bool {
|
||||
logrus.Println("[群管]注册计时器", key)
|
||||
if ts.Cron != "" {
|
||||
var ctx *zero.Ctx
|
||||
if isinit {
|
||||
process.GlobalInitMutex.Lock()
|
||||
}
|
||||
if ts.SelfID != 0 {
|
||||
ctx = zero.GetBot(ts.SelfID)
|
||||
} else {
|
||||
@ -71,6 +75,9 @@ func (c *Clock) RegisterTimer(ts *Timer, save bool) bool {
|
||||
return false
|
||||
})
|
||||
}
|
||||
if isinit {
|
||||
process.GlobalInitMutex.Unlock()
|
||||
}
|
||||
eid, err := c.cron.AddFunc(ts.Cron, func() { ts.sendmsg(ts.GrpID, ctx) })
|
||||
if err == nil {
|
||||
c.entmu.Lock()
|
||||
@ -187,7 +194,7 @@ func (c *Clock) loadTimers(db *sql.Sqlite) {
|
||||
var t Timer
|
||||
_ = c.db.FindFor("timer", &t, "", func() error {
|
||||
tescape := t
|
||||
go c.RegisterTimer(&tescape, false)
|
||||
go c.RegisterTimer(&tescape, false, true)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user