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
Title string
Url string
Image string
}

View file

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

View file

@ -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))