wip 15m clock

This commit is contained in:
Cynthia Foxwell 2023-07-26 21:39:45 -06:00
parent 0d6a1398f0
commit 4e9466b242
2 changed files with 43 additions and 0 deletions

42
events/clock.go Normal file
View file

@ -0,0 +1,42 @@
package events
import (
"fmt"
"time"
"unicode/utf8"
"github.com/Cynosphere/comcord/state"
)
var sentTime bool = false
func SetupClock() {
clock := time.NewTicker(500 * time.Millisecond)
go func() {
for {
select {
case <- clock.C: {
now := time.Now().UTC()
if now.Minute() % 15 == 0 && now.Second() < 2 && !sentTime {
if state.IsInPrompt() {
// TODO
} else {
fmt.Printf("%s\n\r", now.Format("[Mon 02-Jan-06 15:04:05]"))
}
client := state.GetClient()
self, err := client.MeStore.Me()
if err != nil {
return
}
state.SetNameLength(utf8.RuneCountInString(self.Username) + 2)
sentTime = true
} else if now.Second() > 2 && sentTime {
sentTime = false
}
}
}
}
}()
}

View file

@ -8,4 +8,5 @@ func Setup(session *ningen.State) {
session.PreHandler.AddHandler(Ready)
session.PreHandler.AddHandler(MessageCreate)
session.PreHandler.AddHandler(MessageUpdate)
SetupClock()
}