Skip to content

Commit

Permalink
SoftBan Worker (#1724)
Browse files Browse the repository at this point in the history
* created a softban worker

* only delete key from dict if it is there

* pep8 stuff
  • Loading branch information
douglascamata authored Jul 29, 2016
1 parent f196118 commit b9aff7a
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 11 deletions.
9 changes: 9 additions & 0 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,15 @@ def init_config():
type=float,
default=15.0
)
add_config(
parser,
load,
short_flag="-bf",
long_flag="--softban_fix",
help="Fix softban automatically",
type=bool,
default=False
)
add_config(
parser,
load,
Expand Down
2 changes: 2 additions & 0 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
class PokemonGoBot(object):

WORKERS = [
cell_workers.SoftBanWorker,
cell_workers.IncubateEggsWorker,
cell_workers.PokemonTransferWorker,
cell_workers.EvolveAllWorker,
Expand All @@ -54,6 +55,7 @@ def __init__(self, config):
self.cell = None
self.recent_forts = [None] * config.forts_max_circle_size
self.tick_count = 0
self.softban = False

# Make our own copy of the workers for this instance
self.workers = list(self.WORKERS)
Expand Down
1 change: 1 addition & 0 deletions pokemongo_bot/cell_workers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
from pokemon_transfer_worker import PokemonTransferWorker
from recycle_items_worker import RecycleItemsWorker
from seen_fort_worker import SeenFortWorker
from soft_ban_worker import SoftBanWorker
4 changes: 4 additions & 0 deletions pokemongo_bot/cell_workers/pokemon_catch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def work(self):
else:
if response_dict['status_code'] is 1:
logger.log('Fail to use berry. Seem like you are softbanned.', 'red')
self.bot.softban = True
else:
logger.log(
'Fail to use berry. Status Code: {}'.format(response_dict['status_code']),
Expand Down Expand Up @@ -185,6 +186,8 @@ def work(self):
if status is 3:
logger.log(
'Oh no! {} vanished! :('.format(pokemon_name), 'red')
if success_percentage == 100:
self.softban = True
if status is 1:
self.bot.metrics.captured_pokemon(pokemon_name, cp, iv_display, pokemon_potential)

Expand All @@ -195,6 +198,7 @@ def work(self):
iv_display,
sum(response_dict['responses']['CATCH_POKEMON']['capture_award']['xp'])
), 'blue')
self.bot.softban = False

if (self.config.evolve_captured
and (self.config.evolve_captured[0] == 'all'
Expand Down
17 changes: 6 additions & 11 deletions pokemongo_bot/cell_workers/seen_fort_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def work(self):
spin_details = response_dict['responses']['FORT_SEARCH']
spin_result = spin_details.get('result', -1)
if spin_result == 1:
self.bot.softban = False
logger.log("Loot: ", 'green')
experience_awarded = spin_details.get('experience_awarded',
False)
Expand Down Expand Up @@ -82,16 +83,6 @@ def work(self):
format_time((pokestop_cooldown / 1000) -
seconds_since_epoch)))

if not items_awarded and not experience_awarded and not pokestop_cooldown:
message = (
'Stopped at Pokestop and did not find experience, items '
'or information about the stop cooldown. You are '
'probably softbanned. Try to play on your phone, '
'if pokemons always ran away and you find nothing in '
'PokeStops you are indeed softbanned. Please try again '
'in a few hours.')
raise RuntimeError(message)

self.bot.recent_forts = self.bot.recent_forts[1:] + [fort['id']]
elif spin_result == 2:
logger.log("[#] Pokestop out of range")
Expand All @@ -116,7 +107,11 @@ def work(self):
'chain_hack_sequence_number']
else:
logger.log('Possibly searching too often - taking a short rest :)', 'yellow')
self.bot.fort_timeouts[fort["id"]] = (time.time() + 300) * 1000 # Don't spin for 5m
if spin_result == 1 and not items_awarded and not experience_awarded and not pokestop_cooldown:
self.bot.softban = True
logger.log('[!] Possibly got softban too...', 'red')
else:
self.bot.fort_timeouts[fort["id"]] = (time.time() + 300) * 1000 # Don't spin for 5m
return 11
sleep(2)
return 0
Expand Down
61 changes: 61 additions & 0 deletions pokemongo_bot/cell_workers/soft_ban_worker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from pgoapi.utilities import f2i

from pokemongo_bot import logger
from pokemongo_bot.constants import Constants
from pokemongo_bot.cell_workers import MoveToFortWorker, SeenFortWorker
from pokemongo_bot.cell_workers.utils import distance
from pokemongo_bot.worker_result import WorkerResult


class SoftBanWorker(object):

def __init__(self, bot):
self.bot = bot
self.api = bot.api
self.config = bot.config

def work(self):
if not self.should_run():
return

forts = self.bot.get_forts(order_by_distance=True)

if len(forts) == 0:
logger.log('Found no forts to reset softban, skipping...', 'red')
return
logger.log('Got softban, fixing...', 'yellow')

fort_distance = distance(
self.bot.position[0],
self.bot.position[1],
forts[0]['latitude'],
forts[0]['longitude'],
)

if fort_distance > Constants.MAX_DISTANCE_FORT_IS_REACHABLE:
MoveToFortWorker(self.bot).work()
self.bot.recent_forts = self.bot.recent_forts[0:-1]
if forts[0]['id'] in self.bot.fort_timeouts:
del self.bot.fort_timeouts[forts[0]['id']]
return WorkerResult.RUNNING
else:
logger.log('Starting 50 spins...')
for i in xrange(50):
if (i + 1) % 10 == 0:
logger.log('Spin #{}'.format(str(i+1)))
self.spin_fort(forts[0])
self.softban = False
logger.log('Softban should be fixed.')

def spin_fort(self, fort):
self.api.fort_search(
fort_id=fort['id'],
fort_latitude=fort['latitude'],
fort_longitude=fort['longitude'],
player_latitude=f2i(self.bot.position[0]),
player_longitude=f2i(self.bot.position[1])
)
self.api.call()

def should_run(self):
return self.bot.config.softban_fix and self.bot.softban

0 comments on commit b9aff7a

Please sign in to comment.