aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config/guild.go8
-rw-r--r--user/xp.go11
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)