mirror of
https://github.com/prosolis/gogobee.git
synced 2026-07-15 08:32:41 +00:00
Skip URL preview when message contains multiple links
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -56,17 +56,21 @@ func (p *URLsPlugin) OnMessage(ctx MessageContext) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
urls := urlRe.FindAllString(ctx.Body, 5) // limit to 5 URLs per message
|
allURLs := urlRe.FindAllString(ctx.Body, -1)
|
||||||
if len(urls) == 0 {
|
// Filter out Matrix internal links (user mentions, room links, etc.)
|
||||||
|
var urls []string
|
||||||
|
for _, u := range allURLs {
|
||||||
|
if !strings.Contains(u, "matrix.to/") {
|
||||||
|
urls = append(urls, u)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only preview if there is exactly one URL; skip multi-URL messages
|
||||||
|
if len(urls) != 1 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, u := range urls {
|
for _, u := range urls {
|
||||||
// Skip Matrix internal links (user mentions, room links, etc.)
|
|
||||||
if strings.Contains(u, "matrix.to/") {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
title, desc, err := p.fetchPreview(u)
|
title, desc, err := p.fetchPreview(u)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Debug("urls: fetch preview failed", "url", u, "err", err)
|
slog.Debug("urls: fetch preview failed", "url", u, "err", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user