From 4e9466b2424ef1b054e9671c2172b33f1ff0ee22 Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Wed, 26 Jul 2023 21:39:45 -0600 Subject: [PATCH] wip 15m clock --- events/clock.go | 42 ++++++++++++++++++++++++++++++++++++++++++ events/main.go | 1 + 2 files changed, 43 insertions(+) create mode 100644 events/clock.go diff --git a/events/clock.go b/events/clock.go new file mode 100644 index 0000000..01ad0f3 --- /dev/null +++ b/events/clock.go @@ -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 + } + } + } + } + }() +} diff --git a/events/main.go b/events/main.go index 7d2b358..bdd20ed 100644 --- a/events/main.go +++ b/events/main.go @@ -8,4 +8,5 @@ func Setup(session *ningen.State) { session.PreHandler.AddHandler(Ready) session.PreHandler.AddHandler(MessageCreate) session.PreHandler.AddHandler(MessageUpdate) + SetupClock() }