From c9129c2e7edcf6e588cac674dfdb240f1714083d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Herg=C3=A8s?= Date: Sat, 17 Jan 2026 19:15:12 +0100 Subject: feat(member): save cache in db every 30 minutes --- main.go | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 21b372b..0d5bcd3 100644 --- a/main.go +++ b/main.go @@ -40,7 +40,8 @@ var ( } verbose bool - stopPeriodicReducer chan<- interface{} + stopPeriodicReducer chan<- any + stopPeriodicSaver chan<- any ) //go:embed assets/inter-variable.ttf @@ -60,13 +61,10 @@ func init() { panic(err) } inter := font.Font{Typeface: "Inter"} - font.DefaultCache.Add( - []font.Face{ - { - Font: inter, - Face: fontTTF, - }, - }) + font.DefaultCache.Add([]font.Face{{ + Font: inter, + Face: fontTTF, + }}) plot.DefaultFont = inter } @@ -181,12 +179,18 @@ func main() { if gokord.Debug { d = 3 * exp.DebugFactor * time.Second } + d2 := 30 * time.Minute + if gokord.Debug { + d2 = 1 * exp.DebugFactor * time.Second + } - user.PeriodicReducer(dg) + user.PeriodicReducer(ctx, dg) stopPeriodicReducer = gokord.NewTimer(d, func(stop chan<- any) { - dg.Logger().Debug("periodic reducer") - user.PeriodicReducer(dg) + user.PeriodicReducer(ctx, dg) + }) + stopPeriodicSaver = gokord.NewTimer(d2, func(c chan<- any) { + user.PeriodicSaver(ctx, dg) }) }, Innovations: innovations, @@ -223,6 +227,9 @@ func main() { } s.Logger().Debug("pushed rolereaction message command", "CommandID", c.ID) }) + b.AddHandler(func(ct context.Context, s bot.Session, _ *event.Disconnect) { + user.PeriodicSaver(ctx, s) + }) b.AddHandler(func(_ context.Context, s bot.Session, i *event.InteractionCreate) { if i.Type != types.InteractionApplicationCommand { return -- cgit v1.2.3