Skip to content

Commit

Permalink
V1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Revadike committed Apr 26, 2020
1 parent 51b3386 commit 21480c4
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 9 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"no-caller": "error",
"no-case-declarations": "error",
"no-confusing-arrow": "error",
"no-console": "error",
"no-constructor-return": "error",
"no-dupe-else-if": "error",
"no-duplicate-imports": "error",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ No, these are only usable by using the config.
## Changelog
### V1.3.0
* Changed method of obtaining free games list (Closes #13)
* Added better logger (Closes #14)

### V1.2.3
* Small bugfix
Expand Down
17 changes: 9 additions & 8 deletions gimme_free_epic_shit.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
const Config = require(`${__dirname}/config.json`);
const Logger = require("tracer").console(`${__dirname}/logger.js`);
const ClientLoginAdapter = require("epicgames-client-login-adapter");
const { "Launcher": EpicGames } = require("epicgames-client");
const PROMO_QUERY = `query searchStoreQuery($category: String, $locale: String, $start: Int) {
Expand Down Expand Up @@ -47,7 +48,7 @@ const PROMO_QUERY = `query searchStoreQuery($category: String, $locale: String,
}

if (!await client.login().catch(() => false)) {
console.log(`Failed to login as ${client.config.email}, please attempt manually.`);
Logger.warn(`Failed to login as ${client.config.email}, please attempt manually.`);
let auth = await ClientLoginAdapter.init(account);
let exchangeCode = await auth.getExchangeCode();
await auth.close();
Expand All @@ -57,7 +58,7 @@ const PROMO_QUERY = `query searchStoreQuery($category: String, $locale: String,
}
}

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

let { data } = await client.http.sendGraphQL(null, PROMO_QUERY, { "category": "freegames", "locale": "en-US" });
let { elements } = JSON.parse(data).data.Catalog.searchStore;
Expand All @@ -69,27 +70,27 @@ const PROMO_QUERY = `query searchStoreQuery($category: String, $locale: String,
try {
let purchased = await client.purchase(offer, 1);
if (purchased) {
console.log(`Successfully claimed ${offer.title} (${purchased})`);
Logger.info(`Successfully claimed ${offer.title} (${purchased})`);
} else {
console.log(`${offer.title} was already claimed for this account`);
Logger.info(`${offer.title} was already claimed for this account`);
}
} catch (err) {
console.log(`Failed to claim ${offer.title} (${err})`);
Logger.warn(`Failed to claim ${offer.title} (${err})`);
}
}

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

if (loop) {
console.log(`Waiting ${delay} minutes`);
Logger.info(`Waiting ${delay} minutes`);
await sleep(delay);
} else {
process.exit(0);
}
} while (loop);
})().catch(err => {
console.error(err);
Logger.error(err);
process.exit(1);
});
42 changes: 42 additions & 0 deletions logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"use strict";
const colors = require("colors");
const fs = require("fs");
const path = require("path");

module.exports = {
"format": " {{timestamp}} | {{title}} | {{message}}",
"dateformat": "yyyy-mm-dd | HH:MM:ss.l",
"filters": {
"log": colors.white,
"trace": colors.magenta,
"debug": colors.blue,
"info": colors.green,
"warn": colors.magenta,
"error": [colors.red, colors.bold]
},
"preprocess": data => {
data.title = data.title.toUpperCase();
while (data.title.length < 5) { data.title += " "; }
data.args = [...data.args];
if (data.args[0] && data.args[0].logpath) {
data.logpath = data.args[0].logpath;
data.args.shift();
}
},
"transport": data => {
// eslint-disable-next-line no-console
console.log(data.output);
if (data.level === 4) {
return;
}

const streamoptions = {
"flags": "a",
"encoding": "utf8"
};
fs.createWriteStream(path.join(__dirname, "log.txt"), streamoptions).write(`\r\n${data.rawoutput}`);
if (data.logpath) {
fs.createWriteStream(data.logpath, streamoptions).write(`\r\n${data.rawoutput}`);
}
}
};
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"eslint": "^6.8.0"
},
"dependencies": {
"colors": "^1.4.0",
"epicgames-client": "^2.0.23",
"epicgames-client-login-adapter": "^0.1.0"
"epicgames-client-login-adapter": "^0.1.0",
"tracer": "^1.0.3"
}
}

0 comments on commit 21480c4

Please sign in to comment.