refactor(xp): use own trim function

for next gokord update
This commit is contained in:
Anhgelus Morhtuuzh 2025-08-04 13:21:32 +02:00
parent 977c818328
commit cf2093095e
Signed by: anhgelus
GPG key ID: 617773CACE89052C
2 changed files with 15 additions and 1 deletions

View file

@ -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, " ")
}