aboutsummaryrefslogtreecommitdiff
path: root/commands
diff options
context:
space:
mode:
authorWilliam Hergès <william@herges.fr>2025-08-31 15:35:55 +0200
committerWilliam Hergès <william@herges.fr>2025-08-31 15:35:55 +0200
commit05941e243f9bef6c8f461bafae9dbd12a88362b6 (patch)
tree5e80b2ad61aeb45a9298e234c3980fe459fc12a1 /commands
parent3f6b0717e2d1e954e0db324bc3a389d2f34e2a4b (diff)
fix(stats): index out of range
and not showing no value
Diffstat (limited to 'commands')
-rw-r--r--commands/stats.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/commands/stats.go b/commands/stats.go
index 26719dc..06b10bd 100644
--- a/commands/stats.go
+++ b/commands/stats.go
@@ -144,17 +144,24 @@ func stats(s *discordgo.Session, i *discordgo.InteractionCreate, days uint, exec
copaings[raw.CopaingID] = &cp
}
pts, ok := stats[raw.CopaingID]
+ now := time.Now().Unix()
if !ok {
pts = make([]plotter.XY, days)
+ for i := 0; i < int(days); i++ {
+ pts[i] = plotter.XY{
+ X: float64(i - int(days)),
+ Y: 0,
+ }
+ }
stats[raw.CopaingID] = pts
}
- t := raw.CreatedAt.Unix() - time.Now().Unix()
+ t := raw.CreatedAt.Unix() - now
if !gokord.Debug {
t = int64(math.Ceil(float64(t) / (24 * 60 * 60)))
} else {
t = int64(math.Ceil(float64(t) / 6))
}
- pts[t] = plotter.XY{
+ pts[int64(days)-t] = plotter.XY{
X: float64(t),
Y: float64(raw.XP),
}