Skip to content

Commit

Permalink
Updated Wago Addons support
Browse files Browse the repository at this point in the history
  • Loading branch information
AcidWeb committed Jul 5, 2022
1 parent cca23b1 commit a76996d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 48 deletions.
43 changes: 18 additions & 25 deletions CB/Core.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,12 +505,8 @@ def search(self, query):
payload = requests.get(f'https://addons.wago.io/api/external/addons/_search?query={quote_plus(query.strip())}'
f'&game_version={self.clientType}', headers=HEADERS,
auth=APIAuth('Bearer', self.config['WAAAPIKey']), timeout=5)
if payload.status_code == 401:
raise RuntimeError('Wago Addons API key is missing or incorrect.')
elif payload.status_code == 403:
raise RuntimeError('Provided Wago Addons API key is expired. Please acquire a new one.')
else:
payload = payload.json()
self.parse_wagoaddons_error(payload.status_code)
payload = payload.json()
for result in payload['data']:
results.append(result['website_url'])
return results
Expand All @@ -537,18 +533,13 @@ def create_reg(self):
'[HKEY_CURRENT_USER\Software\Classes\weakauras-companion\shell\open\command]\n'
'@="\\"' + os.path.abspath(sys.executable).replace('\\', '\\\\') + '\\" \\"%1\\""')

@retry(custom_error='Failed to parse the URI.')
def parse_wagoapp_payload(self, url):
projectid = url.replace('wago-app://addons/', '')
payload = requests.get(f'https://addons.wago.io/api/external/addons/{projectid}?game_version='
f'{self.clientType}', headers=HEADERS,
auth=APIAuth('Bearer', self.config['WAAAPIKey']), timeout=5)
if payload.status_code == 401:
raise RuntimeError('Wago Addons API key is missing or incorrect.')
elif payload.status_code == 403:
raise RuntimeError('Provided Wago Addons API key is expired. Please acquire a new one.')
else:
payload = payload.json()
self.parse_wagoaddons_error(payload.status_code)
payload = payload.json()
return f'https://addons.wago.io/addons/{payload["slug"]}'

@retry()
Expand All @@ -572,12 +563,8 @@ def bulk_check(self, addons):
# payload = requests.post(f'https://addons.wago.io/api/external/addons/_recents?game_version='
# f'{self.clientType}', json={'addons': ids_wago}, headers=HEADERS,
# auth=APIAuth('Bearer', self.config['WAAAPIKey']), timeout=5)
# if payload.status_code == 401:
# raise RuntimeError('Wago Addons API key is missing or incorrect.')
# elif payload.status_code == 403:
# raise RuntimeError('Provided Wago Addons API key is expired. Please acquire a new one.')
# else:
# payload = payload.json()
# self.parse_wagoaddons_error(payload.status_code)
# payload = payload.json()
# for addon in payload['addons']:
# self.wagoCache[addon] = payload['addons'][addon]

Expand Down Expand Up @@ -626,12 +613,8 @@ def detect_addons(self):
payload = requests.post(f'https://addons.wago.io/api/external/addons/_match?game_version='
f'{self.clientType}', json={'addons': output}, headers=HEADERS,
auth=APIAuth('Bearer', self.config['WAAAPIKey']), timeout=5)
if payload.status_code == 401:
raise RuntimeError('Wago Addons API key is missing or incorrect.')
elif payload.status_code == 403:
raise RuntimeError('Provided Wago Addons API key is expired. Please acquire a new one.')
else:
payload = payload.json()
self.parse_wagoaddons_error(payload.status_code)
payload = payload.json()
for addon in payload['addons']:
if self.check_if_installed(addon['website_url']):
namesinstalled.append(addon['name'])
Expand Down Expand Up @@ -671,6 +654,16 @@ def export_addons(self):
addons.append(url)
return f'install {",".join(sorted(addons))}'

def parse_wagoaddons_error(self, code):
if code == 401:
raise RuntimeError('Wago Addons API key is missing or incorrect.')
elif code == 403:
raise RuntimeError('Provided Wago Addons API key is expired. Please acquire a new one.')
elif code == 423:
raise RuntimeError('Provided Wago Addons API key is blocked. Please acquire a new one.')
elif code == 429 or code == 500:
raise RuntimeError('Temporary Wago Addons API issue. Please try later.')


class WagoAddonsHasher:
def __init__(self, directory):
Expand Down
4 changes: 3 additions & 1 deletion CB/WagoAddons.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def __init__(self, url, checkcache, clienttype, allowdev, apikey):
raise RuntimeError(f'{url}\nWago Addons API key is missing or incorrect.')
elif self.payload.status_code == 403:
raise RuntimeError(f'{url}\nProvided Wago Addons API key is expired. Please acquire a new one.')
elif self.payload.status_code == 404 or self.payload.status_code == 500:
elif self.payload.status_code == 423:
raise RuntimeError(f'{url}\nProvided Wago Addons API key is blocked. Please acquire a new one.')
elif self.payload.status_code == 404 or self.payload.status_code == 429 or self.payload.status_code == 500:
raise RuntimeError(f'{url}\nThis might be a temporary issue with Wago Addons API or the project was '
f'removed/renamed. In this case, uninstall it (and reinstall if it still exists) '
f'to fix this issue.')
Expand Down
8 changes: 4 additions & 4 deletions CurseBreaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def start(self):
'tion.\n')
if len(self.core.config['Addons']) == 0:
self.console.print('To enable Wago Addons support API key needs to be provided.\nIt can be obtained here: ['
'link=https://www.patreon.com/wagoio]https://www.patreon.com/wagoio[/link]\nAfter that i'
'link=https://addons.wago.io/patreon]https://addons.wago.io/patreon[/link]\nAfter that i'
't needs to added to application configuration by using [green]set wago_addons_api[/gree'
'n] command.\nCommand [green]import[/green] might be used to detect already installed ad'
'dons.')
Expand Down Expand Up @@ -768,7 +768,7 @@ def c_set(self, args):
else:
self.console.print('[green]Usage:[/green]\n\t[green]set wago_addons_api [API key][/green]\n\t\tSets Wago Ad'
'dons API key required to use Wago Addons as addon source.\n\t\tIt can be obtained here:'
' [link=https://www.patreon.com/wagoio]https://www.patreon.com/wagoio[/link]\n\t[green]s'
' [link=https://addons.wago.io/patreon]https://addons.wago.io/patreon[/link]\n\t[green]s'
'et wago_api [API key][/green]\n\t\tSets Wago API key required to access private entries'
'.\n\t\tIt can be obtained here: [link=https://wago.io/account]https://wago.io/account[/'
'link]\n\t[green]set wago_wow_account [Account name][/green]\n\t\tSets WoW account used '
Expand Down Expand Up @@ -916,8 +916,8 @@ def c_help(self, _):
'[green]toggle wago [Username][/green]\n\tEnables/disables automatic Wago updates.\n\tIf a u'
'sername is provided check will start to ignore the specified author.\n'
'[green]set wago_addons_api [API key][/green]\n\tSets Wago Addons API key required to use Wa'
'go Addons as addon source.\n\tIt can be obtained here: [link=https://www.patreon.com/wagoio'
']https://www.patreon.com/wagoio[/link]\n'
'go Addons as addon source.\n\tIt can be obtained here: [link=https://addons.wago.io/patreon'
']https://addons.wago.io/patreon[/link]\n'
'[green]set wago_api [API key][/green]\n\tSets Wago API key required to access private entri'
'es.\n\tIt can be obtained here: [link=https://wago.io/account]https://wago.io/account[/link'
']\n'
Expand Down
34 changes: 17 additions & 17 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ By default **CurseBreaker** will create backups of the entire `WTF` directory.

## WAGO ADDONS SUPPORT
To use Wago Addons as addon source user needs to provide a personal API key.\
The key can be obtained [here](https://www.patreon.com/wagoio) and needs to be added to the application configuration by using `set wago_addons_api` command.
The key can be obtained [here](https://addons.wago.io/patreon) and needs to be added to the application configuration by using `set wago_addons_api` command.

## WEAKAURAS SUPPORT
**CurseBreaker** by default will try to update all detected WeakAuras and Plater profiles/scripts. Process work the same as WeakAuras Companion.\
Expand Down

0 comments on commit a76996d

Please sign in to comment.