modules/commands+level: Prestiging now flushes level cache

This allows newly prestiged users to get their roles back.
master
Luther Wen Xu 2020-01-04 21:16:10 +07:00
parent c80fdc51cc
commit ec1657d398
Signed by: chanbakjsd
GPG Key ID: B7D77E3E9D102B70
2 changed files with 12 additions and 1 deletions

@ -93,6 +93,7 @@ func ListenPrestigeReact(s *discordgo.Session, m *discordgo.MessageReactionAdd)
log.Error(s, "checkPrestigeReact", "SetPrestigeMultiplier", err) log.Error(s, "checkPrestigeReact", "SetPrestigeMultiplier", err)
return return
} }
level.ClearCache(m.UserID)
s.ChannelMessageSend(m.ChannelID, s.ChannelMessageSend(m.ChannelID,
fmt.Sprintf( fmt.Sprintf(
"**PRESTIGE > ** <@%s>, you have prestiged!", m.UserID, "**PRESTIGE > ** <@%s>, you have prestiged!", m.UserID,

@ -17,6 +17,12 @@ var (
lastKnownLevel = make(map[string]int) lastKnownLevel = make(map[string]int)
) )
func ClearCache(discordID string) {
levelMutex.Lock()
defer levelMutex.Unlock()
delete(lastKnownLevel, discordID)
}
func QueueCheck(discordID string) { func QueueCheck(discordID string) {
levelMutex.Lock() levelMutex.Lock()
defer levelMutex.Unlock() defer levelMutex.Unlock()
@ -46,7 +52,11 @@ func ScheduleUpdates(s *discordgo.Session) {
return return
} }
if newLevel > oldLevel { if newLevel > oldLevel {
err = gacha.RollReward(s, checkID, newLevel-oldLevel) timeToRoll := newLevel - oldLevel
if oldLevel == 0 {
timeToRoll--
}
err = gacha.RollReward(s, checkID, timeToRoll)
if err != nil { if err != nil {
log.Error(s, err) log.Error(s, err)
} }