From 08c096ddb2761e84af0c5b7c6ab0b15adff1ce2e Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Wed, 4 Aug 2021 15:11:35 +0200 Subject: [PATCH] Force Discord to fetch fresh previews for the streams Signed-off-by: Knut Ahlers --- mod_livePosting.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/mod_livePosting.go b/mod_livePosting.go index f0acfd2..bc1bbba 100644 --- a/mod_livePosting.go +++ b/mod_livePosting.go @@ -222,6 +222,18 @@ func (m modLivePosting) sendLivePost(username, displayName, title, game, preview } } + // Discord caches the images and the URLs do not change every time + // so we force Discord to load a new image every time + previewImageURL, err := url.Parse( + strings.NewReplacer( + "{width}", strconv.Itoa(livePostingPreviewWidth), + "{height}", strconv.Itoa(livePostingPreviewHeight), + ).Replace(previewImage), + ) + previewImageQuery := previewImageURL.Query() + previewImageQuery.Add("_discordNoCache", time.Now().Format(time.RFC3339)) + previewImageURL.RawQuery = previewImageQuery.Encode() + msgEmbed := &discordgo.MessageEmbed{ Author: &discordgo.MessageEmbedAuthor{ Name: displayName, @@ -232,7 +244,7 @@ func (m modLivePosting) sendLivePost(username, displayName, title, game, preview {Name: "Game", Value: game}, }, Image: &discordgo.MessageEmbedImage{ - URL: strings.NewReplacer("{width}", strconv.Itoa(livePostingPreviewWidth), "{height}", strconv.Itoa(livePostingPreviewHeight)).Replace(previewImage), + URL: previewImageURL.String(), Width: livePostingPreviewWidth, Height: livePostingPreviewHeight, },