From b26037c7dccdfc7c8b6df06a146e4ede332cc42b Mon Sep 17 00:00:00 2001 From: davtur19 Date: Thu, 26 Mar 2026 19:39:52 +0100 Subject: [PATCH] Add mention for clarity --- .env.example | 3 ++- internal/core/inline.go | 1 + internal/core/main.go | 1 + internal/core/util.go | 25 +++++++++++++++++++++++-- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index 803add0..65ed848 100644 --- a/.env.example +++ b/.env.example @@ -31,6 +31,7 @@ DEFAULT_ENABLE_SILENT=false DEFAULT_ENABLE_NSFW=false DEFAULT_MEDIA_ALBUM_LIMIT=10 DEFAULT_LANGUAGE=en +DEFAULT_DELETE_LINKS=false # other REPO_URL=https://github.com/govdbot/govd @@ -38,7 +39,7 @@ PROFILER_PORT=6060 # default pprof port METRICS_PORT=8080 # default prometheus metrics port LOG_LEVEL=info WHITELIST=id1,id2,id3 -CAPTIONS_HEADER="source - @{{username}}" +CAPTIONS_HEADER="{{mention}}:\nsource - @{{username}}" CAPTIONS_DESCRIPTION="
{{text}}
" ADMINS=id1,id2 AUTOMATIC_LANGUAGE_DETECTION=true diff --git a/internal/core/inline.go b/internal/core/inline.go index dafd7fd..3ded59a 100644 --- a/internal/core/inline.go +++ b/internal/core/inline.go @@ -89,6 +89,7 @@ func HandleInlineResultTask( taskResult.Media, bot.Username, extractorCtx.Chat.Captions, + ctx.EffectiveUser, ) err = SendInlineFormats( diff --git a/internal/core/main.go b/internal/core/main.go index 7da00ee..177233c 100644 --- a/internal/core/main.go +++ b/internal/core/main.go @@ -34,6 +34,7 @@ func HandleDownloadTask( taskResult.Media, bot.Username, extractorCtx.Chat.Captions, + ctx.EffectiveUser, ) _, err = SendFormats( diff --git a/internal/core/util.go b/internal/core/util.go index 44fe2ab..a97e15e 100644 --- a/internal/core/util.go +++ b/internal/core/util.go @@ -13,6 +13,7 @@ import ( "github.com/govdbot/govd/internal/util" "github.com/govdbot/govd/internal/util/download" "github.com/govdbot/govd/internal/util/libav" + "github.com/PaulSonOfLars/gotgbot/v2" ) var ErrNoMedia = errors.New("no media found") @@ -86,22 +87,42 @@ func insertVideoInfo(format *models.MediaFormat, filePath string) { format.Height = height } -func formatCaption(media *models.Media, username string, isEnabled bool) string { +func formatCaption(media *models.Media, botUsername string, isEnabled bool, user *gotgbot.User) string { caption := media.Caption if len(caption) > 600 { caption = caption[:600] + "..." } + formatText := func(s string) string { - s = strings.ReplaceAll(s, "{{username}}", username) + var displayName string + if user.Username != "" { + displayName = "@" + user.Username + } else { + displayName = user.FirstName + if user.LastName != "" { + displayName += " " + user.LastName + } + } + + // Wrap the name/username in a permanent ID link to handle username changes + mention := fmt.Sprintf("%s", user.Id, displayName) + + s = strings.ReplaceAll(s, "{{username}}", botUsername) s = strings.ReplaceAll(s, "{{url}}", media.ContentURL) s = strings.ReplaceAll(s, "{{text}}", util.Unquote(caption)) + s = strings.ReplaceAll(s, "{{mention}}", mention) return s } + var description string header := formatText(config.Env.CaptionsHeader) if isEnabled && caption != "" { description = formatText(config.Env.CaptionsDescription) } + + if description == "" { + return header + } return header + "\n" + description }