feat(xp): basic reducer
This commit is contained in:
parent
c1e4653a5c
commit
2aaeb2115b
3 changed files with 13 additions and 1 deletions
|
@ -30,6 +30,7 @@ func OnMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|||
return
|
||||
}
|
||||
c := GetCopaing(m.Author.ID, m.GuildID)
|
||||
onLastEventUpdate(c)
|
||||
// add xp
|
||||
trimmed := utils.TrimMessage(strings.ToLower(m.Content))
|
||||
m.Member.User = m.Author
|
||||
|
@ -62,6 +63,7 @@ func OnVoiceUpdate(s *discordgo.Session, e *discordgo.VoiceStateUpdate) {
|
|||
if e.Member.User.Bot {
|
||||
return
|
||||
}
|
||||
onLastEventUpdate(GetCopaing(e.UserID, e.GuildID))
|
||||
cfg := config.GetGuildConfig(e.GuildID)
|
||||
if cfg.IsDisabled(e.ChannelID) {
|
||||
return
|
||||
|
|
|
@ -42,3 +42,10 @@ func onNewLevel(s *discordgo.Session, m *discordgo.Member, level uint) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func onLastEventUpdate(c *Copaing) {
|
||||
h := c.HourSinceLastEvent()
|
||||
c.XP -= Lose(h, c.XP)
|
||||
c.Save()
|
||||
c.SetLastEvent()
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package xp
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/anhgelus/gokord"
|
||||
"github.com/anhgelus/gokord/utils"
|
||||
|
@ -77,7 +78,9 @@ func (c *Copaing) HourSinceLastEvent() uint {
|
|||
}
|
||||
u := c.GetUserBase()
|
||||
res := client.Get(context.Background(), fmt.Sprintf("%s:%s", u.GenKey(), LastEvent))
|
||||
if res.Err() != nil {
|
||||
if errors.Is(res.Err(), redis.Nil) {
|
||||
return 0
|
||||
} else if res.Err() != nil {
|
||||
utils.SendAlert("xp/member.go - Getting last event", res.Err().Error(), "base_key", u.GenKey())
|
||||
return 0
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue