Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #24

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion betty/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async def get_owned_ids(self):

async def get_game_details(self, business_id):
headers = {
'Authorization': f"Bearer 26a7d8bae3b004c1847e14418567d527e337c97440ac52113306ac6861036590",
'Authorization': f"Bearer OUFuRGfR35XVY7LML-7ITHALa_oiRoTAwQxFTrGMgz8",
'Content-Type': "application/json"
}
resp = await self.http_client.do_request('get', f"https://cdn.contentful.com/spaces/rporu91m20dc/environments/master/entries?skip=0&order=&include=3&content_type=productCode&locale=en&limit=100&fields.entitlementBusinessId={business_id}", headers=headers)
Expand Down
33 changes: 24 additions & 9 deletions betty/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
AUTH_START_URL = r"https://bethesda.net/en/dashboard?cogs_modal=login"
AUTH_FINISH_URL = r"cogs_modal"
AUTH_REDIRECT_URL = r"radiant/v1/graphql"
AUTH_CHECK_URL = r"https://api.bethesda.net/dwemer/attunement/v1/authenticate"
API_URL = r"https://api.bethesda.net"

BETTY_WINREG_LOCATION = "SOFTWARE\\Bethesda Softworks\\Bethesda.net"
BETTY_LAUNCHER_EXE = "BethesdaNetLauncher.exe"
Expand All @@ -25,19 +27,32 @@ def regex_pattern(regex):
JS = {
regex_pattern(AUTH_FINISH_URL): [
r'''
function getCookie(name) {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop().split(';').shift();
function checkLogin() {
makeLoginRequest(() => { location.href = '%s'; })
}

function check_login() {
if (getCookie('bnet-username')) {
location.href = '%s';
function makeLoginRequest(callback) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE && xhr.status >= 200 && xhr.status < 300) {
callback();
}
}
xhr.open('PUT', '%s', true);
xhr.withCredentials = true;
xhr.send(null);
}

setInterval(check_login, 3000);
// Catch all requests and check if auth is successful after any API request
var origOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function() {
this.addEventListener('load', async function() {
if (this.responseURL.indexOf('%s') >= 0) {
checkLogin();
}
});
origOpen.apply(this, arguments);
};

function findpersist() {
if (document.getElementsByName("persist").length < 1) {
Expand All @@ -47,6 +62,6 @@ def regex_pattern(regex):
}
}
findpersist();
''' % AUTH_REDIRECT_URL
''' % (AUTH_REDIRECT_URL, AUTH_CHECK_URL, API_URL)
]
}
2 changes: 1 addition & 1 deletion betty/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Galaxy Bethesda plugin",
"platform": "bethesda",
"guid": "cb57391f-1675-35b1-05c0-896d43bdf4f8",
"version": "0.185",
"version": "0.186",
"description": "Galaxy Bethesda plugin",
"author": "TouwaStar",
"email": "[email protected]",
Expand Down
6 changes: 5 additions & 1 deletion betty/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ async def get_owned_games(self):
product_ids = self._check_for_owned_products(owned_ids)
pre_order_ids = set(owned_ids) - set(product_ids)

games_to_send.extend(await self._get_owned_pre_orders(pre_order_ids))
try:
games_to_send.extend(await self._get_owned_pre_orders(pre_order_ids))
except Exception as e:
log.warning(f"Unable to obtain preorders: {repr(e)}")

games_to_send.extend(self._get_owned_games())

log.info(f"Games to send (with free games): {games_to_send}")
Expand Down