Skip to content

Commit

Permalink
Merge pull request #5785 from PokemonGoF/dev
Browse files Browse the repository at this point in the history
Dev merge to master PR
  • Loading branch information
solderzzc authored Nov 7, 2016
2 parents fc27b42 + 227f798 commit 7a56de0
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 35 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# PokemonGo-Bot
[PokemonGo-Bot](https://github.com/PokemonGoF/PokemonGo-Bot) is a project created by the [PokemonGoF](https://github.com/PokemonGoF) team.

## Is the bot working? [New API basic support](https://github.com/PokemonGoF/PokemonGo-Bot/pull/5784)
## Is the bot working? [Yes, since this PR](https://github.com/PokemonGoF/PokemonGo-Bot/pull/5784)

## Table of Contents
- [Installation](https://github.com/PokemonGoF/PokemonGo-Bot/blob/dev/docs/installation.md)
Expand Down Expand Up @@ -75,7 +75,7 @@ If you do not want any data to be gathered, you can turn off this feature by set

## Credits
- [tejado](https://github.com/tejado) many thanks for the API
- [U6 Group](http://pgoapi.com) for the U6
- [pogodevorg](https://github.com/pogodevorg/pgoapi) Without keyphact's coordination, this would not gonna happan again.
- [Mila432](https://github.com/Mila432/Pokemon_Go_API) for the login secrets
- [elliottcarlson](https://github.com/elliottcarlson) for the Google Auth PR
- [AeonLucid](https://github.com/AeonLucid/POGOProtos) for improved protos
Expand Down
1 change: 1 addition & 0 deletions configs/config.json.cluster.example
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"best_in_family": true,
"// candy_limit = 0 means no limit, so it will never change current buddy": {},
"candy_limit": 0,
"candy_limit_absolute":0,
"// force_first_change = true will always change buddy at start removing current one": {},
"force_first_change": false,
"buddy_change_wait_min": 3,
Expand Down
3 changes: 2 additions & 1 deletion configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"best_in_family": true,
"// candy_limit = 0 means no limit, so it will never change current buddy": {},
"candy_limit": 0,
"candy_limit_absolute":0,
"// force_first_change = true will always change buddy at start removing current one": {},
"force_first_change": false,
"buddy_change_wait_min": 3,
Expand Down Expand Up @@ -253,7 +254,7 @@
"name": { "param": "pokemon" },
"latitude": { "param": "cords" },
"longitude": { "param": "cords" },
"expiration": { "param": "timeend", "format": "milliseconds" }
"expiration": { "param": "timeend", "format": "seconds" }
}
},
{
Expand Down
3 changes: 2 additions & 1 deletion configs/config.json.map.example
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"best_in_family": true,
"// candy_limit = 0 means no limit, so it will never change current buddy": {},
"candy_limit": 0,
"candy_limit_absolute":0,
"// force_first_change = true will always change buddy at start removing current one": {},
"force_first_change": false,
"buddy_change_wait_min": 3,
Expand Down Expand Up @@ -506,7 +507,7 @@
"name": { "param": "pokemon" },
"latitude": { "param": "cords" },
"longitude": { "param": "cords" },
"expiration": { "param": "timeend", "format": "milliseconds" }
"expiration": { "param": "timeend", "format": "seconds" }
}
},
{
Expand Down
1 change: 1 addition & 0 deletions configs/config.json.path.example
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"best_in_family": true,
"// candy_limit = 0 means no limit, so it will never change current buddy": {},
"candy_limit": 0,
"candy_limit_absolute":0,
"// force_first_change = true will always change buddy at start removing current one": {},
"force_first_change": false,
"buddy_change_wait_min": 3,
Expand Down
1 change: 1 addition & 0 deletions configs/config.json.pokemon.example
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"best_in_family": true,
"// candy_limit = 0 means no limit, so it will never change current buddy": {},
"candy_limit": 0,
"candy_limit_absolute":0,
"// force_first_change = true will always change buddy at start removing current one": {},
"force_first_change": false,
"buddy_change_wait_min": 3,
Expand Down
4 changes: 3 additions & 1 deletion docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ This task is an upgrade version of the MoveToMapPokemon task. It will fetch poke
"name": { "param": "pokemon" },
"latitude": { "param": "cords" },
"longitude": { "param": "cords" },
"expiration": { "param": "timeend", "format": "milliseconds" }
"expiration": { "param": "timeend", "format": "seconds" }
}
}
],
Expand Down Expand Up @@ -1298,6 +1298,7 @@ After setting a buddy it's not possible to remove it, only change it. So if a bu
* `buddy_list`: `Default: []`. List of pokemon names that will be used as buddy. If '[]' or 'none', will not use or change buddy.
* `best_in_family`: `Default: True`. If True, picks best Pokemon in the family (sorted by cp).
* `candy_limit`: `Default: 0`. Set the candy limit to be rewarded per buddy, when reaching this limit the bot will change the buddy to the next in the list. When candy_limit = 0 or only one buddy in list, it has no limit and never changes buddy.
* `candy_limit_absolute`: `Default: 0`. Set the absolute candy limit to be rewarded per buddy, when reaching this limit the bot will change the buddy to the next in the list. When candy_limit_absolute = 0 or only one buddy in list, it has no limit and never changes buddy. Use this to stop collecting candy when a candy threshold for your buddy's pokemon family is reached (e.g. 50 for evolving).
* `force_first_change`: `Default: False`. If True, will try to change buddy at bot start according to the buddy list. If False, will use the buddy already set until candy_limit is reached and then use the buddy list.
* `buddy_change_wait_min`: `Default: 3`. Minimum time (in seconds) that the buddy change takes.
* `buddy_change_wait_max`: `Default: 5`. Maximum time (in seconds) that the buddy change takes.
Expand All @@ -1314,6 +1315,7 @@ After setting a buddy it's not possible to remove it, only change it. So if a bu
"best_in_family": true,
"// candy_limit = 0 means no limit, so it will never change current buddy": {},
"candy_limit": 0,
"candy_limit_absolute": 0,
"// force_first_change = true will always change buddy at start removing current one": {},
"force_first_change": false,
"buddy_change_wait_min": 3,
Expand Down
58 changes: 51 additions & 7 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def _setup_event_system(self):
if self.config.websocket_start_embedded_server:
self.sio_runner = SocketIoRunner(self.config.websocket_server_url)
self.sio_runner.start_listening_async()

websocket_handler = SocketIoHandler(
self,
self.config.websocket_server_url
Expand Down Expand Up @@ -476,6 +476,20 @@ def _register_events(self):
'caught_last_24_hour',
)
)
self.event_manager.register_event(
'pokemon_vip_caught',
parameters=(
'pokemon',
'ncp', 'cp', 'iv', 'iv_display', 'exp',
'stardust',
'encounter_id',
'latitude',
'longitude',
'pokemon_id',
'daily_catch_limit',
'caught_last_24_hour',
)
)
self.event_manager.register_event(
'pokemon_evolved',
parameters=('pokemon', 'iv', 'cp', 'candy', 'xp')
Expand Down Expand Up @@ -910,7 +924,8 @@ def check_session(self, position):
self.api = ApiWrapper(config=self.config)
self.api.set_position(*position)
self.login()
self.api.activate_signature(self.get_encryption_lib())
self.api.set_signature_lib(self.get_encryption_lib())
self.api.set_hash_lib(self.get_hash_lib())

def login(self):
self.event_manager.emit(
Expand Down Expand Up @@ -964,20 +979,47 @@ def get_encryption_lib(self):
if _platform == "Windows" or _platform == "win32":
# Check if we are on 32 or 64 bit
if sys.maxsize > 2**32:
file_name = 'encrypt_64.dll'
file_name = 'src/pgoapi/pgoapi/lib/encrypt64.dll'
else:
file_name = 'encrypt.dll'
file_name = 'src/pgoapi/pgoapi/lib/encrypt32.dll'
if _platform.lower() == "darwin":
file_name= 'src/pgoapi/pgoapi/lib/libencrypt-osx-64.so'
if _platform.lower() == "linux" or _platform.lower() == "linux2":
file_name = 'src/pgoapi/pgoapi/lib/libencrypt-linux-x86-64.so'
if self.config.encrypt_location == '':
path = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
else:
file_name = 'encrypt.so'
path = self.config.encrypt_location

full_path = path + '/'+ file_name
if not os.path.isfile(full_path):
self.logger.error(file_name + ' is not found! Please place it in the bots root directory or set encrypt_location in config.')
self.logger.info('Platform: '+ _platform + ' ' + file_name + ' directory: '+ path)
sys.exit(1)
else:
self.logger.info('Found '+ file_name +'! Platform: ' + _platform + ' ' + file_name + ' directory: ' + path)

return full_path

def get_hash_lib(self):
if _platform == "Windows" or _platform == "win32":
# Check if we are on 32 or 64 bit
if sys.maxsize > 2**32:
file_name = 'src/pgoapi/pgoapi/lib/niantichash64.dll'
else:
file_name = 'src/pgoapi/pgoapi/lib/niantichash32.dll'
if _platform.lower() == "darwin":
file_name= 'src/pgoapi/pgoapi/lib/libniantichash-osx-64.so'
if _platform.lower() == "linux" or _platform.lower() == "linux2":
file_name = 'src/pgoapi/pgoapi/lib/libniantichash-linux-x86-64.so'
if self.config.encrypt_location == '':
path = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
else:
path = self.config.encrypt_location

full_path = path + '/'+ file_name
if not os.path.isfile(full_path):
self.logger.error(file_name + ' is not found! Please place it in the bots root directory or set encrypt_location in config.')
self.logger.error(file_name + ' is not found! Please place it in the bots root directory')
self.logger.info('Platform: '+ _platform + ' ' + file_name + ' directory: '+ path)
sys.exit(1)
else:
Expand All @@ -995,7 +1037,9 @@ def _setup_api(self):
self.login()
# chain subrequests (methods) into one RPC call

self.api.activate_signature(self.get_encryption_lib())
self.api.set_signature_lib(self.get_encryption_lib())
self.api.set_hash_lib(self.get_hash_lib())

self.logger.info('')
# send empty map_cells and then our position
self.update_web_location()
Expand Down
27 changes: 24 additions & 3 deletions pokemongo_bot/cell_workers/buddy_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class BuddyPokemon(BaseTask):
"best_in_family": true,
"// candy_limit = 0 means no limit, so it will never change current buddy": {},
"candy_limit": 0,
"candy_limit_absolute": 0,
"// force_first_change = true will always change buddy at start removing current one": {},
"force_first_change": false,
"buddy_change_wait_min": 3,
Expand All @@ -42,6 +43,16 @@ class BuddyPokemon(BaseTask):
to the next in the list. When candy_limit = 0 or
only one buddy in list, it has no limit and never
changes buddy.
candy_limit_absolute: Default: 0. Set the absolute candy limit to be
rewarded per buddy, when reaching this
limit the bot will change the buddy to the
next in the list. When
candy_limit_absolute = 0 or only one buddy
in list, it has no limit and never changes
buddy. Use this to stop collecting candy
when a candy threshold for your buddy's
pokemon family is reached (e.g. 50 for
evolving).
force_first_change: Default: False. If True, will try to change buddy at
bot start according to the buddy list. If False, will
use the buddy already set until candy_limit is reached
Expand All @@ -61,6 +72,7 @@ def initialize(self):
self.buddy_list = self.config.get('buddy_list', [])
self.best_in_family = self.config.get('best_in_family', True)
self.candy_limit = self.config.get('candy_limit', 0) # 0 = No Limit
self.candy_limit_absolute = self.config.get('candy_limit_absolute', 0) # 0 = No Limit
self.force_first_change = self.config.get('force_first_change', False)
self.buddy_change_wait_min = self.config.get('buddy_change_wait_min', 3)
self.buddy_change_wait_max = self.config.get('buddy_change_wait_max', 5)
Expand Down Expand Up @@ -93,10 +105,16 @@ def work(self):
return WorkerResult.SUCCESS

if self.buddy_list:
if self.force_first_change or not self.buddy or self.candy_limit != 0 and self.candy_awarded >= self.candy_limit:
pokemon = self._get_pokemon_by_name(self._get_pokemon_by_id(self.buddy['id']).name)
if self.force_first_change or not self.buddy or pokemon is None or (self.candy_limit != 0 and self.candy_awarded >= self.candy_limit) or self._check_candy_limit_absolute(pokemon):
self.force_first_change = False

remaining = [name for name in self.buddy_list if name not in self.cache]
remaining = []
for name in self.buddy_list:
pokemon = self._get_pokemon_by_name(name)
if name not in self.cache and pokemon is not None and not self._check_candy_limit_absolute(pokemon):
remaining.append(name)

if not remaining:
self.cache = []
return WorkerResult.SUCCESS
Expand Down Expand Up @@ -199,6 +217,9 @@ def _get_award(self):
)
return False

def _check_candy_limit_absolute(self, pokemon):
return self.candy_limit_absolute != 0 and inventory.candies().get(pokemon.family_id).quantity >= self.candy_limit_absolute

def _check_old_reward(self):
if not self.buddy:
return
Expand All @@ -215,7 +236,7 @@ def _get_pokemon_by_name(self, name):
pokemons = inventory.pokemons().all()
pokemon = None
for p in pokemons:
if p.name.lower() == name:
if p.name.lower() == name.lower():
pokemon = p
break

Expand Down
60 changes: 41 additions & 19 deletions pokemongo_bot/cell_workers/pokemon_catch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,25 +649,47 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False):

result = c.fetchone()

self.emit_event(
'pokemon_caught',
formatted='Captured {pokemon}! (CP: {cp} IV: {iv} {iv_display} NCP: {ncp}) Catch Limit: ({caught_last_24_hour}/{daily_catch_limit}) +{exp} exp +{stardust} stardust',
data={
'pokemon': pokemon.name,
'ncp': str(round(pokemon.cp_percent, 2)),
'cp': str(int(pokemon.cp)),
'iv': str(pokemon.iv),
'iv_display': str(pokemon.iv_display),
'exp': str(exp_gain),
'stardust': stardust_gain,
'encounter_id': str(self.pokemon['encounter_id']),
'latitude': str(self.pokemon['latitude']),
'longitude': str(self.pokemon['longitude']),
'pokemon_id': str(pokemon.pokemon_id),
'caught_last_24_hour': str(result[0]),
'daily_catch_limit': str(self.daily_catch_limit)
}
)
if is_vip:
self.emit_event(
'pokemon_vip_caught',
formatted='Vip Captured {pokemon}! (CP: {cp} IV: {iv} {iv_display} NCP: {ncp}) Catch Limit: ({caught_last_24_hour}/{daily_catch_limit}) +{exp} exp +{stardust} stardust',
data={
'pokemon': pokemon.name,
'ncp': str(round(pokemon.cp_percent, 2)),
'cp': str(int(pokemon.cp)),
'iv': str(pokemon.iv),
'iv_display': str(pokemon.iv_display),
'exp': str(exp_gain),
'stardust': stardust_gain,
'encounter_id': str(self.pokemon['encounter_id']),
'latitude': str(self.pokemon['latitude']),
'longitude': str(self.pokemon['longitude']),
'pokemon_id': str(pokemon.pokemon_id),
'caught_last_24_hour': str(result[0]),
'daily_catch_limit': str(self.daily_catch_limit)
}
)

else:
self.emit_event(
'pokemon_caught',
formatted='Captured {pokemon}! (CP: {cp} IV: {iv} {iv_display} NCP: {ncp}) Catch Limit: ({caught_last_24_hour}/{daily_catch_limit}) +{exp} exp +{stardust} stardust',
data={
'pokemon': pokemon.name,
'ncp': str(round(pokemon.cp_percent, 2)),
'cp': str(int(pokemon.cp)),
'iv': str(pokemon.iv),
'iv_display': str(pokemon.iv_display),
'exp': str(exp_gain),
'stardust': stardust_gain,
'encounter_id': str(self.pokemon['encounter_id']),
'latitude': str(self.pokemon['latitude']),
'longitude': str(self.pokemon['longitude']),
'pokemon_id': str(pokemon.pokemon_id),
'caught_last_24_hour': str(result[0]),
'daily_catch_limit': str(self.daily_catch_limit)
}
)


inventory.pokemons().add(pokemon)
Expand Down
10 changes: 10 additions & 0 deletions pokemongo_bot/cell_workers/sniper.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,16 @@ def work(self):
if targets:
# Order the targets (descending)
targets = sorted(targets, key=itemgetter(*self.order), reverse=True)
#List Pokemons found
self._trace('Sniping the {} best Pokemons found, ordered by {}'.format(self.bullets, self.order))
self._trace('+----+------+----------------+-------+----------+---------+---------+----------+')
self._trace('| # | Id | Name | IV | Verified | VIP | Missing | Priority |')
self._trace('+----+------+----------------+-------+----------+---------+---------+----------+')
row_format ="|{:>3} |{:>5} | {:<15}|{:>6} | {:<9}| {:<8}| {:<8}|{:>9} |"
for index, target in enumerate(targets):
self._trace(row_format.format(*[index+1, target.get('pokemon_id'), target.get('pokemon_name'), target.get('iv'), str(target.get('verified')), str(target.get('vip')), str(target.get('missing')), target.get('priority')]))

self._trace('+----+------+----------------+-------+----------+---------+---------+----------+')
shots = 0

# For as long as there are targets available, try to snipe untill we run out of bullets
Expand Down
1 change: 1 addition & 0 deletions pokemongo_bot/event_handlers/logging_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class LoggingHandler(EventHandler):
'pokemon_release': 'green',
'pokemon_upgraded': 'green',
'pokemon_vanished': 'red',
'pokemon_vip_caught': 'blue',
'pokestop_empty': 'yellow',
'pokestop_log': 'magenta',
'pokestop_searching_too_often': 'yellow',
Expand Down
Loading

0 comments on commit 7a56de0

Please sign in to comment.