diff options
| author | William Hergès <william@herges.fr> | 2025-08-04 13:21:32 +0200 |
|---|---|---|
| committer | William Hergès <william@herges.fr> | 2025-08-04 13:21:32 +0200 |
| commit | cf2093095e769cdfac7fd83adc61d7ff6e958c0a (patch) | |
| tree | 0e644abaa4d520d032738ab2582b6c09d39776c3 /exp | |
| parent | 977c818328c1c14880029510c6b3742a12858dcb (diff) | |
refactor(xp): use own trim function
for next gokord update
Diffstat (limited to 'exp')
| -rw-r--r-- | exp/functions.go | 14 |
1 files changed, 14 insertions, 0 deletions
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, " ") +} |
