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

SoftBan Worker #1724

Merged
merged 5 commits into from
Jul 29, 2016
Merged
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
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@douglascamata , I am not sure this works. It's better be self.bot.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
Copy link
Contributor

@elicwhite elicwhite Jul 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure, the intent here is to continue to the next worker if it can't find a fort?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because we need to walk randomly until we can find a fort to walk to.

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
Copy link

@wilsonyqm wilsonyqm Jul 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This too. #1724 (comment)

logger.log('Softban should be fixed.')

def spin_fort(self, fort):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could get pulled out. Seems like there are a couple of places that would be able to use this function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely we should start service classes to wrap some API functions. I created #1726 for us to keep track of this.

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