create embed post for epic games

because they no longer create them for urls
This commit is contained in:
Seraphim Strub 2024-05-29 21:35:12 +00:00
parent b6d8863195
commit 1d5c7056be
4 changed files with 28 additions and 8 deletions

View file

@ -11,4 +11,5 @@ type Deal struct {
Id string Id string
Title string Title string
Url string Url string
Image string
} }

View file

@ -42,6 +42,10 @@ type epicApiBody struct {
Description string `json:"description"` Description string `json:"description"`
OfferType string `json:"offerType"` OfferType string `json:"offerType"`
IsCodeRedemptionOnly bool `json:"isCodeRedemptionOnly"` IsCodeRedemptionOnly bool `json:"isCodeRedemptionOnly"`
KeyImages []struct {
Type string `json:"type"`
Url string `json:"url"`
} `json:"keyImages"`
ProductSlug string `json:"productSlug"` ProductSlug string `json:"productSlug"`
OfferMappings []struct { OfferMappings []struct {
PageSlug string `json:"pageSlug"` PageSlug string `json:"pageSlug"`
@ -119,6 +123,13 @@ func (e EpicStruct) Load() error {
continue continue
} }
image := ""
for _, keyImage := range element.KeyImages {
if keyImage.Type == "DieselStoreFrontWide" {
image = keyImage.Url
}
}
id := fmt.Sprintf("%v%v", e.idPrefix, element.Id) id := fmt.Sprintf("%v%v", e.idPrefix, element.Id)
title := element.Title title := element.Title
url := fmt.Sprintf("%v%v", e.baseUrl, productSlug) url := fmt.Sprintf("%v%v", e.baseUrl, productSlug)
@ -127,6 +138,7 @@ func (e EpicStruct) Load() error {
Id: id, Id: id,
Title: title, Title: title,
Url: url, Url: url,
Image: image,
} }
} }

View file

@ -116,12 +116,21 @@ func main() {
} }
func sendWebhook(client webhook.Client, deal api.Deal) { 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(). if _, err := client.CreateMessage(message.Build(),
SetContent(status).Build(),
rest.WithDelay(2*time.Second), rest.WithDelay(2*time.Second),
); err != nil { ); err != nil {
logger.Error("sending message failed", slog.Any("error", err)) logger.Error("sending message failed", slog.Any("error", err))

2
go.sum
View file

@ -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/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 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA=
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= 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 h1:apcjvQsrTAVv76i5+GxFLRjWa10nFRKZXtPJ+2SD0iU=
github.com/disgoorg/disgo v0.18.6/go.mod h1:gkl6DBdbKUvmOOJayWPSvS52KPN/8uJGJ2f13gCEB1o= github.com/disgoorg/disgo v0.18.6/go.mod h1:gkl6DBdbKUvmOOJayWPSvS52KPN/8uJGJ2f13gCEB1o=
github.com/disgoorg/json v1.1.0 h1:7xigHvomlVA9PQw9bMGO02PHGJJPqvX5AnwlYg/Tnys= github.com/disgoorg/json v1.1.0 h1:7xigHvomlVA9PQw9bMGO02PHGJJPqvX5AnwlYg/Tnys=