Skip to content

Commit

Permalink
fix error obtaining product slug for url (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
j6nca authored Jun 6, 2024
1 parent 3862f5f commit c988bd1
Show file tree
Hide file tree
Showing 4 changed files with 907 additions and 10 deletions.
6 changes: 6 additions & 0 deletions bot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ A script to check Epic Games store weekly for new freebies, pushes notifications

## Usage

### Local
```
npm install
npm run start
```

### Docker
```
docker run -e SEND_UPCOMING=true -e DISCORD_WEBHOOK='foobar' \
Expand Down
4 changes: 2 additions & 2 deletions bot/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions bot/src/epic_games.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ async function check_store() {
const title = game.title
console.log(game.title)
console.log(game.catalogNs.mappings)
const slug = game.catalogNs.mappings != null && game.catalogNs.mappings.length > 0 ? game.catalogNs.mappings[0].pageSlug : "error"
const slug = game.productSlug != null ? game.productSlug : game.catalogNs.mappings != null && game.catalogNs.mappings.length > 0 ? game.catalogNs.mappings[0].pageSlug : "error"
console.log(slug)
var original_price = game.price.totalPrice.fmtPrice.originalPrice
original_price = parseFloat(original_price.replace(/[^0-9\.]+/g,"")).toFixed(2).toString()
original_price = parseFloat(original_price.replace(/[^0-9\.]+/g, "")).toFixed(2).toString()
const publisher = game.seller.name
const description = game.description
var thumbnail = game.keyImages != null ? game.keyImages[0].url : "error"
Expand Down Expand Up @@ -70,14 +70,14 @@ async function check_store() {
}

// Skip any false-positives (may just be on sale, or non-updated)
if (game.price.totalPrice.discountPrice != 0){
if (game.price.totalPrice.discountPrice != 0) {
skip = true
}
if (!sendUpcoming && end_date == null){

if (!sendUpcoming && end_date == null) {
skip = true
}

if (!skip) {
const found_game = {
title: title,
Expand All @@ -93,7 +93,7 @@ async function check_store() {
}
})
const ordered_game_list = game_list.sort(
function(a, b) {
function (a, b) {
return (a.end_date === null) - (b.end_date === null) || +(a > b) || -(a < b);
})

Expand Down Expand Up @@ -181,7 +181,7 @@ check_store().then(games => {
games.forEach((game) => {
var webhooks = discord_webhook.split(",")
webhooks.forEach((webhook) => {
if(notify){
if (notify) {
send_discord(game, webhook)
}
})
Expand Down
Loading

0 comments on commit c988bd1

Please sign in to comment.