Skip to content

Commit

Permalink
✨ manager cron 完善
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Oct 28, 2021
1 parent 6f4c40f commit c0327fe
Show file tree
Hide file tree
Showing 12 changed files with 379 additions and 607 deletions.
24 changes: 15 additions & 9 deletions plugin_manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"
"time"

"github.com/sirupsen/logrus"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/extension/rate"
"github.com/wdvxdr1123/ZeroBot/message"
Expand Down Expand Up @@ -256,29 +257,34 @@ func init() { // 插件主体
Handle(func(ctx *zero.Ctx) {
dateStrs := ctx.State["regex_matched"].([]string)
ts := timer.GetFilledTimer(dateStrs, ctx.Event.SelfID, false)
if ts.Enable {
if ts.En() {
go clock.RegisterTimer(ts, ctx.Event.GroupID, true)
ctx.SendChain(message.Text("记住了~"))
} else {
ctx.SendChain(message.Text("参数非法!"))
ctx.SendChain(message.Text("参数非法:" + ts.Alert))
}
})
// 定时 cron 提醒
zero.OnRegex(`^在"(.*)"时(用.+)?提醒大家(.*)`, zero.AdminPermission, zero.OnlyGroup).SetBlock(true).SetPriority(40).
Handle(func(ctx *zero.Ctx) {
dateStrs := ctx.State["regex_matched"].([]string)
var url, alert string
if len(dateStrs) == 3 {
url = dateStrs[1]
switch len(dateStrs) {
case 4:
url = dateStrs[2]
alert = dateStrs[3]
case 3:
alert = dateStrs[2]
} else {
alert = dateStrs[1]
default:
ctx.SendChain(message.Text("参数非法!"))
return
}
ts := timer.GetFilledCronTimer(dateStrs[0], alert, url, ctx.Event.SelfID)
logrus.Debugln("[manager] cron:", dateStrs[1])
ts := timer.GetFilledCronTimer(dateStrs[1], alert, url, ctx.Event.SelfID)
if clock.RegisterTimer(ts, ctx.Event.GroupID, true) {
ctx.SendChain(message.Text("记住了~"))
} else {
ctx.SendChain(message.Text("参数非法!"))
ctx.SendChain(message.Text("参数非法:" + ts.Alert))
}
})
// 取消定时
Expand All @@ -298,7 +304,7 @@ func init() { // 插件主体
zero.OnRegex(`^取消在"(.*)"的提醒`, zero.AdminPermission, zero.OnlyGroup).SetBlock(true).SetPriority(40).
Handle(func(ctx *zero.Ctx) {
dateStrs := ctx.State["regex_matched"].([]string)
ts := timer.Timer{Cron: dateStrs[0]}
ts := timer.Timer{Cron: dateStrs[1]}
ti := ts.GetTimerInfo(ctx.Event.GroupID)
ok := clock.CancelTimer(ti)
if ok {
Expand Down
19 changes: 11 additions & 8 deletions plugin_manager/timer/migrate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
io "io"
"os"
"time"

"github.com/FloatTech/ZeroBot-Plugin/utils/file"
)
Expand Down Expand Up @@ -50,15 +51,17 @@ func main() {
if loadTimers(os.Args[1]) {
timersmapnew.Timers = make(map[string]*Timer)
for s, t := range timersmap.Timers {
timersmapnew.Timers[s] = &Timer{
Enable: t.Enable,
Alert: t.Alert,
Url: t.Url,
Month: t.Month,
Day: t.Day,
Hour: t.Hour,
Minute: t.Minute,
tm := &Timer{
Alert: t.Alert,
Url: t.Url,
}
tm.SetMonth(time.Month(t.Month))
tm.SetDay(int(t.Day))
tm.SetHour(int(t.Hour))
tm.SetMinute(int(t.Minute))
tm.SetWeek(time.Weekday(t.Week))
tm.SetEn(t.Enable)
timersmapnew.Timers[s] = tm
}
saveTimers(os.Args[2])
}
Expand Down
Loading

0 comments on commit c0327fe

Please sign in to comment.