-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added nickname templating, worker for naming on startup
- Loading branch information
1 parent
79152bc
commit 2086336
Showing
8 changed files
with
138 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from pokemongo_bot import logger | ||
from pokemongo_bot.human_behaviour import sleep | ||
from utils import nickname_pokemon | ||
|
||
class NicknameAllWorker(object): | ||
def __init__(self,bot): | ||
self.bot = bot | ||
|
||
def work(self): | ||
if not self._should_run(): | ||
return | ||
|
||
try: | ||
inventory = reduce(dict.__getitem__, ["responses", "GET_INVENTORY", "inventory_delta", "inventory_items"], self.bot.get_inventory()) | ||
except KeyError: | ||
pass | ||
else: | ||
template = self.bot.config.nickname_template | ||
logger.log("Nicknaming all pokemon in inventory with template {}".format(template),'yellow') | ||
pokemon_data = self._get_inventory_pokemon(inventory) | ||
for pokemon in pokemon_data: | ||
nickname_pokemon(self.bot,pokemon) | ||
sleep(1.2) | ||
logger.log("Finished renaming all pokemon.",'green') | ||
|
||
def _should_run(self): | ||
if not self.bot.config.nickname_template: | ||
return False | ||
|
||
if self.bot.tick_count > 1: | ||
return False | ||
|
||
return True | ||
|
||
def _get_inventory_pokemon(self,inventory_dict): | ||
pokemon_data = [] | ||
for inv_data in inventory_dict: | ||
try: | ||
pokemon = reduce(dict.__getitem__,['inventory_item_data','pokemon_data'],inv_data) | ||
except KeyError: | ||
pass | ||
else: | ||
if not pokemon.get('is_egg',False): | ||
pokemon_data.append(pokemon) | ||
return pokemon_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters