From 7508627d86a4f2ef9b3caebd88d92fe8be854816 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Herg=C3=A8s?= Date: Wed, 30 Jul 2025 21:34:07 +0200 Subject: feat(xp): boost XP if user has a certain role --- config/guild.go | 8 ++++++++ user/xp.go | 11 +++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/config/guild.go b/config/guild.go index fb7eaef..63736df 100644 --- a/config/guild.go +++ b/config/guild.go @@ -10,6 +10,7 @@ type GuildConfig struct { ID uint `gorm:"primarykey"` GuildID string `gorm:"not null;unique"` XpRoles []XpRole + BoostXpRoles []BoostXpRole DisabledChannels string FallbackChannel string DaysXPRemains uint `gorm:"default:90"` // 30 * 3 = 90 (three months) @@ -22,6 +23,13 @@ type XpRole struct { GuildConfigID uint } +type BoostXpRole struct { + ID uint `gorm:"primarykey"` + Boost float64 + RoleID string + GuildConfigID uint +} + func GetGuildConfig(guildID string) *GuildConfig { cfg := GuildConfig{GuildID: guildID} if err := cfg.Load(); err != nil { diff --git a/user/xp.go b/user/xp.go index 7e58665..6dbed59 100644 --- a/user/xp.go +++ b/user/xp.go @@ -87,10 +87,17 @@ func (c *Copaing) GetXPForDays(n uint) (uint, error) { } func (c *Copaing) GetBoost(m *discordgo.Member) float64 { + boost := 1.0 if m.PremiumSince != nil { - return 2.0 + boost = max(boost, 2.0) } - return 1.0 + cfg := config.GetGuildConfig(c.GuildID) + for _, r := range cfg.BoostXpRoles { + if slices.Contains(m.Roles, r.RoleID) { + boost = max(boost, r.Boost) + } + } + return boost } // GetBestXP returns n Copaing with the best XP within d days (d <= cfg.DaysXPRemain; d < 0 <=> d = cfg.DaysXPRemain) -- cgit v1.2.3