From a68146e0280fb95d9f237b17677644bc445bc48e Mon Sep 17 00:00:00 2001 From: Denozordec Date: Sun, 15 Mar 2026 21:33:05 +0700 Subject: [PATCH] Add deduplication of strings in link rewriting process in main.go to ensure unique links are returned, enhancing link handling efficiency. --- main.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 37106f1..675d464 100644 --- a/main.go +++ b/main.go @@ -389,6 +389,22 @@ func hasAnyLinks(links userLinks) bool { // serverParamRe matches server=... in tg://proxy URLs var serverParamRe = regexp.MustCompile(`server=[^&]+`) +func deduplicateStrings(items []string) []string { + if len(items) <= 1 { + return items + } + seen := make(map[string]struct{}, len(items)) + out := make([]string, 0, len(items)) + for _, s := range items { + if _, ok := seen[s]; ok { + continue + } + seen[s] = struct{}{} + out = append(out, s) + } + return out +} + func (b *bot) rewriteLinksWithHost(links userLinks) userLinks { host := strings.TrimSpace(b.cfg.TelemtLinkHost) if host == "" { @@ -403,7 +419,7 @@ func (b *bot) rewriteLinksWithHost(links userLinks) userLinks { for i, s := range items { out[i] = serverParamRe.ReplaceAllString(s, replacement) } - return out + return deduplicateStrings(out) } return userLinks{ Classic: rewrite(links.Classic),