From 1d5c7056be5054086f4848524849d6a94fd6e94d Mon Sep 17 00:00:00 2001 From: Seraphim Strub Date: Wed, 29 May 2024 21:35:12 +0000 Subject: [PATCH] create embed post for epic games because they no longer create them for urls --- cmd/dealsbot/api/api.go | 1 + cmd/dealsbot/api/epic.go | 16 ++++++++++++++-- cmd/dealsbot/main.go | 17 +++++++++++++---- go.sum | 2 -- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/cmd/dealsbot/api/api.go b/cmd/dealsbot/api/api.go index dbddd27..46f29a7 100644 --- a/cmd/dealsbot/api/api.go +++ b/cmd/dealsbot/api/api.go @@ -11,4 +11,5 @@ type Deal struct { Id string Title string Url string + Image string } diff --git a/cmd/dealsbot/api/epic.go b/cmd/dealsbot/api/epic.go index 5a1b985..bf285e4 100644 --- a/cmd/dealsbot/api/epic.go +++ b/cmd/dealsbot/api/epic.go @@ -42,8 +42,12 @@ type epicApiBody struct { Description string `json:"description"` OfferType string `json:"offerType"` IsCodeRedemptionOnly bool `json:"isCodeRedemptionOnly"` - ProductSlug string `json:"productSlug"` - OfferMappings []struct { + KeyImages []struct { + Type string `json:"type"` + Url string `json:"url"` + } `json:"keyImages"` + ProductSlug string `json:"productSlug"` + OfferMappings []struct { PageSlug string `json:"pageSlug"` PageType string `json:"pageType"` } `json:"offerMappings"` @@ -119,6 +123,13 @@ func (e EpicStruct) Load() error { continue } + image := "" + for _, keyImage := range element.KeyImages { + if keyImage.Type == "DieselStoreFrontWide" { + image = keyImage.Url + } + } + id := fmt.Sprintf("%v%v", e.idPrefix, element.Id) title := element.Title url := fmt.Sprintf("%v%v", e.baseUrl, productSlug) @@ -127,6 +138,7 @@ func (e EpicStruct) Load() error { Id: id, Title: title, Url: url, + Image: image, } } diff --git a/cmd/dealsbot/main.go b/cmd/dealsbot/main.go index 9fdf18e..70d1828 100644 --- a/cmd/dealsbot/main.go +++ b/cmd/dealsbot/main.go @@ -116,12 +116,21 @@ func main() { } func sendWebhook(client webhook.Client, deal api.Deal) { - var status string + content := "currently free:" + message := discord.NewWebhookMessageCreateBuilder() - status = fmt.Sprintf("currently free: %v\n", deal.Url) + if deal.Image == "" { + message.SetContent(fmt.Sprintf("%v %v\n", content, deal.Url)) + } else { + message.SetContent(content).SetEmbeds( + discord.NewEmbedBuilder(). + SetTitle(deal.Title). + SetURL(deal.Url). + SetImage(deal.Image). + Build()) + } - if _, err := client.CreateMessage(discord.NewWebhookMessageCreateBuilder(). - SetContent(status).Build(), + if _, err := client.CreateMessage(message.Build(), rest.WithDelay(2*time.Second), ); err != nil { logger.Error("sending message failed", slog.Any("error", err)) diff --git a/go.sum b/go.sum index 63283f2..3b900e8 100644 --- a/go.sum +++ b/go.sum @@ -15,8 +15,6 @@ github.com/dgraph-io/ristretto v0.1.1 h1:6CWw5tJNgpegArSHpNHJKldNeq03FQCwYvfMVWa github.com/dgraph-io/ristretto v0.1.1/go.mod h1:S1GPSBCYCIhmVNfcth17y2zZtQT6wzkzgwUve0VDWWA= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= -github.com/disgoorg/disgo v0.18.5 h1:T4X9ARKJFwCon4xkw4Dg+SjGpFo7usQ7QCCX2+snGXQ= -github.com/disgoorg/disgo v0.18.5/go.mod h1:gkl6DBdbKUvmOOJayWPSvS52KPN/8uJGJ2f13gCEB1o= github.com/disgoorg/disgo v0.18.6 h1:apcjvQsrTAVv76i5+GxFLRjWa10nFRKZXtPJ+2SD0iU= github.com/disgoorg/disgo v0.18.6/go.mod h1:gkl6DBdbKUvmOOJayWPSvS52KPN/8uJGJ2f13gCEB1o= github.com/disgoorg/json v1.1.0 h1:7xigHvomlVA9PQw9bMGO02PHGJJPqvX5AnwlYg/Tnys=