aboutsummaryrefslogtreecommitdiff
path: root/user/xp.go
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <anhgelus@anhgelus.world>2025-05-13 17:35:03 +0200
committerAnhgelus Morhtuuzh <anhgelus@anhgelus.world>2025-05-13 17:35:03 +0200
commiteaf9fa51cdd9509c5d075633b712ec9b5ea712c7 (patch)
tree90e5845ef70b9db272f202aedcbd5b5e024b4623 /user/xp.go
parent067e149e72da10790e347b82045d82a96397d6cf (diff)
perf(db): remove useless XP data
Diffstat (limited to 'user/xp.go')
-rw-r--r--user/xp.go16
1 files changed, 6 insertions, 10 deletions
diff --git a/user/xp.go b/user/xp.go
index 7501139..d88e3ce 100644
--- a/user/xp.go
+++ b/user/xp.go
@@ -1,7 +1,6 @@
package user
import (
- "fmt"
"github.com/anhgelus/gokord"
"github.com/anhgelus/gokord/utils"
"github.com/anhgelus/les-copaings-bot/config"
@@ -9,7 +8,6 @@ import (
"github.com/bwmarrin/discordgo"
"slices"
"sync"
- "time"
)
type cXP struct {
@@ -61,16 +59,14 @@ func (c *Copaing) GetXP() (uint, error) {
func (c *Copaing) GetXPForDays(n uint) (uint, error) {
xp := uint(0)
- var y, d int
- var m time.Month
- if gokord.Debug {
- y, m, d = time.Unix(time.Now().Unix()-int64(24*60*60), 0).Date() // reduce time for debug
- } else {
- y, m, d = time.Unix(time.Now().Unix()-int64(n*24*60*60), 0).Date()
- }
rows, err := gokord.DB.
Model(&CopaingXP{}).
- Where(fmt.Sprintf("created_at >= '%d-%d-%d' and guild_id = ? and copaing_id = ?", y, m, d), c.GuildID, c.ID).
+ Where(
+ "created_at >= '?' and guild_id = ? and copaing_id = ?",
+ exp.TimeStampNDaysBefore(n),
+ c.GuildID,
+ c.ID,
+ ).
Rows()
defer rows.Close()
if err != nil {