From c467da38188ea1d920eaa6a2c0dd076e1370040a Mon Sep 17 00:00:00 2001 From: net8q Date: Sun, 14 Aug 2016 19:43:16 +0200 Subject: [PATCH] Detect and alert for permaban --- CONTRIBUTORS.md | 1 + pokecli.py | 8 ++++++++ pokemongo_bot/api_wrapper.py | 11 +++++++++++ 3 files changed, 20 insertions(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index c363f3d804..33aee29d31 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -69,3 +69,4 @@ * extink * Quantra * pmquan + * net8q diff --git a/pokecli.py b/pokecli.py index 064c87c9ba..4ab48fc34c 100644 --- a/pokecli.py +++ b/pokecli.py @@ -43,6 +43,7 @@ from pokemongo_bot.base_dir import _base_dir from pokemongo_bot.health_record import BotEvent from pokemongo_bot.plugin_loader import PluginLoader +from pokemongo_bot.api_wrapper import PermaBannedException try: from demjson import jsonlint @@ -137,6 +138,13 @@ def handle_sigint(*args): ) time.sleep(30) + except PermaBannedException: + bot.event_manager.emit( + 'api_error', + sender=bot, + level='info', + formatted='Probably permabanned, Game Over ! Play again at https://club.pokemon.com/us/pokemon-trainer-club/sign-up/' + ) except GeocoderQuotaExceeded: raise Exception("Google Maps API key over requests limit.") except Exception as e: diff --git a/pokemongo_bot/api_wrapper.py b/pokemongo_bot/api_wrapper.py index 7224b0b4e4..2c51f32ff2 100644 --- a/pokemongo_bot/api_wrapper.py +++ b/pokemongo_bot/api_wrapper.py @@ -10,6 +10,9 @@ from human_behaviour import sleep +class PermaBannedException(Exception): + pass + class ApiWrapper(PGoApi): def __init__(self): PGoApi.__init__(self) @@ -77,6 +80,14 @@ def is_response_valid(self, result, request_callers): if not isinstance(result['responses'], dict): return False + try: + # Permaban symptom is empty response to GET_INVENTORY and status_code = 3 + if result['status_code'] == 3 and 'GET_INVENTORY' in request_callers and not result['responses']['GET_INVENTORY']: + raise PermaBannedException + except KeyError: + # Still wrong + return False + # the response can still programatically be valid at this point # but still be wrong. we need to check if the server did sent what we asked it for request_caller in request_callers: