aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <anhgelus@anhgelus.world>2025-08-18 13:56:32 +0200
committerAnhgelus Morhtuuzh <anhgelus@anhgelus.world>2025-08-18 13:56:32 +0200
commit026abcc07a57eeda8a08a746ad2b664e956360f3 (patch)
treea5705ceb2b192c9ee18c4cce575a2251e3b72d1d
parentcf2093095e769cdfac7fd83adc61d7ff6e958c0a (diff)
feat(xp): increase precision of timestamp
seems like to fix periodic reducer not working
-rw-r--r--.gitignore1
-rw-r--r--docker-compose.yml22
-rw-r--r--exp/functions.go10
-rw-r--r--main.go10
-rw-r--r--user/level.go10
5 files changed, 20 insertions, 33 deletions
diff --git a/.gitignore b/.gitignore
index 7cc06cf..c8977f6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,3 +26,4 @@ go.work
tmp
config/**.toml
data
+docker-compose.yml
diff --git a/docker-compose.yml b/docker-compose.yml
deleted file mode 100644
index 77b28da..0000000
--- a/docker-compose.yml
+++ /dev/null
@@ -1,22 +0,0 @@
-services:
- bot:
- build: .
- restart: always
- env_file:
- - .env
- volumes:
- - ./config:/app/config
- depends_on:
- - postgres
- postgres:
- image: postgres:alpine
- env_file:
- - .env
- volumes:
- - ./data:/var/lib/postgresql/data
- adminer:
- image: docker.io/adminer
- ports:
- - "8080:8080"
- depends_on:
- - postgres
diff --git a/exp/functions.go b/exp/functions.go
index 026eb34..c20e6a8 100644
--- a/exp/functions.go
+++ b/exp/functions.go
@@ -50,14 +50,14 @@ func LevelXP(level uint) uint {
// TimeStampNDaysBefore returns the timestamp (year-month-day) n days before today
func TimeStampNDaysBefore(n uint) string {
- var y, d int
- var m time.Month
+ var unix time.Time
if gokord.Debug {
- y, m, d = time.Unix(time.Now().Unix()-int64(24*60*60), 0).Date() // reduce time for debug
+ unix = time.Unix(time.Now().Unix()-int64(n), 0) // reduce time for debug
} else {
- y, m, d = time.Unix(time.Now().Unix()-int64(n*24*60*60), 0).Date()
+ unix = time.Unix(time.Now().Unix()-int64(n*24*60*60), 0)
}
- return fmt.Sprintf("%d-%d-%d", y, m, d)
+ unix = unix.UTC()
+ return fmt.Sprintf("%d-%d-%d %d:%d:%d UTC", unix.Year(), unix.Month(), unix.Day(), unix.Hour(), unix.Minute(), unix.Second())
}
func TrimMessage(s string) string {
diff --git a/main.go b/main.go
index 4610bc4..cfd4b58 100644
--- a/main.go
+++ b/main.go
@@ -195,7 +195,15 @@ func afterInit(dg *discordgo.Session) {
dg.AddHandler(OnVoiceUpdate)
dg.AddHandler(OnLeave)
- stopPeriodicReducer = utils.NewTimer(24*time.Hour, func(stop chan<- interface{}) {
+ d := 24 * time.Hour
+ if gokord.Debug {
+ d = 24 * time.Second
+ }
+
+ user.PeriodicReducer(dg)
+
+ stopPeriodicReducer = utils.NewTimer(d, func(stop chan<- interface{}) {
+ utils.SendDebug("Periodic reducer")
user.PeriodicReducer(dg)
})
}
diff --git a/user/level.go b/user/level.go
index 6d9b674..9ef7372 100644
--- a/user/level.go
+++ b/user/level.go
@@ -86,14 +86,14 @@ func PeriodicReducer(dg *discordgo.Session) {
go func() {
defer wg.Done()
cfg := config.GetGuildConfig(g.ID)
- err := gokord.DB.
+ res := gokord.DB.
Model(&CopaingXP{}).
Where("guild_id = ? and created_at < ?", g.ID, exp.TimeStampNDaysBefore(cfg.DaysXPRemains)).
- Delete(&CopaingXP{}).
- Error
- if err != nil {
- utils.SendAlert("user/level.go - Removing old XP", err.Error(), "guild_id", g.ID)
+ Delete(&CopaingXP{})
+ if res.Error != nil {
+ utils.SendAlert("user/level.go - Removing old XP", res.Error.Error(), "guild_id", g.ID)
}
+ utils.SendDebug("Guild cleaned", "guild", g.Name, "rows affected", res.RowsAffected)
}()
}
wg.Wait()