diff options
| author | William Hergès <william@herges.fr> | 2025-08-31 15:35:55 +0200 |
|---|---|---|
| committer | William Hergès <william@herges.fr> | 2025-08-31 15:35:55 +0200 |
| commit | 05941e243f9bef6c8f461bafae9dbd12a88362b6 (patch) | |
| tree | 5e80b2ad61aeb45a9298e234c3980fe459fc12a1 | |
| parent | 3f6b0717e2d1e954e0db324bc3a389d2f34e2a4b (diff) | |
fix(stats): index out of range
and not showing no value
| -rw-r--r-- | commands/stats.go | 11 |
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), } |
