aboutsummaryrefslogtreecommitdiff
path: root/user
diff options
context:
space:
mode:
authorWilliam Hergès <william@herges.fr>2025-07-30 21:24:03 +0200
committerWilliam Hergès <william@herges.fr>2025-07-30 21:24:03 +0200
commit436ec957481bdadefc8a38dc5ad848021a34ac37 (patch)
treed1e4509ea8a4baa0a8527276a615ddfe1d5dbb8a /user
parent977c818328c1c14880029510c6b3742a12858dcb (diff)
feat(xp): boost XP if user is boosting the server
Diffstat (limited to 'user')
-rw-r--r--user/xp.go23
1 files changed, 16 insertions, 7 deletions
diff --git a/user/xp.go b/user/xp.go
index 71a1ced..7e58665 100644
--- a/user/xp.go
+++ b/user/xp.go
@@ -6,6 +6,7 @@ import (
"github.com/anhgelus/les-copaings-bot/config"
"github.com/anhgelus/les-copaings-bot/exp"
"github.com/bwmarrin/discordgo"
+ "math"
"slices"
"sync"
)
@@ -31,17 +32,18 @@ func (c *Copaing) AddXP(s *discordgo.Session, m *discordgo.Member, xp uint, fn f
}
pastLevel := exp.Level(old)
utils.SendDebug("Adding xp", "member", m.DisplayName(), "old xp", old, "xp to add", xp, "old level", pastLevel)
- c.CopaingXPs = append(c.CopaingXPs, CopaingXP{CopaingID: c.ID, XP: xp, GuildID: c.GuildID})
+ c.CopaingXPs = append(c.CopaingXPs, CopaingXP{
+ CopaingID: c.ID,
+ XP: uint(math.Floor(float64(xp) * c.GetBoost(m))),
+ GuildID: c.GuildID,
+ })
if err = c.Save(); err != nil {
utils.SendAlert(
"user/xp.go - Saving user",
err.Error(),
- "xp",
- c.CopaingXPs,
- "discord_id",
- c.DiscordID,
- "guild_id",
- c.GuildID,
+ "xp", c.CopaingXPs,
+ "discord_id", c.DiscordID,
+ "guild_id", c.GuildID,
)
return
}
@@ -84,6 +86,13 @@ func (c *Copaing) GetXPForDays(n uint) (uint, error) {
return xp, nil
}
+func (c *Copaing) GetBoost(m *discordgo.Member) float64 {
+ if m.PremiumSince != nil {
+ return 2.0
+ }
+ return 1.0
+}
+
// GetBestXP returns n Copaing with the best XP within d days (d <= cfg.DaysXPRemain; d < 0 <=> d = cfg.DaysXPRemain)
//
// This function is slow