From 18256f00d3be8dd4818c05a0b3703d6585a53e28 Mon Sep 17 00:00:00 2001 From: krau <71133316+krau@users.noreply.github.com> Date: Mon, 27 Jan 2025 18:48:58 +0800 Subject: [PATCH] feat: enhance artwork caption with username and website link --- telegram/utils/post_artwork.go | 5 ++++- telegram/utils/utils.go | 11 ++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/telegram/utils/post_artwork.go b/telegram/utils/post_artwork.go index 8b2adce..d8689f3 100644 --- a/telegram/utils/post_artwork.go +++ b/telegram/utils/post_artwork.go @@ -369,10 +369,13 @@ func recaptionArtwork(ctx context.Context, artwork *types.Artwork, bot *telego.B return } newCaption := GetArtworkHTMLCaption(newArtwork) - bot.EditMessageCaption(&telego.EditMessageCaptionParams{ + _, err = bot.EditMessageCaption(&telego.EditMessageCaptionParams{ ChatID: ChannelChatID, MessageID: newArtwork.Pictures[0].TelegramInfo.MessageID, Caption: newCaption, ParseMode: telego.ModeHTML, }) + if err != nil { + common.Logger.Warnf("error when recaption artwork: %s", err) + } } diff --git a/telegram/utils/utils.go b/telegram/utils/utils.go index 06b2e4c..5cdbeae 100644 --- a/telegram/utils/utils.go +++ b/telegram/utils/utils.go @@ -99,7 +99,16 @@ func GetArtworkHTMLCaption(artwork *types.Artwork) string { tag = tagCharsReplacer.Replace(tag) tags += "#" + strings.TrimSpace(common.EscapeHTML(tag)) + " " } - caption += fmt.Sprintf("\n
%s
", tags) + caption += fmt.Sprintf("\n
%s
\n", tags) + if ChannelChatID.Username != "" { + caption += common.EscapeHTML(ChannelChatID.Username) + } + if artwork.ID != "" && config.Cfg.API.SiteURL != "" { + if ChannelChatID.Username != "" { + caption += " | " + } + caption += fmt.Sprintf("在网站查看", config.Cfg.API.SiteURL, artwork.ID) + } return caption }