feat(xp): gain from vocal

This commit is contained in:
Anhgelus Morhtuuzh 2024-04-14 21:44:11 +02:00
parent 3e06848f72
commit 1a36ecd053
No known key found for this signature in database
GPG key ID: CF4550297832A29F
3 changed files with 112 additions and 8 deletions

View file

@ -2,6 +2,7 @@ package xp
import (
"github.com/anhgelus/gokord"
"github.com/bwmarrin/discordgo"
"gorm.io/gorm"
)
@ -20,3 +21,14 @@ func (c *Copaing) Load() *Copaing {
func (c *Copaing) Save() {
gokord.DB.Save(c)
}
func (c *Copaing) AddXP(s *discordgo.Session, xp uint, fn func(uint, uint)) {
pastLevel := Level(c.XP)
c.XP += xp
c.Save()
newLevel := Level(c.XP)
if newLevel > pastLevel {
fn(c.XP, newLevel)
onNewLevel(s, newLevel)
}
}