diff options
| author | Anhgelus Morhtuuzh <anhgelus@anhgelus.world> | 2025-08-06 02:15:08 +0200 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <anhgelus@anhgelus.world> | 2025-08-06 02:15:08 +0200 |
| commit | d72004ae1470711d8a58199d89edfcfccd6ea77f (patch) | |
| tree | 59685ffa6903f2d7b9e3f9271705e13961cdaac5 | |
| parent | 30992e873cc5d68f7e231e5ea920e5fec748836d (diff) | |
| parent | cf2093095e769cdfac7fd83adc61d7ff6e958c0a (diff) | |
Merge branch 'main' into refactor/config-command
| -rw-r--r-- | events.go | 2 | ||||
| -rw-r--r-- | exp/functions.go | 14 |
2 files changed, 15 insertions, 1 deletions
@@ -31,7 +31,7 @@ func OnMessage(s *discordgo.Session, m *discordgo.MessageCreate) { } c := user.GetCopaing(m.Author.ID, m.GuildID) // add exp - trimmed := utils.TrimMessage(strings.ToLower(m.Content)) + trimmed := exp.TrimMessage(strings.ToLower(m.Content)) m.Member.User = m.Author m.Member.GuildID = m.GuildID xp := min(exp.MessageXP(uint(len(trimmed)), exp.CalcDiversity(trimmed)), MaxXpPerMessage) diff --git a/exp/functions.go b/exp/functions.go index 119b6a8..026eb34 100644 --- a/exp/functions.go +++ b/exp/functions.go @@ -4,7 +4,9 @@ import ( "fmt" "github.com/anhgelus/gokord" "math" + "regexp" "slices" + "strings" "time" ) @@ -57,3 +59,15 @@ func TimeStampNDaysBefore(n uint) string { } 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, " ") +} |
