Skip to content
This repository has been archived by the owner on May 12, 2024. It is now read-only.

Commit

Permalink
add some egs free game settings to settings file
Browse files Browse the repository at this point in the history
  • Loading branch information
aloop committed Jan 6, 2024
1 parent e01b611 commit 75a229e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
21 changes: 16 additions & 5 deletions api-client/epic-games-store.js
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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",
});
Expand Down Expand Up @@ -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}`
);
}

Expand Down
23 changes: 16 additions & 7 deletions config.example.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
6 changes: 2 additions & 4 deletions cron-tasks/fetch-free-epic-games.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 75a229e

Please sign in to comment.