fix: twitter plugin replacement logic
Some checks failed
ci/woodpecker/push/ci Pipeline failed
ci/woodpecker/tag/release Pipeline was successful

This commit is contained in:
Felipe M 2025-06-23 11:18:47 +02:00
parent 3b09a9dd47
commit 368c45cd13
Signed by: fmartingr
GPG key ID: CCFBC5637D4000A8

View file

@ -54,17 +54,12 @@ func (p *TwitterExpander) OnMessage(msg *model.Message, config map[string]interf
// Parse the URL
parsedURL, err := url.Parse(link)
if err != nil {
// If parsing fails, just do the simple replacement
link = strings.Replace(link, "twitter.com", replacementDomain, 1)
link = strings.Replace(link, "x.com", replacementDomain, 1)
return link
}
// Change the host to the configured domain
if strings.Contains(parsedURL.Host, "twitter.com") {
parsedURL.Host = strings.Replace(parsedURL.Host, "twitter.com", replacementDomain, 1)
} else if strings.Contains(parsedURL.Host, "x.com") {
parsedURL.Host = strings.Replace(parsedURL.Host, "x.com", replacementDomain, 1)
if strings.Contains(parsedURL.Host, "twitter.com") || strings.Contains(parsedURL.Host, "x.com") {
parsedURL.Host = replacementDomain
}
// Remove query parameters