create embed post for epic games
because they no longer create them for urls
This commit is contained in:
parent
b6d8863195
commit
1d5c7056be
4 changed files with 28 additions and 8 deletions
|
@ -11,4 +11,5 @@ type Deal struct {
|
|||
Id string
|
||||
Title string
|
||||
Url string
|
||||
Image string
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
2
go.sum
2
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=
|
||||
|
|
Loading…
Reference in a new issue