diff --git a/api-client/epic-games-store.js b/api-client/epic-games-store.js index b888ca7..aca3735 100644 --- a/api-client/epic-games-store.js +++ b/api-client/epic-games-store.js @@ -1,6 +1,17 @@ -const productBaseUrl = "https://www.epicgames.com/store/en-US/product/"; +import loadConfig from "../utils/config.js"; + +const { settings = {}, epicGamesStore = {} } = await loadConfig(); + +const timeZone = settings?.timeZone || "America/Los_Angeles"; +const locale = settings?.locale || "en-US"; +const country = settings?.country || "US"; + +const productBaseUrl = + epicGamesStore?.productBaseUrl || + `https://www.epicgames.com/store/${locale}/product/`; const freeGamesApiUrl = - "https://store-site-backend-static.ak.epicgames.com/freeGamesPromotions?locale=en-US&country=US&allowCountries=US"; + epicGamesStore?.freeGamesApiUrl || + `https://store-site-backend-static.ak.epicgames.com/freeGamesPromotions?locale=${locale}&country=${country}&allowCountries=${country}`; function isCurrentlyFree(game) { const currentDate = Date.now(); @@ -24,8 +35,8 @@ function getFormattedEndDate(game) { game?.promotions?.promotionalOffers[0]?.promotionalOffers[0]?.endDate; if (giveawayEnd !== null) { - return new Date(giveawayEnd).toLocaleString("en-US", { - timeZone: "America/Los_Angeles", + return new Date(giveawayEnd).toLocaleString(locale, { + timeZone, dateStyle: "full", timeStyle: "long", }); @@ -67,7 +78,7 @@ export async function fetchFreeGames() { if (!response.ok) { throw new Error( - `Could not obtain Token Price, server responded with: ${response}` + `Error while fetching free Epic Games Store games, server responded with: ${response}` ); } diff --git a/config.example.json b/config.example.json index 52017a3..c9d2d21 100644 --- a/config.example.json +++ b/config.example.json @@ -1,21 +1,30 @@ { + "http": { + "host": "https://example.com", + "listenHost": "127.0.0.1", + "listenPort": 5000 + }, + "settings": { + "timeZone": "America/Los_Angeles", + "locale": "en-US", + "country": "US" + }, "discord": { "clientId": "", "guildId": "", "token": "" }, + "channels": { + "deals": "" + }, "blizzard": { "clientId": "", "clientSecret": "", "authTokenUrl": "https://us.battle.net/oauth/token?grant_type=client_credentials", "tokenPriceUrl": "https://us.api.blizzard.com/data/wow/token/index?namespace=dynamic-us" }, - "http": { - "host": "https://example.com", - "listenHost": "127.0.0.1", - "listenPort": 5000 - }, - "channels": { - "deals": "" + "epicGamesStore": { + "productBaseUrl": "https://www.epicgames.com/store/en-US/product/", + "freeGamesApiUrl": "https://store-site-backend-static.ak.epicgames.com/freeGamesPromotions?locale=en_US&country=US&allowCountries=US" } } diff --git a/cron-tasks/fetch-free-epic-games.js b/cron-tasks/fetch-free-epic-games.js index 592cd10..8b8dd59 100644 --- a/cron-tasks/fetch-free-epic-games.js +++ b/cron-tasks/fetch-free-epic-games.js @@ -3,12 +3,10 @@ import { EmbedBuilder } from "discord.js"; import { fetchNewGames } from "../models/epic-games-store.js"; import loadConfig from "../utils/config.js"; -const { - channels: { deals }, -} = await loadConfig(); +const { channels: { deals = false } = {} } = await loadConfig(); function postNewDeals(client, games) { - if (games.length > 0) { + if (games.length > 0 && deals) { try { const channel = client.channels.cache.get(deals);