Merge branch 'main' into refactor/config-command

This commit is contained in:
Anhgelus Morhtuuzh 2025-08-06 02:15:08 +02:00
commit d72004ae14
Signed by: anhgelus
GPG key ID: CAD341EFA92DDDE5
2 changed files with 15 additions and 1 deletions

View file

@ -31,7 +31,7 @@ func OnMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
} }
c := user.GetCopaing(m.Author.ID, m.GuildID) c := user.GetCopaing(m.Author.ID, m.GuildID)
// add exp // add exp
trimmed := utils.TrimMessage(strings.ToLower(m.Content)) trimmed := exp.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 := min(exp.MessageXP(uint(len(trimmed)), exp.CalcDiversity(trimmed)), MaxXpPerMessage) xp := min(exp.MessageXP(uint(len(trimmed)), exp.CalcDiversity(trimmed)), MaxXpPerMessage)

View file

@ -4,7 +4,9 @@ import (
"fmt" "fmt"
"github.com/anhgelus/gokord" "github.com/anhgelus/gokord"
"math" "math"
"regexp"
"slices" "slices"
"strings"
"time" "time"
) )
@ -57,3 +59,15 @@ func TimeStampNDaysBefore(n uint) string {
} }
return fmt.Sprintf("%d-%d-%d", y, m, d) return fmt.Sprintf("%d-%d-%d", y, m, d)
} }
func TrimMessage(s string) string {
not := regexp.MustCompile("[^a-zA-Z0-9éèêàùûç,;:!.?]")
ping := regexp.MustCompile("<(@&?|#)[0-9]{18}>")
link := regexp.MustCompile("https?://[a-zA-Z0-9.]+[.][a-z]+.*")
s = ping.ReplaceAllLiteralString(s, "")
s = link.ReplaceAllLiteralString(s, "")
s = not.ReplaceAllLiteralString(s, "")
return strings.Trim(s, " ")
}