Skip to content

Commit

Permalink
Detect and alert for permaban (#3944)
Browse files Browse the repository at this point in the history
  • Loading branch information
net8q authored and elicwhite committed Aug 14, 2016
1 parent df97a04 commit fd9d7e3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@
* extink
* Quantra
* pmquan
* net8q
8 changes: 8 additions & 0 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions pokemongo_bot/api_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

from human_behaviour import sleep

class PermaBannedException(Exception):
pass

class ApiWrapper(PGoApi):
def __init__(self):
PGoApi.__init__(self)
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit fd9d7e3

Please sign in to comment.