diff --git a/README.md b/README.md index 12dabcc..91f02b6 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ Data is stored in the volume `fgc`. 1. [Install Node.js](https://nodejs.org/en/download) 2. Clone/download this repository and `cd` into it in a terminal 3. Run `npm install && npx playwright install firefox` +4. Run `pip install apprise` to install [apprise](https://github.com/caronc/apprise) if you want notifications This downloads Firefox to a cache in home ([doc](https://playwright.dev/docs/browsers#managing-browser-binaries)). If you are missing some dependencies for the browser on your system, you can use `sudo npx playwright install firefox --with-deps`. @@ -63,16 +64,17 @@ Available options/variables and their default values: | WIDTH | 1280 | Width of the opened browser (and screen vor VNC in Docker). | | HEIGHT | 1280 | Height of the opened browser (and screen vor VNC in Docker). | | VNC_PASSWORD | | VNC password for Docker. No password used by default! | +| NOTIFY | | Notification services to use (Pushover, Slack, Telegram...), see below. | | EMAIL | | Default email for any login. | | PASSWORD | | Default password for any login. | | EG_EMAIL | | Epic Games email for login. Overrides EMAIL. | | EG_PASSWORD | | Epic Games password for login. Overrides PASSWORD. | -| EG_OTPKEY | | Epic Games MFA OTP key. | +| EG_OTPKEY | | Epic Games MFA OTP key. | | PG_EMAIL | | Prime Gaming email for login. Overrides EMAIL. | | PG_PASSWORD | | Prime Gaming password for login. Overrides PASSWORD. | -| PG_OTPKEY | | Prime Gaming MFA OTP key. | -| GOG_EMAIL | | GOG email for login. Overrides EMAIL. | -| GOG_PASSWORD | | GOG password for login. Overrides PASSWORD. | +| PG_OTPKEY | | Prime Gaming MFA OTP key. | +| GOG_EMAIL | | GOG email for login. Overrides EMAIL. | +| GOG_PASSWORD | | GOG password for login. Overrides PASSWORD. | See `config.js` for all options. @@ -80,6 +82,12 @@ See `config.js` for all options. On Linux/macOS you can prefix the variables you want to set, for example `EMAIL=foo@bar.baz SHOW=1 node epic-games` will show the browser and skip asking you for your login email. For Docker you can pass variables using `-e VAR=VAL`, for example `docker run -e EMAIL=foo@bar.baz ...` or using `--env-file` (see [docs](https://docs.docker.com/engine/reference/commandline/run/#set-environment-variables--e---env---env-file)). If you are using [docker compose](https://docs.docker.com/compose/environment-variables/), you can put them in the `environment:` section. +### Notifications +The scripts will try to send notifications for successfully claimed games and any errors like needing to log in or encountered captchas (should not happen). + +[apprise](https://github.com/caronc/apprise) is used for notifications and offers many services including Pushover, Slack, Telegram, SMS, Email, desktop and custom notifications. +You just need to set `NOTIFY` to the notifications services you want to use, e.g. `NOTIFY='mailto://myemail:mypass@gmail.com' 'pbul://o.gn5kj6nfhv736I7jC3cj3QLRiyhgl98b'` - refer to their list of services and [examples](https://github.com/caronc/apprise#command-line-usage). + ### Automatic login, two-factor authentication If you set the options for email, password and OTP key, there will be no prompts and logins should happen automatically. This is optional since all stores should stay logged in since cookies are refreshed. To get the OTP key, it is easiest to follow the store's guide for adding an authenticator app. You should also scan the shown QR code with your favorite app to have an alternative method for 2FA. @@ -160,12 +168,12 @@ v1.0 Standalone scripts node epic-games and node prime-gaming using Chromium. Changed to Firefox for all scripts since Chromium led to captchas. Claiming then also worked in headless mode without Docker. Added options via env vars, configurable in `data/config.env`. - + Added OTP generation via otplib for automatic login, even with 2FA. --- -Logo with smaller aspect ratio (for Telegram bot etc.): +Logo with smaller aspect ratio (for Telegram bot etc.): 👾 - [emojipedia](https://emojipedia.org/alien-monster/) ![logo-fgc](https://user-images.githubusercontent.com/493741/214589922-093d6557-6393-421c-b577-da58ff3671bc.png) diff --git a/config.js b/config.js index f60b23e..726e6bd 100644 --- a/config.js +++ b/config.js @@ -11,6 +11,7 @@ export const cfg = { height: Number(process.env.HEIGHT) || 1280, // height of the opened browser timeout: (Number(process.env.TIMEOUT) || 20) * 1000, // 20s, default for playwright is 30s novnc_port: process.env.NOVNC_PORT, // running in docker if set + notify: process.env.NOTIFY, // apprise notification services // auth epic-games eg_email: process.env.EG_EMAIL || process.env.EMAIL, eg_password: process.env.EG_PASSWORD || process.env.PASSWORD, diff --git a/util.js b/util.js index a14bb1d..fb86c12 100644 --- a/util.js +++ b/util.js @@ -76,3 +76,22 @@ export const stealth = async (context) => { await context.addInitScript(evasion.cb, evasion.a); } }; + +// notifications via apprise CLI +import { exec } from 'child_process'; +import { cfg } from './config.js'; + +export const notify = (html) => { + if (!cfg.notify) return; + exec(`apprise ${cfg.notify} -i html -b '${html}'`, (error, stdout, stderr) => { + if (error) { + console.log(`error: ${error.message}`); + if (error.message.includes('command not found')) { + console.info('Run `pip install apprise`. See https://github.com/vogler/free-games-claimer#notifications'); + } + return; + } + if (stderr) console.error(`stderr: ${stderr}`); + if (stdout) console.log(`stdout: ${stdout}`); + }); +}