Skip to content

Commit

Permalink
fix(discord-bot): ensure accurate parsing of Twitch.tv URLs regardles…
Browse files Browse the repository at this point in the history
…s of trailing punctuation (#538)
  • Loading branch information
barbequeorbarbecue authored Jan 26, 2025
1 parent 48ddb6b commit 194c28d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions helper/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,18 @@ func ContainsLowerCase(s string, substr string) bool {
return strings.Contains(strings.ToLower(s), substr)
}

func removeTrailingPunctuationFromURL(s string) string {
re := regexp.MustCompile(`[^_\w]+$`)
return re.ReplaceAllString(s, "")
}

func GetURL(domain, messageContent string) string {
pattern := fmt.Sprintf(`%s\S*`, domain)
re := regexp.MustCompile(pattern)
match := re.FindString(messageContent)

if match != "" {
match = removeTrailingPunctuationFromURL(match)
return "https://" + match
}

Expand Down

0 comments on commit 194c28d

Please sign in to comment.