From ad7e01f05218ca317a9426d99995dd6d2678583d Mon Sep 17 00:00:00 2001 From: krau <71133316+krau@users.noreply.github.com> Date: Sun, 21 Dec 2025 13:17:10 +0800 Subject: [PATCH] fix: improve text message handling by removing duplicates and empty lines --- client/bot/handlers/parse.go | 20 ++++++++++++++++++-- client/bot/handlers/utils/msgelem/parse.go | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/client/bot/handlers/parse.go b/client/bot/handlers/parse.go index 808727c..8de413c 100644 --- a/client/bot/handlers/parse.go +++ b/client/bot/handlers/parse.go @@ -31,7 +31,23 @@ func handleTextMessage(ctx *ext.Context, u *ext.Update) error { if len(entityUrls) > 0 { text += "\n" + strings.Join(entityUrls, "\n") } - ok, pser := parsers.CanHandle(text) + // read lines and remove empty lines & duplicates + lines := strings.Split(text, "\n") + seen := make(map[string]struct{}) + var processedLines []string + for _, line := range lines { + line = strings.TrimSpace(line) + if line == "" { + continue + } + if _, ok := seen[line]; ok { + continue + } + seen[line] = struct{}{} + processedLines = append(processedLines, line) + } + source := strings.TrimSpace(strings.Join(processedLines, "\n")) + ok, pser := parsers.CanHandle(source) if !ok { return dispatcher.EndGroups } @@ -40,7 +56,7 @@ func handleTextMessage(ctx *ext.Context, u *ext.Update) error { return err } - item, err := pser.Parse(ctx, text) + item, err := pser.Parse(ctx, source) if errors.Is(err, parsers.ErrNoParserFound) { return dispatcher.EndGroups } diff --git a/client/bot/handlers/utils/msgelem/parse.go b/client/bot/handlers/utils/msgelem/parse.go index a5adc88..9795176 100644 --- a/client/bot/handlers/utils/msgelem/parse.go +++ b/client/bot/handlers/utils/msgelem/parse.go @@ -21,7 +21,7 @@ func BuildParsedTextEntity(item parser.Item) (string, []tg.MessageEntityClass, e styling.Plain(i18n.T(i18nk.BotMsgParseInfoAuthorPrefix, nil)), styling.Code(item.Author), styling.Plain(i18n.T(i18nk.BotMsgParseInfoDescriptionPrefix, nil)), - styling.Code(strutil.Ellipsis(item.Description, 233)), + styling.Blockquote(strutil.Ellipsis(item.Description, 233), true), styling.Plain(i18n.T(i18nk.BotMsgParseInfoFileCountPrefix, nil)), styling.Code(fmt.Sprintf("%d", len(item.Resources))), styling.Plain(i18n.T(i18nk.BotMsgParseInfoTotalSizePrefix, nil)),