aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2026-01-17 20:52:13 +0000
committerAnhgelus Morhtuuzh <william@herges.fr>2026-01-17 20:52:13 +0000
commita3543d79561a3754540b921c54c3c177016c2397 (patch)
tree318b29652c4f59a7f6a16ff7a566b1a9935d069d /main.go
parent05ec1c26fe884097efe8fe1490916c518028e597 (diff)
parentc661541e45dddd6a082af66fcf7df7ba7dfdc6a6 (diff)
Merge pull request '[Perf] Member state' (#5) from perf/member-state into main
Reviewed-on: https://git.anhgelus.world/anhgelus/les-copaings-bot/pulls/5
Diffstat (limited to 'main.go')
-rw-r--r--main.go47
1 files changed, 30 insertions, 17 deletions
diff --git a/main.go b/main.go
index d2e6c01..1012f19 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
}
@@ -86,20 +84,22 @@ func main() {
adm := gokord.AdminPermission
+ ctx := user.SetState(context.Background(), user.NewState())
+
rankCmd := cmd.New("rank", "Affiche le niveau d'un copaing").
AddOption(cmd.NewOption(
types.CommandOptionUser,
"copaing",
"Le niveau du Copaing que vous souhaitez obtenir",
)).
- SetHandler(commands.Rank)
+ SetHandler(commands.Rank(ctx))
configCmd := cmd.New("config", "Modifie la config").
SetPermission(&adm).
SetHandler(commands.ConfigCommand)
topCmd := cmd.New("top", "Copaings les plus actifs").
- SetHandler(commands.Top)
+ SetHandler(commands.Top(ctx))
resetCmd := cmd.New("reset", "Reset l'xp").
SetHandler(commands.Reset).
@@ -111,7 +111,7 @@ func main() {
"user",
"Copaing a reset",
).IsRequired()).
- SetHandler(commands.ResetUser).
+ SetHandler(commands.ResetUser(ctx)).
SetPermission(&adm)
creditsCmd := cmd.New("credits", "Crédits").
@@ -128,7 +128,7 @@ func main() {
"user",
"Utilisateur à inspecter",
)).
- SetHandler(commands.Stats)
+ SetHandler(commands.Stats(ctx))
rolereactCmd := cmd.New("rolereact", "Envoie un message permettant de récupérer des rôles grâce à des réactions").
SetPermission(&adm).
@@ -179,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<- interface{}) {
- dg.Logger().Debug("periodic reducer")
- user.PeriodicReducer(dg)
+ stopPeriodicReducer = gokord.NewTimer(d, func(stop chan<- any) {
+ user.PeriodicReducer(ctx, dg)
+ })
+ stopPeriodicSaver = gokord.NewTimer(d2, func(c chan<- any) {
+ user.PeriodicSaver(ctx, dg)
})
},
Innovations: innovations,
@@ -221,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
@@ -279,9 +288,13 @@ func main() {
b.AddHandler(OnVoiceUpdate)
b.AddHandler(OnLeave)
- b.Start(context.Background())
+ b.Start(ctx)
if stopPeriodicReducer != nil {
stopPeriodicReducer <- true
}
+
+ if stopPeriodicSaver != nil {
+ stopPeriodicSaver <- true
+ }
}