Skip to content

Commit

Permalink
Fixed styling and typos
Browse files Browse the repository at this point in the history
  • Loading branch information
Revadike committed Feb 10, 2020
1 parent 3f085ad commit c4d4808
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Claim [available free game promotions](https://www.epicgames.com/store/free-game
V1.1.1
* Ensured all search results for all namespaces are purchased


V1.1.0
* Added support for email/password arguments
* Moved saved credentials to config.json
Expand Down
28 changes: 13 additions & 15 deletions gimme_free_epic_shit.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,38 @@
const { Launcher } = require(`epicgames-client`);
const { Launcher: EpicGames } = require(`epicgames-client`);
const { email, password } = require(`${__dirname}/config.json`);
const epicClient = new Launcher({
const client = new EpicGames({
email: process.argv[2] || email,
password: process.argv[3] || password
});

(async () => {
if (!await epicClient.init() || !await epicClient.login()) {
throw new Error(`Error while initialize or login process as ${epicClient.config.email}`);
if (!await client.init() || !await client.login()) {
throw new Error(`Error while initializing or logging in as ${client.config.email}`);
}

console.log(`Logged in as ${epicLauncher.account.name} (${epicLauncher.account.id})`);

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 epicClient.getOffersForNamespace(namespace, pagesize, pagesize * i++);
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`) &&
game.customAttributes[`com.epicgames.app.offerNs`].value)
.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);

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

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

if (purchased) {
console.log(`Successfully claimed ${offer.title} (${purchased})`);
Expand All @@ -44,8 +42,8 @@ const epicClient = new Launcher({
}
}

await epicClient.logout();
console.log(`Script finished!`);
await client.logout();
console.log(`Logged out of Epic Games`);
process.exit(0);

})().catch(err => {
Expand Down

0 comments on commit c4d4808

Please sign in to comment.