diff --git a/README.md b/README.md index 1cf0ae6..39582a7 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,16 @@ Claim [available free game promotions](https://www.epicgames.com/store/free-game ## Instructions 1. Download/clone repo -2. Edit `index.js` to include your EpicGames credentials -2. Run `npm install` -3. Run `node index.js` +2. (Optional) Edit `config.json` to include your EpicGames credentials +3. Run `npm install` +4. Run `node gimme_free_epic_shit` or `node gimme_free_epic_shit USERNAME PASSWORD` + +## Changelog +V1.1.0 + * Added support for email/password arguments + * Moved saved credentials to config.json + * Ensured all search results are returned + * Fixed program not exiting + +V1.0.0 + * Initial release \ No newline at end of file diff --git a/config.json b/config.json new file mode 100644 index 0000000..539e797 --- /dev/null +++ b/config.json @@ -0,0 +1,4 @@ +{ + "email": "YOUR_EMAIL_HERE", + "password": "YOUR_PASSWORD_HERE" +} \ No newline at end of file diff --git a/gimme_free_epic_shit.js b/gimme_free_epic_shit.js new file mode 100644 index 0000000..da39e9c --- /dev/null +++ b/gimme_free_epic_shit.js @@ -0,0 +1,53 @@ +const { Launcher } = require(`epicgames-client`); +const { email, password } = require(`${__dirname}/config.json`); +const epic = new Launcher({ + email: process.argv[2] || email, + password: process.argv[3] || password +}); + +(async () => { + if (!await epic.init() || !await epic.login()) { + throw new Error(`Error while initialize or login process.`); + } + + console.log(`Logged in as ${epic.account.name} (${epic.account.id})`); + + let getAllOffers = async (ns, n=100) => { + let i = 0; + let results = []; + while ((i * n) - results.length === 0) { + let { elements } = await epic.getOffersForNamespace(ns, n, n * i++); + results = results.concat(elements); + } + return results; + }; + + let all = await getAllOffers(`epic`); + let freegames = all.filter(game => game.categories.find(cat => cat.path === `freegames`)); + + for (let game of freegames) { + let namespace = game.customAttributes[`com.epicgames.app.offerNs`].value + if (!namespace) { + continue; + } + + let offers = await getAllOffers(namespace); + let offer = offers.find(game => game.currentPrice === 0 && game.discountPercentage === 0); + if (!offer) { + continue; + } + + let purchased = await epic.purchase(offer, 1); + if (purchased) { + console.log(`Successfully claimed ${offer.title} (${purchased})`); + } + } + + await epic.logout(); + console.log(`Enjoy!`); + process.exit(0); + +})().catch(err => { + console.error(err); + process.exit(1) +}); \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index f03a083..0000000 --- a/index.js +++ /dev/null @@ -1,30 +0,0 @@ -const { Launcher } = require(`epicgames-client`); - -const epic = new Launcher({ - email: `YOUR_EMAIL_HERE`, - password: `YOUR_PASSWORD_HERE` -}); - -(async () => { - if(!await epic.init() || !await epic.login()) { - throw new Error(`Error while initialize or login process.`); - } - - console.log(`Logged in as ${epic.account.name} (${epic.account.id})`); - - let all = await epic.getOffersForNamespace(`epic`, 1000, 0); - let freegames = all.elements.filter(game => game.categories.find(cat => cat.path === `freegames`)); - for (let game of freegames) { - let namespace = game.customAttributes[`com.epicgames.app.offerNs`].value - if (!namespace) { - continue; - } - - let offers = await epic.getOffersForNamespace(namespace, 100, 0); - let offer = offers.elements.find(game => game.currentPrice === 0 && game.discountPercentage === 0); - let purchased = await epic.purchase(offer, 1).catch(console.error); - if (purchased) { - console.log(`Successfully redeemed ${offer.title} (${purchased})`); - } - } -})(); \ No newline at end of file diff --git a/package.json b/package.json index b70179c..d9b2a12 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "epicgames-freebies-claimer", "description": "Claim free game promotions from the Epic Game Store", - "version": "1.0.0", + "version": "1.1.0", "author": "Revadike", "homepage": "https://revadike.com", "url": "https://github.com/revadike/epicgames-freebies-claimer", @@ -10,4 +10,4 @@ "dependencies": { "epicgames-client": "latest" } -} \ No newline at end of file +}