You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

44 lines
857 B

package services
import (
lucifer3 "git.aiterp.net/lucifer3/server"
"git.aiterp.net/lucifer3/server/events"
"time"
)
func NewTicker() lucifer3.Service {
return &tickerService{}
}
type tickerService struct{}
func (s *tickerService) Active() bool {
return true
}
func (s *tickerService) HandleEvent(bus *lucifer3.EventBus, event lucifer3.Event) {
if _, ok := event.(events.Started); ok {
go func() {
now := time.Now()
bus.RunEvent(events.Time{
Hour: now.Hour(),
Minute: now.Minute(),
})
time.Sleep(time.Now().Truncate(time.Minute).Add(time.Minute).Sub(time.Now()))
now = time.Now()
bus.RunEvent(events.Time{
Hour: now.Hour(),
Minute: now.Minute(),
})
for t := range time.NewTicker(time.Minute).C {
bus.RunEvent(events.Time{
Hour: t.Hour(),
Minute: t.Minute(),
})
}
}()
}
}