Force Discord to fetch fresh previews for the streams

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2021-08-04 15:11:35 +02:00
parent 19c1c4d7b5
commit 08c096ddb2
Signed by: luzifer
GPG Key ID: 0066F03ED215AD7D

View File

@ -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,
},