feat: add configuration options for instagram and twitter plugins
This commit is contained in:
parent
3a4ba376e7
commit
fc77c97547
5 changed files with 57 additions and 18 deletions
|
@ -18,9 +18,10 @@ type TwitterExpander struct {
|
|||
func NewTwitterExpander() *TwitterExpander {
|
||||
return &TwitterExpander{
|
||||
BasePlugin: plugin.BasePlugin{
|
||||
ID: "social.twitter",
|
||||
Name: "Twitter Link Expander",
|
||||
Help: "Automatically converts twitter.com links to fxtwitter.com links and removes tracking parameters",
|
||||
ID: "social.twitter",
|
||||
Name: "Twitter Link Expander",
|
||||
Help: "Automatically converts twitter.com and x.com links to alternative domain links and removes tracking parameters. Configure 'domain' option to set replacement domain (default: fxtwitter.com)",
|
||||
ConfigRequired: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +33,12 @@ func (p *TwitterExpander) OnMessage(msg *model.Message, config map[string]interf
|
|||
return nil
|
||||
}
|
||||
|
||||
// Get replacement domain from config, default to fxtwitter.com
|
||||
replacementDomain := "fxtwitter.com"
|
||||
if domain, ok := config["domain"].(string); ok && domain != "" {
|
||||
replacementDomain = domain
|
||||
}
|
||||
|
||||
// Regex to match twitter.com links
|
||||
// Match both http://twitter.com and https://twitter.com formats
|
||||
// Also match www.twitter.com
|
||||
|
@ -42,22 +49,22 @@ func (p *TwitterExpander) OnMessage(msg *model.Message, config map[string]interf
|
|||
return nil
|
||||
}
|
||||
|
||||
// Replace twitter.com with fxtwitter.com in the message and clean query parameters
|
||||
// Replace twitter.com/x.com with configured domain in the message and clean query parameters
|
||||
transformed := twitterRegex.ReplaceAllStringFunc(msg.Text, func(link string) string {
|
||||
// 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", "fxtwitter.com", 1)
|
||||
link = strings.Replace(link, "x.com", "fxtwitter.com", 1)
|
||||
link = strings.Replace(link, "twitter.com", replacementDomain, 1)
|
||||
link = strings.Replace(link, "x.com", replacementDomain, 1)
|
||||
return link
|
||||
}
|
||||
|
||||
// Change the host
|
||||
// Change the host to the configured domain
|
||||
if strings.Contains(parsedURL.Host, "twitter.com") {
|
||||
parsedURL.Host = strings.Replace(parsedURL.Host, "twitter.com", "fxtwitter.com", 1)
|
||||
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", "fxtwitter.com", 1)
|
||||
parsedURL.Host = strings.Replace(parsedURL.Host, "x.com", replacementDomain, 1)
|
||||
}
|
||||
|
||||
// Remove query parameters
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue