aboutsummaryrefslogtreecommitdiff
path: root/xp
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <anhgelus.morhtuuzh@proton.me>2024-04-16 15:44:02 +0200
committerAnhgelus Morhtuuzh <anhgelus.morhtuuzh@proton.me>2024-04-16 15:44:02 +0200
commitb4e72dcae10265bbc1595f2e520b1407cf8e250d (patch)
tree78db00afe88a7cb818083c0cc890ae9bd8daf50c /xp
parent7fe68106bec7133981ac91026156977e0c7b4ca1 (diff)
docs(debug): better debug log
Diffstat (limited to 'xp')
-rw-r--r--xp/level.go37
1 files changed, 29 insertions, 8 deletions
diff --git a/xp/level.go b/xp/level.go
index bbe11a4..4830298 100644
--- a/xp/level.go
+++ b/xp/level.go
@@ -78,11 +78,22 @@ func LastEventUpdate(s *discordgo.Session, c *Copaing) {
}
}
if oldXP != c.XP {
- c.Save()
lvl := Level(c.XP)
- if Level(oldXP) != Level(c.XP) {
+ if Level(oldXP) != lvl {
+ utils.SendDebug(
+ "Level changed",
+ "old",
+ Level(oldXP),
+ "new",
+ lvl,
+ "discord_id",
+ c.DiscordID,
+ "guild_id",
+ c.GuildID,
+ )
c.OnNewLevel(s, lvl)
}
+ c.Save()
}
c.SetLastEvent()
}
@@ -109,12 +120,23 @@ func XPUpdate(s *discordgo.Session, c *Copaing) {
}
}
if oldXP != c.XP {
- utils.SendDebug("Save XP", "old", oldXP, "new", c.XP, "user", c.DiscordID)
- c.Save()
lvl := Level(c.XP)
- if Level(oldXP) != Level(c.XP) {
+ if Level(oldXP) != lvl {
+ utils.SendDebug(
+ "Level updated",
+ "old",
+ Level(oldXP),
+ "new",
+ lvl,
+ "discord_id",
+ c.DiscordID,
+ "guild_id",
+ c.GuildID,
+ )
c.OnNewLevel(s, lvl)
}
+ utils.SendDebug("Save XP", "old", oldXP, "new", c.XP, "user", c.DiscordID)
+ c.Save()
}
}
@@ -127,15 +149,14 @@ func PeriodicReducer(s *discordgo.Session) {
}
wg.Add(1)
go func() {
- utils.SendDebug("Async reducer", "user", m.DisplayName(), "guild", g.Name)
c := GetCopaing(m.User.ID, g.ID)
XPUpdate(s, c)
wg.Done()
}()
}
wg.Wait() // finish the entire guild before starting another
- utils.SendDebug("Guild finished", "guild", g.Name)
- time.Sleep(10 * time.Second) // sleep prevents from spamming the Discord API
+ utils.SendDebug("Periodic reduce, guild finished", "guild", g.Name)
+ time.Sleep(10 * time.Second) // sleep prevents from spamming the Discord API and the database
}
utils.SendDebug("Periodic reduce finished", "len(guilds)", len(s.State.Guilds))
}