style(event): move calcdiversity in exp
This commit is contained in:
parent
6b6c775ab3
commit
5af6bd672c
2 changed files with 12 additions and 12 deletions
13
events.go
13
events.go
|
@ -10,7 +10,6 @@ import (
|
||||||
"github.com/anhgelus/les-copaings-bot/user"
|
"github.com/anhgelus/les-copaings-bot/user"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
"github.com/redis/go-redis/v9"
|
"github.com/redis/go-redis/v9"
|
||||||
"slices"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -37,7 +36,7 @@ func OnMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
trimmed := utils.TrimMessage(strings.ToLower(m.Content))
|
trimmed := utils.TrimMessage(strings.ToLower(m.Content))
|
||||||
m.Member.User = m.Author
|
m.Member.User = m.Author
|
||||||
m.Member.GuildID = m.GuildID
|
m.Member.GuildID = m.GuildID
|
||||||
xp := exp.MessageXP(uint(len(trimmed)), calcDiversity(trimmed))
|
xp := exp.MessageXP(uint(len(trimmed)), exp.CalcDiversity(trimmed))
|
||||||
if xp > MaxXpPerMessage {
|
if xp > MaxXpPerMessage {
|
||||||
xp = MaxXpPerMessage
|
xp = MaxXpPerMessage
|
||||||
}
|
}
|
||||||
|
@ -52,16 +51,6 @@ func OnMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func calcDiversity(msg string) uint {
|
|
||||||
var chars []rune
|
|
||||||
for _, c := range []rune(msg) {
|
|
||||||
if !slices.Contains(chars, c) {
|
|
||||||
chars = append(chars, c)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return uint(len(chars))
|
|
||||||
}
|
|
||||||
|
|
||||||
func OnVoiceUpdate(s *discordgo.Session, e *discordgo.VoiceStateUpdate) {
|
func OnVoiceUpdate(s *discordgo.Session, e *discordgo.VoiceStateUpdate) {
|
||||||
if e.Member.User.Bot {
|
if e.Member.User.Bot {
|
||||||
return
|
return
|
||||||
|
|
|
@ -3,6 +3,7 @@ package exp
|
||||||
import (
|
import (
|
||||||
"github.com/anhgelus/gokord"
|
"github.com/anhgelus/gokord"
|
||||||
"math"
|
"math"
|
||||||
|
"slices"
|
||||||
)
|
)
|
||||||
|
|
||||||
func MessageXP(length uint, diversity uint) uint {
|
func MessageXP(length uint, diversity uint) uint {
|
||||||
|
@ -11,6 +12,16 @@ func MessageXP(length uint, diversity uint) uint {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CalcDiversity(msg string) uint {
|
||||||
|
var chars []rune
|
||||||
|
for _, c := range []rune(msg) {
|
||||||
|
if !slices.Contains(chars, c) {
|
||||||
|
chars = append(chars, c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return uint(len(chars))
|
||||||
|
}
|
||||||
|
|
||||||
func VocalXP(time uint) uint {
|
func VocalXP(time uint) uint {
|
||||||
return uint(math.Floor(
|
return uint(math.Floor(
|
||||||
0.01*math.Pow(float64(time), 1.3) + 1,
|
0.01*math.Pow(float64(time), 1.3) + 1,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue