Skip to content

Commit

Permalink
V1.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Revadike committed Apr 26, 2020
1 parent 343c09d commit 8033179
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 70 deletions.
3 changes: 1 addition & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"linebreak-style": "error",
"lines-between-class-members": ["error", "always"],
"max-classes-per-file": "error",
"max-depth": "error",
"max-depth": ["error", 5],
"max-len": ["error", 130],
"max-nested-callbacks": ["error", 4],
"max-statements-per-line": ["error", { "max": 2 }],
Expand Down Expand Up @@ -107,7 +107,6 @@
"no-trailing-spaces": "error",
"no-undef-init": "error",
"no-undefined": "error",
"no-unmodified-loop-condition": "error",
"no-unneeded-ternary": ["error", { "defaultAssignment": false }],
"no-unused-expressions": "error",
"no-use-before-define": "error",
Expand Down
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ Claim [available free game promotions](https://www.epicgames.com/store/free-game
## Requirements
* [Node.js](https://nodejs.org/download/)

## Instructions
## Instructions (config)
1. Download/clone repo
2. Run `npm install`
3. Edit `config.json` to include your EpicGames credentials and options
4. Run `node gimme_free_epic_shit`*

## Instructions (arguments)
1. Download/clone repo
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 0/1`*
4. Run `node gimme_free_epic_shit USERNAME PASSWORD 0/1`*

*Only this step is required after the initial use.

Expand All @@ -23,7 +28,16 @@ Also, this is a good alternative, in case you don't like using Epic's client or
### Why should I even bother claiming these free games?
To which I will say, why not? Most of these games are actually outstanding games! Even if you don't like Epic and their shenanigans, you will be pleased to know that Epic actually funds all the free copies that are given away: ["But we actually found it was more economical to pay developers [a lump sum] to distribute their game free for two weeks..."](https://arstechnica.com/gaming/2019/03/epic-ceo-youre-going-to-see-lower-prices-on-epic-games-store/)

### Can I use the looping or multi-account feature when using launch arguments?
No, these are only usable by using the config.

## Changelog
### V1.2.2
* Added looping feature a.k.a. run forever* (Closes #2)
* Added multi-account support*

*Please update your config accordingly

### V1.2.1
* Makes `rememberLastSession` optional in config or launch parameter (Closes #8)
* Added ESLint linter
Expand Down
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"rememberLastSession": true
}
],
"delay": 3600,
"delay": 1440,
"loop": true
}
122 changes: 59 additions & 63 deletions gimme_free_epic_shit.js
Original file line number Diff line number Diff line change
@@ -1,86 +1,82 @@
"use strict";
const { "Launcher": EpicGames } = require("epicgames-client");
const ClientLoginAdapter = require("epicgames-client-login-adapter");
const sleep = delay => new Promise(res => setTimeout(res, delay * 1000));
const { "Launcher": EpicGames } = require("epicgames-client");
let { accounts, delay, loop } = require(`${__dirname}/config.json`);

(async() => {
let config = require(`${__dirname}/config.json`);
let sleep = delay => new Promise(res => setTimeout(res, delay * 60000));
do {
try {
for (let accountId in config.accounts) {
let account = config.accounts[accountId];
const credentials = {
"email": process.argv[2] || account.email,
"password": process.argv[3] || account.password
};
if (typeof process.argv[4] === "undefined") {
credentials.rememberLastSession = account.rememberLastSession;
} else {
credentials.rememberLastSession = Boolean(Number(process.argv[4]));
}
let client = new EpicGames(credentials);
if (process.argv.length > 2) {
loop = false;
accounts = [{
"email": process.argv[2],
"password": process.argv[3],
"rememberLastSession": Boolean(Number(process.argv[4]))
}];
}

if (!await client.init()) {
throw new Error("Error while initialize process.");
}
for (let account of accounts) {
let client = new EpicGames(account);

if (!await client.login().catch(() => false)) {
console.log(`Failed to login as ${client.config.email}, please attempt manually.`);
let auth = await ClientLoginAdapter.init(credentials);
let exchangeCode = await auth.getExchangeCode();
await auth.close();
if (!await client.init()) {
throw new Error("Error while initialize process.");
}

if (!await client.login(null, exchangeCode)) {
throw new Error("Error while logging in.");
}
if (!await client.login().catch(() => false)) {
console.log(`Failed to login as ${client.config.email}, please attempt manually.`);
let auth = await ClientLoginAdapter.init(account);
let exchangeCode = await auth.getExchangeCode();
await auth.close();

if (!await client.login(null, exchangeCode)) {
throw new Error("Error while logging in.");
}
}

console.log(`Logged in as ${client.account.name} (${client.account.id})`);
let getAllOffers = async(namespace, pagesize = 100) => {
let i = 0;
let results = [];
while ((i * pagesize) - results.length === 0) {
let { elements } = await client.getOffersForNamespace(namespace, pagesize, pagesize * i++);
results = results.concat(elements);
}
return results;
};
console.log(`Logged in as ${client.account.name} (${client.account.id})`);
let getAllOffers = async(namespace, pagesize = 100) => {
let i = 0;
let results = [];
while ((i * pagesize) - results.length === 0) {
let { elements } = await client.getOffersForNamespace(namespace, pagesize, pagesize * i++);
results = results.concat(elements);
}
return results;
};

let all = await getAllOffers("epic");
let freegames = all
.filter(game => game.categories.find(cat => cat.path === "freegames")
let all = await getAllOffers("epic");
let freegames = all
.filter(game => game.categories.find(cat => cat.path === "freegames")
&& game.customAttributes["com.epicgames.app.offerNs"].value)
.map(game => game.customAttributes["com.epicgames.app.offerNs"].value);
.map(game => game.customAttributes["com.epicgames.app.offerNs"].value);

for (let namespace of freegames) {
let offers = await getAllOffers(namespace);
let freeoffers = offers.filter(game => game.currentPrice === 0 && game.discountPercentage === 0);
for (let namespace of freegames) {
let offers = await getAllOffers(namespace);
let freeoffers = offers.filter(game => game.currentPrice === 0 && game.discountPercentage === 0);

for (let offer of freeoffers) {
let purchased = await client.purchase(offer, 1);
for (let offer of freeoffers) {
let purchased = await client.purchase(offer, 1);

if (purchased) {
console.log(`Successfully claimed ${offer.title} (${purchased})`);
} else {
console.log(`${offer.title} was already claimed for this account`);
}
if (purchased) {
console.log(`Successfully claimed ${offer.title} (${purchased})`);
} else {
console.log(`${offer.title} was already claimed for this account`);
}
}
}

await client.logout();
console.log(`Logged ${client.account.name} out of Epic Games`);

await client.logout();
console.log(`Logged out of Epic Games (account ${client.account.name})`);
console.log(`Wait ${config.delay} seconds`);
await sleep(config.delay);
if (loop) {
console.log(`Waiting ${delay} minutes`);
await sleep(delay);
} else {
process.exit(0);
}
} catch (e) {
console.error(e);
console.log(`Wait ${config.delay} seconds`);
await sleep(config.delay);
}
process.exit(0);
}
while (config.loop);
} while (loop);
})().catch(err => {
console.error(err);
process.exit(-1);
process.exit(1);
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "epicgames-freebies-claimer",
"version": "1.2.1",
"version": "1.2.2",
"description": "Claim free game promotions from the Epic Game Store",
"author": "Revadike <https://revadike.ga>",
"main": "gimme_free_epic_shit.js",
Expand Down

0 comments on commit 8033179

Please sign in to comment.