From c49f1ccfed98d3f862e2f04cc157833912fabf68 Mon Sep 17 00:00:00 2001 From: Gobberwart Date: Mon, 22 Aug 2016 10:52:55 +1000 Subject: [PATCH 001/106] Recycle Items schedule/force - Added ability to schedule a forced item recycle regardless of min_empty_space setting. Allows individual items to be recycled based on "keep" settings, even when bag is not nearing capacity. - Added inventory refresh to bot tick (__init.py__) to ensure web displays information correctly. --- configs/config.json.example | 5 +- configs/config.json.path.example | 5 +- pokemongo_bot/__init__.py | 10 ++ pokemongo_bot/cell_workers/recycle_items.py | 94 ++++++++++++++++--- .../event_handlers/colored_logging_handler.py | 2 + 5 files changed, 102 insertions(+), 14 deletions(-) diff --git a/configs/config.json.example b/configs/config.json.example index 5a2a7b7a83..23a9cf4b9a 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -111,7 +111,10 @@ "Razz Berry": { "keep" : 100 } }, "recycle_wait_min": 1, - "recycle_wait_max": 4 + "recycle_wait_max": 4, + "recycle_force": true, + "recycle_force_min": "00:00:00", + "recycle_force_max": "00:01:00" } }, { diff --git a/configs/config.json.path.example b/configs/config.json.path.example index 7612b5a264..0dbc0447ca 100644 --- a/configs/config.json.path.example +++ b/configs/config.json.path.example @@ -101,7 +101,10 @@ "Razz Berry": { "keep" : 100 } }, "recycle_wait_min": 1, - "recycle_wait_max": 4 + "recycle_wait_max": 4, + "recycle_force": true, + "recycle_force_min": "00:00:00", + "recycle_force_max": "00:01:00" } }, { diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index bd0a5ea102..ff8078635a 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -200,6 +200,15 @@ def _register_events(self): ) ) + # recycle stuff + self.event_manager.register_event( + 'next_force_recycle', + parameters=( + 'time' + ) + ) + self.event_manager.register_event('force_recycle') + # fort stuff self.event_manager.register_event( 'spun_fort', @@ -523,6 +532,7 @@ def _register_events(self): def tick(self): self.health_record.heartbeat() self.cell = self.get_meta_cell() + inventory.refresh_inventory() now = time.time() * 1000 diff --git a/pokemongo_bot/cell_workers/recycle_items.py b/pokemongo_bot/cell_workers/recycle_items.py index 1ca8bde91b..b3e1273045 100644 --- a/pokemongo_bot/cell_workers/recycle_items.py +++ b/pokemongo_bot/cell_workers/recycle_items.py @@ -8,6 +8,9 @@ from pokemongo_bot.services.item_recycle_worker import ItemRecycler from pokemongo_bot.tree_config_builder import ConfigException from pokemongo_bot.worker_result import WorkerResult +from random import uniform +from datetime import datetime as dt, timedelta + DEFAULT_MIN_EMPTY_SPACE = 6 @@ -54,7 +57,56 @@ def initialize(self): self.max_revives_keep = self.config.get('max_revives_keep', None) self.recycle_wait_min = self.config.get('recycle_wait_min', 1) self.recycle_wait_max = self.config.get('recycle_wait_max', 4) + self.recycle_force = self.config.get('recycle_force', False) + self.recycle_force_min = self.config.get('recycle_force_min', '00:01:00') + self.recycle_force_max = self.config.get('recycle_force_max', '00:10:00') + self.minInterval = self.getSeconds(self.recycle_force_min) + self.maxInterval = self.getSeconds(self.recycle_force_max) self._validate_item_filter() + + if self.recycle_force: + self._schedule_next_force() + + def getSeconds(self, strTime): + ''' + Return the duration in seconds of a time string + :param strTime: string time of format %H:%M:%S + ''' + try: + x = dt.strptime(strTime, '%H:%M:%S') + seconds = int(timedelta(hours=x.hour,minutes=x.minute,seconds=x.second).total_seconds()) + except ValueError: + seconds = 0; + + if seconds < 0: + seconds = 0; + + return seconds + + def _schedule_next_force(self): + ''' + Schedule the time aof the next forced recycle. + ''' + self._next_force = self._get_next_force_schedule() + self.emit_event( + 'next_force_recycle', + formatted="Next forced item recycle at {time}", + data={ + 'time': str(self._next_force.strftime("%H:%M:%S")) + } + ) + + def _should_force_now(self): + if dt.now() >= self._next_force: + return True + + return False + + def _get_next_force_schedule(self): + now = dt.now() + next_time = now + timedelta(seconds=int(uniform(self.minInterval, self.maxInterval))) + + return next_time def _validate_item_filter(self): """ @@ -77,6 +129,15 @@ def should_run(self): :return: True if the recycling process should be run; otherwise, False. :rtype: bool """ + + if self.recycle_force and self._should_force_now(): + self.emit_event( + 'force_recycle', + formatted="Forcing item recycle based on schedule" + ) + self._schedule_next_force() + return True + if inventory.Items.get_space_left() <= (DEFAULT_MIN_EMPTY_SPACE if self.min_empty_space is None else self.min_empty_space): return True return False @@ -91,25 +152,34 @@ def work(self): worker_result = WorkerResult.SUCCESS if self.should_run(): - if not (self.max_balls_keep is None): - worker_result = self.recycle_excess_category_max(self.max_balls_keep, [1,2,3,4]) - if not (self.max_potions_keep is None): - worker_result = self.recycle_excess_category_max(self.max_potions_keep, [101,102,103,104]) - if not (self.max_berries_keep is None): - worker_result = self.recycle_excess_category_max(self.max_berries_keep, [701,702,703,704,705]) - if not (self.max_revives_keep is None): - worker_result = self.recycle_excess_category_max(self.max_revives_keep, [201,202]) - - inventory.refresh_inventory() - for item_in_inventory in inventory.items().all(): - if self.item_should_be_recycled(item_in_inventory): # Make the bot appears more human action_delay(self.recycle_wait_min, self.recycle_wait_max) # If at any recycling process call we got an error, we consider that the result of this task is error too. if ItemRecycler(self.bot, item_in_inventory, self.get_amount_to_recycle(item_in_inventory)).work() == WorkerResult.ERROR: worker_result = WorkerResult.ERROR + + if not (self.max_balls_keep is None): + this_worker_result = self.recycle_excess_category_max(self.max_balls_keep, [1,2,3,4]) + if this_worker_result <> WorkerResult.SUCCESS: + worker_result = this_worker_result + + if not (self.max_potions_keep is None): + this_worker_result = self.recycle_excess_category_max(self.max_potions_keep, [101,102,103,104]) + if this_worker_result <> WorkerResult.SUCCESS: + worker_result = this_worker_result + + if not (self.max_berries_keep is None): + this_worker_result = self.recycle_excess_category_max(self.max_berries_keep, [701,702,703,704,705]) + if this_worker_result <> WorkerResult.SUCCESS: + worker_result = this_worker_result + + if not (self.max_revives_keep is None): + this_worker_result = self.recycle_excess_category_max(self.max_revives_keep, [201,202]) + if this_worker_result <> WorkerResult.SUCCESS: + worker_result = this_worker_result + return worker_result def recycle_excess_category_max(self, category_max, category_items_list): diff --git a/pokemongo_bot/event_handlers/colored_logging_handler.py b/pokemongo_bot/event_handlers/colored_logging_handler.py index 0bdff6d2b8..39034f5e91 100644 --- a/pokemongo_bot/event_handlers/colored_logging_handler.py +++ b/pokemongo_bot/event_handlers/colored_logging_handler.py @@ -23,6 +23,8 @@ class ColoredLoggingHandler(EventHandler): 'inventory_full': 'yellow', 'item_discard_fail': 'red', 'item_discarded': 'green', + 'next_force_recycle': 'green', + 'force_recycle': 'green', 'keep_best_release': 'green', 'level_up': 'green', 'level_up_reward': 'green', From 80acac7f24b3cbc71c2f6dd77aff009df47b4976 Mon Sep 17 00:00:00 2001 From: Gobberwart Date: Mon, 22 Aug 2016 11:27:08 +1000 Subject: [PATCH 002/106] Updated docs/configs Updated documentation and example config files to show new RecycleItems options. --- configs/config.json.cluster.example | 5 ++++- configs/config.json.map.example | 5 ++++- configs/config.json.optimizer.example | 5 ++++- configs/config.json.pokemon.example | 5 ++++- docs/configuration_files.md | 4 ++++ 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/configs/config.json.cluster.example b/configs/config.json.cluster.example index 604f4d7b36..215016f4e7 100644 --- a/configs/config.json.cluster.example +++ b/configs/config.json.cluster.example @@ -101,7 +101,10 @@ "Razz Berry": { "keep" : 100 } }, "recycle_wait_min": 1, - "recycle_wait_max": 4 + "recycle_wait_max": 4, + "recycle_force": true, + "recycle_force_min": "00:00:00", + "recycle_force_max": "00:01:00" } }, { diff --git a/configs/config.json.map.example b/configs/config.json.map.example index dab997683c..18f6f96efe 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -101,7 +101,10 @@ "Razz Berry": { "keep" : 100 } }, "recycle_wait_min": 1, - "recycle_wait_max": 4 + "recycle_wait_max": 4, + "recycle_force": true, + "recycle_force_min": "00:00:00", + "recycle_force_max": "00:01:00" } }, { diff --git a/configs/config.json.optimizer.example b/configs/config.json.optimizer.example index dfc84f97b4..c0c52cbf3c 100644 --- a/configs/config.json.optimizer.example +++ b/configs/config.json.optimizer.example @@ -166,7 +166,10 @@ "Razz Berry": { "keep" : 100 } }, "recycle_wait_min": 1, - "recycle_wait_max": 4 + "recycle_wait_max": 4, + "recycle_force": true, + "recycle_force_min": "00:00:00", + "recycle_force_max": "00:01:00" } }, { diff --git a/configs/config.json.pokemon.example b/configs/config.json.pokemon.example index 306893bc0b..9b7557b69c 100644 --- a/configs/config.json.pokemon.example +++ b/configs/config.json.pokemon.example @@ -101,7 +101,10 @@ "Razz Berry": { "keep" : 100 } }, "recycle_wait_min": 1, - "recycle_wait_max": 4 + "recycle_wait_max": 4, + "recycle_force": true, + "recycle_force_min": "00:00:00", + "recycle_force_max": "00:01:00" } }, { diff --git a/docs/configuration_files.md b/docs/configuration_files.md index ce78989185..c8ce06e0fa 100644 --- a/docs/configuration_files.md +++ b/docs/configuration_files.md @@ -55,6 +55,10 @@ The behaviors of the bot are configured via the `tasks` key in the `config.json` * `max_potions_keep`: Default `None` | Maximum amount of potions to keep in inventory * `max_berries_keep`: Default `None` | Maximum amount of berries to keep in inventory * `max_revives_keep`: Default `None` | Maximum amount of revives to keep in inventory + * `recycle_force`: Default `False` | Force scheduled recycle, even if min_empty_space not exceeded + * `recycle_force_min`: Default `00:01:00` | Minimum time to wait before scheduling next forced recycle + * `recycle_force_max`: Default `00:10:00` | Maximum time to wait before scheduling next forced recycle + * SpinFort * TransferPokemon * `min_free_slot`: Default `5` | Once the pokebag has less empty slots than this amount, the transfer process is triggered. | Big values (i.e 9999) will trigger the transfer process after each catch. From 587bad06c8ecf68f3b33db2ac61a6c0cab972506 Mon Sep 17 00:00:00 2001 From: PLG Date: Mon, 22 Aug 2016 23:51:35 +0200 Subject: [PATCH 003/106] Patch update_live_stats with xp_per_level As prev_level_xp is in fact the xp of the current level - 1, we need to have the have the value of the current level, which we get from a hard coded value matrix xp_per_level --- pokemongo_bot/cell_workers/update_live_stats.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pokemongo_bot/cell_workers/update_live_stats.py b/pokemongo_bot/cell_workers/update_live_stats.py index f7ae1877e6..4e35e609b0 100644 --- a/pokemongo_bot/cell_workers/update_live_stats.py +++ b/pokemongo_bot/cell_workers/update_live_stats.py @@ -172,7 +172,10 @@ def _update_title(self, title, platform): self.terminal_title = False self._compute_next_update() - + + # hard coded values to supplement unknown current_level_xp + xp_per_level = [[0, 0], [1000, 1000], [2000, 3000], [3000, 6000], [4000, 10000], [5000, 15000], [6000, 21000], [7000, 28000], [8000, 36000], [9000, 45000], [10000, 55000], [10000, 65000], [10000, 75000], [10000, 85000], [15000, 100000], [20000, 120000], [20000, 140000], [20000, 160000], [25000, 185000], [25000, 210000], [50000, 260000], [75000, 335000], [100000, 435000], [125000, 560000], [150000, 710000], [190000, 900000], [200000, 1100000], [250000, 1350000], [300000, 1650000], [350000, 2000000], [500000, 2500000], [500000, 3000000], [750000, 3750000], [1000000, 4750000], [1250000, 6000000], [1500000, 7500000], [2000000, 9500000], [2500000, 12000000], [3000000, 15000000], [5000000, 20000000]] + def _get_stats(self, player_stats): metrics = self.bot.metrics metrics.capture_stats() @@ -182,7 +185,7 @@ def _get_stats(self, player_stats): username = player_data.get('username', '?') distance_travelled = metrics.distance_travelled() current_level = int(player_stats.get('level', 0)) - prev_level_xp = int(player_stats.get('prev_level_xp', 0)) + prev_level_xp = int(xp_per_level[current_level-1][1]) next_level_xp = int(player_stats.get('next_level_xp', 0)) experience = player_stats.get('experience', 0) current_level_xp = experience - prev_level_xp @@ -261,7 +264,7 @@ def _get_stats_line(self, player_stats): username = player_data.get('username', '?') distance_travelled = metrics.distance_travelled() current_level = int(player_stats.get('level', 0)) - prev_level_xp = int(player_stats.get('prev_level_xp', 0)) + prev_level_xp = int(xp_per_level[current_level-1][1]) next_level_xp = int(player_stats.get('next_level_xp', 0)) experience = int(player_stats.get('experience', 0)) current_level_xp = experience - prev_level_xp From 969791dbea0d25b91c5d9687c864b014d0e0544b Mon Sep 17 00:00:00 2001 From: Pierre Le Gallo Date: Tue, 23 Aug 2016 00:22:07 +0200 Subject: [PATCH 004/106] Make xp_per_level global --- pokemongo_bot/cell_workers/update_live_stats.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pokemongo_bot/cell_workers/update_live_stats.py b/pokemongo_bot/cell_workers/update_live_stats.py index 4e35e609b0..b903244c47 100644 --- a/pokemongo_bot/cell_workers/update_live_stats.py +++ b/pokemongo_bot/cell_workers/update_live_stats.py @@ -174,9 +174,12 @@ def _update_title(self, title, platform): self._compute_next_update() # hard coded values to supplement unknown current_level_xp + global xp_per_level xp_per_level = [[0, 0], [1000, 1000], [2000, 3000], [3000, 6000], [4000, 10000], [5000, 15000], [6000, 21000], [7000, 28000], [8000, 36000], [9000, 45000], [10000, 55000], [10000, 65000], [10000, 75000], [10000, 85000], [15000, 100000], [20000, 120000], [20000, 140000], [20000, 160000], [25000, 185000], [25000, 210000], [50000, 260000], [75000, 335000], [100000, 435000], [125000, 560000], [150000, 710000], [190000, 900000], [200000, 1100000], [250000, 1350000], [300000, 1650000], [350000, 2000000], [500000, 2500000], [500000, 3000000], [750000, 3750000], [1000000, 4750000], [1250000, 6000000], [1500000, 7500000], [2000000, 9500000], [2500000, 12000000], [3000000, 15000000], [5000000, 20000000]] def _get_stats(self, player_stats): + global xp_per_level + metrics = self.bot.metrics metrics.capture_stats() runtime = metrics.runtime() @@ -255,6 +258,8 @@ def _get_stats_line(self, player_stats): if not self.displayed_stats: return '' + global xp_per_level + # Gather stats values. metrics = self.bot.metrics metrics.capture_stats() From bc58625830001e3aeb3d27f3147c2821c56a541c Mon Sep 17 00:00:00 2001 From: Gobberwart Date: Tue, 23 Aug 2016 08:49:45 +1000 Subject: [PATCH 005/106] Update web inventory from cache Added "update web inventory" to inventory.py which dumps json to web/inventory-USERNAME.json from the cached inventory instead of calling api. Runs every tick to ensure values are as up-to-date as possible. --- pokemongo_bot/__init__.py | 2 +- pokemongo_bot/inventory.py | 30 ++++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index b18a46a569..7963bd8cb3 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -556,7 +556,7 @@ def _register_events(self): def tick(self): self.health_record.heartbeat() self.cell = self.get_meta_cell() - inventory.refresh_inventory() + inventory.update_web_inventory() now = time.time() * 1000 diff --git a/pokemongo_bot/inventory.py b/pokemongo_bot/inventory.py index 26e4e239e7..10781d7bc9 100644 --- a/pokemongo_bot/inventory.py +++ b/pokemongo_bot/inventory.py @@ -1092,13 +1092,28 @@ def refresh(self): inventory = inventory['responses']['GET_INVENTORY']['inventory_delta']['inventory_items'] for i in (self.pokedex, self.candy, self.items, self.pokemons): i.refresh(inventory) + + self.update_web_inventory() - user_web_inventory = os.path.join(_base_dir, 'web', 'inventory-%s.json' % (self.bot.config.username)) - try: - with open(user_web_inventory, 'w') as outfile: - json.dump(inventory, outfile) - except IOError as e: - errmsg = '[x] Error while opening location file: user_web_inventory' + + def update_web_inventory(self): + web_inventory = os.path.join(_base_dir, "web", "inventory-%s.json" % self.bot.config.username) + json_inventory = [] + + for pokedex in self.pokedex.all(): + json_inventory.append({"inventory_item_data": {"pokedex_entry": pokedex}}) + + for family_id, candy in self.candy._data.items(): + json_inventory.append({"inventory_item_data": {"candy": {"family_id": family_id, "candy": candy.quantity}}}) + + for item_id, item in self.items._data.items(): + json_inventory.append({"inventory_item_data": {"item": {"item_id": item_id, "count": item.count}}}) + + for pokemon in self.pokemons.all(): + json_inventory.append({"inventory_item_data": {"pokemon_data": pokemon._data}}) + + with open(web_inventory, "w") as outfile: + json.dump(json_inventory, outfile) def retrieve_inventories_size(self): """ @@ -1197,6 +1212,9 @@ def refresh_inventory(): :rtype: None """ _inventory.refresh() + +def update_web_inventory(): + _inventory.update_web_inventory() def get_item_inventory_size(): """ From 62a5ad085c00e6efff357a57764a99746d41dfed Mon Sep 17 00:00:00 2001 From: Gobberwart Date: Tue, 23 Aug 2016 09:43:12 +1000 Subject: [PATCH 006/106] Updated comments to include new config settings Updated the comment block at the top of the file to explain/show new settings --- pokemongo_bot/cell_workers/recycle_items.py | 27 ++++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/pokemongo_bot/cell_workers/recycle_items.py b/pokemongo_bot/cell_workers/recycle_items.py index b3e1273045..922d8744e1 100644 --- a/pokemongo_bot/cell_workers/recycle_items.py +++ b/pokemongo_bot/cell_workers/recycle_items.py @@ -18,6 +18,9 @@ class RecycleItems(BaseTask): """ Recycle undesired items if there is less than five space in inventory. You can use either item's name or id. For the full list of items see ../../data/items.json + + Can also force a recycle to occur at a pseudo-random time between recycle_force_min and + recycle_force_max minutes. It's highly recommended to put this task before move_to_fort and spin_fort task in the config file so you'll most likely be able to loot. @@ -41,8 +44,14 @@ class RecycleItems(BaseTask): "Revive": {"keep": 0}, "Max Revive": {"keep": 20}, "Razz Berry": {"keep": 20} - } + }, + "recycle_wait_min": 1, + "recycle_wait_max": 4, + "recycle_force": true, + "recycle_force_min": "00:00:00", + "recycle_force_max": "00:01:00" } + } """ SUPPORTED_TASK_API_VERSION = 1 @@ -152,14 +161,6 @@ def work(self): worker_result = WorkerResult.SUCCESS if self.should_run(): - for item_in_inventory in inventory.items().all(): - if self.item_should_be_recycled(item_in_inventory): - # Make the bot appears more human - action_delay(self.recycle_wait_min, self.recycle_wait_max) - # If at any recycling process call we got an error, we consider that the result of this task is error too. - if ItemRecycler(self.bot, item_in_inventory, self.get_amount_to_recycle(item_in_inventory)).work() == WorkerResult.ERROR: - worker_result = WorkerResult.ERROR - if not (self.max_balls_keep is None): this_worker_result = self.recycle_excess_category_max(self.max_balls_keep, [1,2,3,4]) if this_worker_result <> WorkerResult.SUCCESS: @@ -179,6 +180,14 @@ def work(self): this_worker_result = self.recycle_excess_category_max(self.max_revives_keep, [201,202]) if this_worker_result <> WorkerResult.SUCCESS: worker_result = this_worker_result + + for item_in_inventory in inventory.items().all(): + if self.item_should_be_recycled(item_in_inventory): + # Make the bot appears more human + action_delay(self.recycle_wait_min, self.recycle_wait_max) + # If at any recycling process call we got an error, we consider that the result of this task is error too. + if ItemRecycler(self.bot, item_in_inventory, self.get_amount_to_recycle(item_in_inventory)).work() == WorkerResult.ERROR: + worker_result = WorkerResult.ERROR return worker_result From 2a9f345570a2fccab2d34d73395744a4ca941bf3 Mon Sep 17 00:00:00 2001 From: Gobberwart Date: Tue, 23 Aug 2016 11:38:57 +1000 Subject: [PATCH 007/106] Added player stats to web output Previous commit missed player stats. Fixed. --- pokemongo_bot/inventory.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pokemongo_bot/inventory.py b/pokemongo_bot/inventory.py index 10781d7bc9..e20fa3ad5d 100644 --- a/pokemongo_bot/inventory.py +++ b/pokemongo_bot/inventory.py @@ -1100,6 +1100,18 @@ def update_web_inventory(self): web_inventory = os.path.join(_base_dir, "web", "inventory-%s.json" % self.bot.config.username) json_inventory = [] + inventory_items = self.bot.api.get_inventory() \ + .get('responses', {}) \ + .get('GET_INVENTORY', {}) \ + .get('inventory_delta', {}) \ + .get('inventory_items', {}) + player_data = next((x["inventory_item_data"]["player_stats"] + for x in inventory_items + if x.get("inventory_item_data", {}).get("player_stats", {})), + None) + for player_stat in player_data: + json_inventory.append({"inventory_item_data": {"player_stats": player_data}}) + for pokedex in self.pokedex.all(): json_inventory.append({"inventory_item_data": {"pokedex_entry": pokedex}}) From 32f0c5d2969debd2b0b2ba1ebaa0ca6eec49fa0c Mon Sep 17 00:00:00 2001 From: Gobberwart Date: Tue, 23 Aug 2016 18:32:16 +1000 Subject: [PATCH 008/106] Removed api call for player_stats Removed api call for player_stats, and moved output of player_stats to web to update_live_stats.py --- .../cell_workers/update_live_stats.py | 25 +++++++++++++++++-- pokemongo_bot/inventory.py | 21 ++++++---------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/pokemongo_bot/cell_workers/update_live_stats.py b/pokemongo_bot/cell_workers/update_live_stats.py index f7ae1877e6..5b412cba4d 100644 --- a/pokemongo_bot/cell_workers/update_live_stats.py +++ b/pokemongo_bot/cell_workers/update_live_stats.py @@ -1,10 +1,13 @@ import ctypes +import json +import os from sys import stdout, platform as _platform from datetime import datetime, timedelta from pokemongo_bot.base_task import BaseTask from pokemongo_bot.worker_result import WorkerResult from pokemongo_bot.tree_config_builder import ConfigException +from pokemongo_bot.base_dir import _base_dir class UpdateLiveStats(BaseTask): @@ -92,11 +95,15 @@ def work(self): """ if not self._should_display(): return WorkerResult.SUCCESS - line = self._get_stats_line(self._get_player_stats()) + + player_stats = self._get_player_stats() + line = self._get_stats_line(player_stats) # If line is empty, it couldn't be generated. if not line: return WorkerResult.SUCCESS - + + self.update_web_stats(player_stats) + if self.terminal_title: self._update_title(line, _platform) @@ -356,3 +363,17 @@ def _get_player_stats(self): for x in inventory_items if x.get("inventory_item_data", {}).get("player_stats", {})), None) + + def update_web_stats(self,player_data): + web_inventory = os.path.join(_base_dir, "web", "inventory-%s.json" % self.bot.config.username) + + with open(web_inventory, "r") as infile: + json_stats = json.load(infile) + + json_stats = [x for x in json_stats if not x.get("inventory_item_data", {}).get("player_stats", None)] + + for player_stat in player_data: + json_stats.append({"inventory_item_data": {"player_stats": player_data}}) + + with open(web_inventory, "w") as outfile: + json.dump(json_stats, outfile) diff --git a/pokemongo_bot/inventory.py b/pokemongo_bot/inventory.py index e20fa3ad5d..7a7c341fb1 100644 --- a/pokemongo_bot/inventory.py +++ b/pokemongo_bot/inventory.py @@ -1098,20 +1098,15 @@ def refresh(self): def update_web_inventory(self): web_inventory = os.path.join(_base_dir, "web", "inventory-%s.json" % self.bot.config.username) - json_inventory = [] + + with open(web_inventory, "r") as infile: + json_inventory = json.load(infile) + + json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("pokedex_entry", None)] + json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("candy", None)] + json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("item", None)] + json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("pokemon_data", None)] - inventory_items = self.bot.api.get_inventory() \ - .get('responses', {}) \ - .get('GET_INVENTORY', {}) \ - .get('inventory_delta', {}) \ - .get('inventory_items', {}) - player_data = next((x["inventory_item_data"]["player_stats"] - for x in inventory_items - if x.get("inventory_item_data", {}).get("player_stats", {})), - None) - for player_stat in player_data: - json_inventory.append({"inventory_item_data": {"player_stats": player_data}}) - for pokedex in self.pokedex.all(): json_inventory.append({"inventory_item_data": {"pokedex_entry": pokedex}}) From b8bb2d152d6bfa765ff224e40ca8c37c61fdb8af Mon Sep 17 00:00:00 2001 From: Gobberwart Date: Tue, 23 Aug 2016 18:59:45 +1000 Subject: [PATCH 009/106] Slight logic error Correct error that would result in player_data being written multiple times. Something in the bot is still doing that somewhere, but definitely not in this new code. --- pokemongo_bot/cell_workers/update_live_stats.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pokemongo_bot/cell_workers/update_live_stats.py b/pokemongo_bot/cell_workers/update_live_stats.py index 5b412cba4d..13dd8576cf 100644 --- a/pokemongo_bot/cell_workers/update_live_stats.py +++ b/pokemongo_bot/cell_workers/update_live_stats.py @@ -371,9 +371,8 @@ def update_web_stats(self,player_data): json_stats = json.load(infile) json_stats = [x for x in json_stats if not x.get("inventory_item_data", {}).get("player_stats", None)] - - for player_stat in player_data: - json_stats.append({"inventory_item_data": {"player_stats": player_data}}) + + json_stats.append({"inventory_item_data": {"player_stats": player_data}}) with open(web_inventory, "w") as outfile: json.dump(json_stats, outfile) From ee8f2d04cca887d0d2f4a47a820703000d8982d5 Mon Sep 17 00:00:00 2001 From: Dmitry Ovodov Date: Tue, 23 Aug 2016 22:46:43 +0300 Subject: [PATCH 010/106] Move SleepSchedule from workers to main bot instance and some whitespace cleanup --- pokecli.py | 8 +- pokemongo_bot/__init__.py | 13 +- pokemongo_bot/cell_workers/__init__.py | 3 +- pokemongo_bot/cell_workers/sleep_schedule.py | 153 ---------------- pokemongo_bot/sleep_schedule.py | 180 +++++++++++++++++++ 5 files changed, 195 insertions(+), 162 deletions(-) delete mode 100644 pokemongo_bot/cell_workers/sleep_schedule.py create mode 100644 pokemongo_bot/sleep_schedule.py diff --git a/pokecli.py b/pokecli.py index 5a06978029..047fdb1575 100644 --- a/pokecli.py +++ b/pokecli.py @@ -180,6 +180,7 @@ def get_commit_hash(): formatted='Bot caught SIGINT. Shutting down.' ) report_summary(bot) +''' except Exception as e: # always report session summary and then raise exception if bot: @@ -210,7 +211,7 @@ def get_commit_hash(): formatted='Error caching forts for {path}', data={'path': cached_forts_path} ) - +''' def report_summary(bot): @@ -570,7 +571,7 @@ def _json_loader(filename): type=float, default=8.0 ) - + add_config( parser, load, @@ -579,7 +580,7 @@ def _json_loader(filename): type=bool, default=True ) - + # Start to parse other attrs config = parser.parse_args() if not config.username and 'username' not in load: @@ -594,6 +595,7 @@ def _json_loader(filename): config.raw_tasks = load.get('tasks', []) config.daily_catch_limit = load.get('daily_catch_limit', 800) config.vips = load.get('vips', {}) + config.sleep_schedule = load.get('sleep_schedule', []) if config.map_object_cache_time < 0.0: parser.error("--map_object_cache_time is out of range! (should be >= 0.0)") diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 94ecf8ef09..97803b1249 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -25,6 +25,7 @@ from human_behaviour import sleep from item_list import Item from metrics import Metrics +from sleep_schedule import SleepSchedule from pokemongo_bot.event_handlers import LoggingHandler, SocketIoHandler, ColoredLoggingHandler, SocialHandler from pokemongo_bot.socketio_server.runner import SocketIoRunner from pokemongo_bot.websocket_remote_control import WebsocketRemoteControl @@ -101,6 +102,8 @@ def __init__(self, config): def start(self): self._setup_event_system() self._setup_logging() + self.sleep_schedule = SleepSchedule(self, self.config.sleep_schedule) if self.config.sleep_schedule else None + if self.sleep_schedule: self.sleep_schedule.work() self._setup_api() self._load_recent_forts() init_inventory(self) @@ -183,9 +186,9 @@ def _register_events(self): 'duration', 'resume' ) - ) - - + ) + + self.event_manager.register_event('location_cache_error') self.event_manager.register_event('bot_start') @@ -550,6 +553,8 @@ def tick(self): self.health_record.heartbeat() self.cell = self.get_meta_cell() + if self.sleep_schedule: self.sleep_schedule.work() + now = time.time() * 1000 for fort in self.cell["forts"]: @@ -935,7 +940,7 @@ def get_poke_info(info, pokemon): if show_candies: line_p += '[{} candies]'.format(pokes[0].candy_quantity) line_p += ': ' - + poke_info = ['({})'.format(', '.join([get_poke_info(x, p) for x in poke_info_displayed])) for p in pokes] self.logger.info(line_p + ' | '.join(poke_info)) diff --git a/pokemongo_bot/cell_workers/__init__.py b/pokemongo_bot/cell_workers/__init__.py index 66df050917..f4411d307e 100644 --- a/pokemongo_bot/cell_workers/__init__.py +++ b/pokemongo_bot/cell_workers/__init__.py @@ -17,9 +17,8 @@ from follow_spiral import FollowSpiral from collect_level_up_reward import CollectLevelUpReward from follow_cluster import FollowCluster -from sleep_schedule import SleepSchedule from update_live_stats import UpdateLiveStats from update_live_inventory import UpdateLiveInventory from catch_pokemon import CatchPokemon from complete_tutorial import CompleteTutorial -from random_pause import RandomPause \ No newline at end of file +from random_pause import RandomPause diff --git a/pokemongo_bot/cell_workers/sleep_schedule.py b/pokemongo_bot/cell_workers/sleep_schedule.py deleted file mode 100644 index b7e0a711a4..0000000000 --- a/pokemongo_bot/cell_workers/sleep_schedule.py +++ /dev/null @@ -1,153 +0,0 @@ -from datetime import datetime, timedelta -from time import sleep -from random import uniform -from pokemongo_bot.base_task import BaseTask - - -class SleepSchedule(BaseTask): - """Pauses the execution of the bot every day for some time - - Simulates the user going to sleep every day for some time, the sleep time - and the duration is changed every day by a random offset defined in the - config file - Example Config: - { - "type": "SleepSchedule", - "config": { - "time": "12:00", - "duration":"5:30", - "time_random_offset": "00:30", - "duration_random_offset": "00:30" - "wake_up_at_location": "" - } - } - time: (HH:MM) local time that the bot should sleep - duration: (HH:MM) the duration of sleep - time_random_offset: (HH:MM) random offset of time that the sleep will start - for this example the possible start time is 11:30-12:30 - duration_random_offset: (HH:MM) random offset of duration of sleep - for this example the possible duration is 5:00-6:00 - wake_up_at_location: (lat, long | lat, long, alt | "") the location at which the bot wake up - *Note that an empty string ("") will not change the location*. """ - SUPPORTED_TASK_API_VERSION = 1 - - LOG_INTERVAL_SECONDS = 600 - SCHEDULING_MARGIN = timedelta(minutes=10) # Skip if next sleep is RESCHEDULING_MARGIN from now - - def initialize(self): - # self.bot.event_manager.register_event('sleeper_scheduled', parameters=('datetime',)) - self._process_config() - self._schedule_next_sleep() - self._calculate_current_sleep() - - def work(self): - if self._should_sleep_now(): - self._sleep() - self._schedule_next_sleep() - wake_up_at_location = self.config.get("wake_up_at_location", "") - if wake_up_at_location: - self.bot.api.set_position(self.wake_up_at_location[0],self.wake_up_at_location[1],self.wake_up_at_location[2]) - self.bot.login() - - def _process_config(self): - self.time = datetime.strptime(self.config.get('time', '01:00'), '%H:%M') - - # Using datetime for easier stripping of timedeltas - duration = datetime.strptime(self.config.get('duration', '07:00'), '%H:%M') - self.duration = int(timedelta(hours=duration.hour, minutes=duration.minute).total_seconds()) - - time_random_offset = datetime.strptime(self.config.get('time_random_offset', '01:00'), '%H:%M') - self.time_random_offset = int( - timedelta( - hours=time_random_offset.hour, minutes=time_random_offset.minute).total_seconds()) - - duration_random_offset = datetime.strptime(self.config.get('duration_random_offset', '00:30'), '%H:%M') - self.duration_random_offset = int( - timedelta( - hours=duration_random_offset.hour, minutes=duration_random_offset.minute).total_seconds()) - - wake_up_at_location = self.config.get("wake_up_at_location", "") - if wake_up_at_location: - try: - wake_up_at_location = wake_up_at_location.split(',',2) - lat=float(wake_up_at_location[0]) - lng=float(wake_up_at_location[1]) - if len(wake_up_at_location) == 3: - alt=float(wake_up_at_location[2]) - else: - alt = uniform(self.bot.config.alt_min, self.bot.config.alt_max) - except ValueError: - raise ValueError('SleepSchedule wake_up_at_location, parsing error in location') #TODO there must be a more elegant way to do it... - - self.wake_up_at_location = [lat, lng, alt] - - def _schedule_next_sleep(self): - self._next_sleep = self._get_next_sleep_schedule() - self._next_duration = self._get_next_duration() - self.emit_event( - 'next_sleep', - formatted="Next sleep at {time}", - data={ - 'time': str(self._next_sleep) - } - ) - - def _calculate_current_sleep(self): - self._current_sleep = self._next_sleep - timedelta(days=1) - current_duration = self._get_next_duration() - self._current_end = self._current_sleep + timedelta(seconds = current_duration) - - def _should_sleep_now(self): - if datetime.now() >= self._next_sleep: - return True - if datetime.now() >= self._current_sleep and datetime.now() < self._current_end: - self._next_duration = (self._current_end - datetime.now()).total_seconds() - return True - - return False - - def _get_next_sleep_schedule(self): - now = datetime.now() + self.SCHEDULING_MARGIN - next_time = now.replace(hour=self.time.hour, minute=self.time.minute) - - next_time += timedelta(seconds=self._get_random_offset(self.time_random_offset)) - - # If sleep time is passed add one day - if next_time <= now: - next_time += timedelta(days=1) - - return next_time - - def _get_next_duration(self): - duration = self.duration + self._get_random_offset(self.duration_random_offset) - return duration - - def _get_random_offset(self, max_offset): - offset = uniform(-max_offset, max_offset) - return int(offset) - - def _sleep(self): - sleep_to_go = self._next_duration - - sleep_m, sleep_s = divmod(sleep_to_go, 60) - sleep_h, sleep_m = divmod(sleep_m, 60) - sleep_hms = '%02d:%02d:%02d' % (sleep_h, sleep_m, sleep_s) - - now = datetime.now() - wake = str(now + timedelta(seconds=sleep_to_go)) - - self.emit_event( - 'bot_sleep', - formatted="Sleeping for {time_hms}, wake at {wake}", - data={ - 'time_hms': sleep_hms, - 'wake': wake - } - ) - while sleep_to_go > 0: - if sleep_to_go < self.LOG_INTERVAL_SECONDS: - sleep(sleep_to_go) - sleep_to_go = 0 - else: - sleep(self.LOG_INTERVAL_SECONDS) - sleep_to_go -= self.LOG_INTERVAL_SECONDS diff --git a/pokemongo_bot/sleep_schedule.py b/pokemongo_bot/sleep_schedule.py new file mode 100644 index 0000000000..0000c900d2 --- /dev/null +++ b/pokemongo_bot/sleep_schedule.py @@ -0,0 +1,180 @@ +from datetime import datetime, timedelta +from time import sleep +from random import uniform + + +class SleepSchedule(object): + """Pauses the execution of the bot every day for some time + + Simulates the user going to sleep every day for some time, the sleep time + and the duration is changed every day by a random offset defined in the + config file + Example Config: + "sleep_schedule": [ + { + "time": "12:00", + "duration":"5:30", + "time_random_offset": "00:30", + "duration_random_offset": "00:30" + "wake_up_at_location": "" + }, + { + "time": "17:45", + "duration":"3:00", + "time_random_offset": "01:00", + "duration_random_offset": "00:30" + "wake_up_at_location": "" + } + ] + time: (HH:MM) local time that the bot should sleep + duration: (HH:MM) the duration of sleep + time_random_offset: (HH:MM) random offset of time that the sleep will start + for this example the possible start time is 11:30-12:30 + duration_random_offset: (HH:MM) random offset of duration of sleep + for this example the possible duration is 5:00-6:00 + wake_up_at_location: (lat, long | lat, long, alt | "") the location at which the bot wake up + *Note that an empty string ("") will not change the location*. """ + + LOG_INTERVAL_SECONDS = 600 + SCHEDULING_MARGIN = timedelta(minutes=10) # Skip if next sleep is RESCHEDULING_MARGIN from now + + def __init__(self, bot, config): + self.bot = bot + self._process_config(config) + self._schedule_next_sleep() + self._calculate_current_sleep() + + def work(self): + if self._should_sleep_now(): + self._sleep() + self._schedule_next_sleep() + wake_up_at_location = self._wake_up_at_location + if wake_up_at_location: + self.bot.api.set_position(self.wake_up_at_location[0],self.wake_up_at_location[1],self.wake_up_at_location[2]) + self.bot.login() + + def _process_config(self, config): + self.entries = [] + for entry in config: + prepared = {} + prepared['time'] = datetime.strptime(entry['time'] if 'time' in entry else '01:00', '%H:%M') + + # Using datetime for easier stripping of timedeltas + raw_duration = datetime.strptime(entry['duration'] if 'duration' in entry else '07:00', '%H:%M') + duration = int(timedelta(hours=raw_duration.hour, minutes=raw_duration.minute).total_seconds()) + + raw_time_random_offset = datetime.strptime(entry['time_random_offset'] if 'time_random_offset' in entry else '01:00', '%H:%M') + time_random_offset = int( + timedelta( + hours=raw_time_random_offset.hour, minutes=raw_time_random_offset.minute).total_seconds()) + + raw_duration_random_offset = datetime.strptime(entry['duration_random_offset'] if 'duration_random_offset' in entry else '00:30', '%H:%M') + duration_random_offset = int( + timedelta( + hours=raw_duration_random_offset.hour, minutes=raw_duration_random_offset.minute).total_seconds()) + + raw_wake_up_at_location = entry['wake_up_at_location'] if 'wake_up_at_location' in entry else '' + if raw_wake_up_at_location: + try: + wake_up_at_location = wake_up_at_location.split(',',2) + lat=float(wake_up_at_location[0]) + lng=float(wake_up_at_location[1]) + if len(wake_up_at_location) == 3: + alt=float(wake_up_at_location[2]) + else: + alt = uniform(self.bot.config.alt_min, self.bot.config.alt_max) + except ValueError: + raise ValueError('SleepSchedule wake_up_at_location, parsing error in location') #TODO there must be a more elegant way to do it... + + prepared['wake_up_at_location'] = [lat, lng, alt] + prepared['duration'] = duration + prepared['time_random_offset'] = time_random_offset + prepared['duration_random_offset'] = duration_random_offset + self.entries.append(prepared) + + def _schedule_next_sleep(self): + self._next_sleep, self._next_duration, self._wake_up_at_location = self._get_next_sleep_schedule() + self.bot.event_manager.emit( + 'next_sleep', + sender=self, + formatted="Next sleep at {time}", + data={ + 'time': str(self._next_sleep) + } + ) + + def _calculate_current_sleep(self): + self._current_sleep = self._next_sleep - timedelta(days=1) + current_duration = self._next_duration + self._current_end = self._current_sleep + timedelta(seconds = current_duration) + + def _should_sleep_now(self): + if datetime.now() >= self._next_sleep: + return True + if datetime.now() >= self._current_sleep and datetime.now() < self._current_end: + self._next_duration = (self._current_end - datetime.now()).total_seconds() + return True + + return False + + def _get_next_sleep_schedule(self): + now = datetime.now() + self.SCHEDULING_MARGIN + + times = [] + for index in range(len(self.entries)): + next_time = now.replace(hour=self.entries[index]['time'].hour, minute=self.entries[index]['time'].minute) + next_time += timedelta(seconds=self._get_random_offset(self.entries[index]['time_random_offset'])) + + # If sleep time is passed add one day + if next_time <= now: + next_time += timedelta(days=1) + + times.append(next_time) + + diffs = {} + for index in range(len(self.entries)): + diff = (next_time-now).total_seconds() + if diff >= 0: diffs[index] = diff + + closest = min(diffs.iterkeys(), key=lambda x: diffs[x]) + + next_time = times[closest] + next_duration = self._get_next_duration(self.entries[closest]) + location = self.entries[closest]['wake_up_at_location'] if 'wake_up_at_location' in self.entries[closest] else '' + + return next_time, next_duration, location + + def _get_next_duration(self, entry): + duration = entry['duration'] + self._get_random_offset(entry['duration_random_offset']) + return duration + + def _get_random_offset(self, max_offset): + offset = uniform(-max_offset, max_offset) + return int(offset) + + def _sleep(self): + sleep_to_go = self._next_duration + + sleep_m, sleep_s = divmod(sleep_to_go, 60) + sleep_h, sleep_m = divmod(sleep_m, 60) + sleep_hms = '%02d:%02d:%02d' % (sleep_h, sleep_m, sleep_s) + + now = datetime.now() + wake = str(now + timedelta(seconds=sleep_to_go)) + + self.bot.event_manager.emit( + 'bot_sleep', + sender=self, + formatted="Sleeping for {time_hms}, wake at {wake}", + data={ + 'time_hms': sleep_hms, + 'wake': wake + } + ) + while sleep_to_go > 0: + if sleep_to_go < self.LOG_INTERVAL_SECONDS: + sleep(sleep_to_go) + sleep_to_go = 0 + else: + sleep(self.LOG_INTERVAL_SECONDS) + sleep_to_go -= self.LOG_INTERVAL_SECONDS From 03361efd5305bd78be0aebaafd463d5a11fd7628 Mon Sep 17 00:00:00 2001 From: Dmitry Ovodov Date: Wed, 24 Aug 2016 01:48:16 +0300 Subject: [PATCH 011/106] Update example configs --- configs/config.json.cluster.example | 26 ++++++++++++++++---------- configs/config.json.example | 27 ++++++++++++++++----------- configs/config.json.map.example | 26 ++++++++++++++++---------- configs/config.json.optimizer.example | 26 ++++++++++++++++---------- configs/config.json.path.example | 26 ++++++++++++++++---------- configs/config.json.pokemon.example | 26 ++++++++++++++++---------- pokemongo_bot/sleep_schedule.py | 8 ++++---- 7 files changed, 100 insertions(+), 65 deletions(-) diff --git a/configs/config.json.cluster.example b/configs/config.json.cluster.example index b847c1a638..886683a631 100644 --- a/configs/config.json.cluster.example +++ b/configs/config.json.cluster.example @@ -12,16 +12,6 @@ { "type": "HandleSoftBan" }, - { - "type": "SleepSchedule", - "config": { - "enabled": false, - "time": "22:54", - "duration":"7:46", - "time_random_offset": "00:24", - "duration_random_offset": "00:43" - } - }, { "type": "CompleteTutorial", "config": { @@ -177,6 +167,22 @@ "walk_min": 2.16, "alt_min": 500, "alt_max": 1000, + "sleep_schedule": [ + { + "time": "12:00", + "duration": "5:30", + "time_random_offset": "00:30", + "duration_random_offset": "00:30", + "wake_up_at_location": "" + }, + { + "time": "17:45", + "duration": "3:00", + "time_random_offset": "01:00", + "duration_random_offset": "00:30", + "wake_up_at_location": "" + } + ], "debug": false, "test": false, "health_record": true, diff --git a/configs/config.json.example b/configs/config.json.example index 2986e59205..421399a5d3 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -12,17 +12,6 @@ { "type": "HandleSoftBan" }, - { - "type": "SleepSchedule", - "config": { - "enabled": false, - "time": "22:54", - "duration":"7:46", - "time_random_offset": "00:24", - "duration_random_offset": "00:43", - "wake_up_at_location": "" - } - }, { "type": "RandomPause", "config": { @@ -202,6 +191,22 @@ "walk_min": 2.16, "alt_min": 500, "alt_max": 1000, + "sleep_schedule": [ + { + "time": "12:00", + "duration": "5:30", + "time_random_offset": "00:30", + "duration_random_offset": "00:30", + "wake_up_at_location": "" + }, + { + "time": "17:45", + "duration": "3:00", + "time_random_offset": "01:00", + "duration_random_offset": "00:30", + "wake_up_at_location": "" + } + ], "gps_default_altitude": 8.0, "replicate_gps_xy_noise": false, "replicate_gps_z_noise": false, diff --git a/configs/config.json.map.example b/configs/config.json.map.example index d2990b1b38..7cd7ff619e 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -12,16 +12,6 @@ { "type": "HandleSoftBan" }, - { - "type": "SleepSchedule", - "config": { - "enabled": false, - "time": "22:54", - "duration":"7:46", - "time_random_offset": "00:24", - "duration_random_offset": "00:43" - } - }, { "type": "CompleteTutorial", "config": { @@ -433,6 +423,22 @@ "walk_min": 2.16, "alt_min": 500, "alt_max": 1000, + "sleep_schedule": [ + { + "time": "12:00", + "duration": "5:30", + "time_random_offset": "00:30", + "duration_random_offset": "00:30", + "wake_up_at_location": "" + }, + { + "time": "17:45", + "duration": "3:00", + "time_random_offset": "01:00", + "duration_random_offset": "00:30", + "wake_up_at_location": "" + } + ], "debug": false, "test": false, "health_record": true, diff --git a/configs/config.json.optimizer.example b/configs/config.json.optimizer.example index 54886ee30f..c657e9424d 100644 --- a/configs/config.json.optimizer.example +++ b/configs/config.json.optimizer.example @@ -12,16 +12,6 @@ { "type": "HandleSoftBan" }, - { - "type": "SleepSchedule", - "config": { - "enabled": false, - "time": "22:54", - "duration":"7:46", - "time_random_offset": "00:24", - "duration_random_offset": "00:43" - } - }, { "type": "CompleteTutorial", "config": { @@ -249,6 +239,22 @@ "walk_min": 2.16, "alt_min": 500, "alt_max": 1000, + "sleep_schedule": [ + { + "time": "12:00", + "duration": "5:30", + "time_random_offset": "00:30", + "duration_random_offset": "00:30", + "wake_up_at_location": "" + }, + { + "time": "17:45", + "duration": "3:00", + "time_random_offset": "01:00", + "duration_random_offset": "00:30", + "wake_up_at_location": "" + } + ], "debug": false, "test": false, "health_record": true, diff --git a/configs/config.json.path.example b/configs/config.json.path.example index 291a2351d2..692f98c1d2 100644 --- a/configs/config.json.path.example +++ b/configs/config.json.path.example @@ -12,16 +12,6 @@ { "type": "HandleSoftBan" }, - { - "type": "SleepSchedule", - "config": { - "enabled": false, - "time": "22:54", - "duration":"7:46", - "time_random_offset": "00:24", - "duration_random_offset": "00:43" - } - }, { "type": "CompleteTutorial", "config": { @@ -182,6 +172,22 @@ "walk_min": 2.16, "alt_min": 500, "alt_max": 1000, + "sleep_schedule": [ + { + "time": "12:00", + "duration": "5:30", + "time_random_offset": "00:30", + "duration_random_offset": "00:30", + "wake_up_at_location": "" + }, + { + "time": "17:45", + "duration": "3:00", + "time_random_offset": "01:00", + "duration_random_offset": "00:30", + "wake_up_at_location": "" + } + ], "debug": false, "test": false, "health_record": true, diff --git a/configs/config.json.pokemon.example b/configs/config.json.pokemon.example index 484c4f4877..7146cac558 100644 --- a/configs/config.json.pokemon.example +++ b/configs/config.json.pokemon.example @@ -12,16 +12,6 @@ { "type": "HandleSoftBan" }, - { - "type": "SleepSchedule", - "config": { - "enabled": false, - "time": "22:54", - "duration":"7:46", - "time_random_offset": "00:24", - "duration_random_offset": "00:43" - } - }, { "type": "CompleteTutorial", "config": { @@ -187,6 +177,22 @@ "walk_min": 2.16, "alt_min": 500, "alt_max": 1000, + "sleep_schedule": [ + { + "time": "12:00", + "duration": "5:30", + "time_random_offset": "00:30", + "duration_random_offset": "00:30", + "wake_up_at_location": "" + }, + { + "time": "17:45", + "duration": "3:00", + "time_random_offset": "01:00", + "duration_random_offset": "00:30", + "wake_up_at_location": "" + } + ], "debug": false, "test": false, "health_record": true, diff --git a/pokemongo_bot/sleep_schedule.py b/pokemongo_bot/sleep_schedule.py index 0000c900d2..114caa97e2 100644 --- a/pokemongo_bot/sleep_schedule.py +++ b/pokemongo_bot/sleep_schedule.py @@ -13,16 +13,16 @@ class SleepSchedule(object): "sleep_schedule": [ { "time": "12:00", - "duration":"5:30", + "duration": "5:30", "time_random_offset": "00:30", - "duration_random_offset": "00:30" + "duration_random_offset": "00:30", "wake_up_at_location": "" }, { "time": "17:45", - "duration":"3:00", + "duration": "3:00", "time_random_offset": "01:00", - "duration_random_offset": "00:30" + "duration_random_offset": "00:30", "wake_up_at_location": "" } ] From 22c2dbdf15b5f3f746adaad3e8efd07562c8eef1 Mon Sep 17 00:00:00 2001 From: Dmitry Ovodov Date: Wed, 24 Aug 2016 01:58:30 +0300 Subject: [PATCH 012/106] undebugging --- pokecli.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pokecli.py b/pokecli.py index 047fdb1575..70e88b892e 100644 --- a/pokecli.py +++ b/pokecli.py @@ -180,7 +180,7 @@ def get_commit_hash(): formatted='Bot caught SIGINT. Shutting down.' ) report_summary(bot) -''' + except Exception as e: # always report session summary and then raise exception if bot: @@ -211,7 +211,6 @@ def get_commit_hash(): formatted='Error caching forts for {path}', data={'path': cached_forts_path} ) -''' def report_summary(bot): From 453b7717a910963912283b7fbeba8278f7b46110 Mon Sep 17 00:00:00 2001 From: Dmitry Ovodov Date: Wed, 24 Aug 2016 02:12:12 +0300 Subject: [PATCH 013/106] Something gone wrong, recovering changes --- pokemongo_bot/sleep_schedule.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pokemongo_bot/sleep_schedule.py b/pokemongo_bot/sleep_schedule.py index 114caa97e2..0688846e46 100644 --- a/pokemongo_bot/sleep_schedule.py +++ b/pokemongo_bot/sleep_schedule.py @@ -47,11 +47,14 @@ def __init__(self, bot, config): def work(self): if self._should_sleep_now(): self._sleep() - self._schedule_next_sleep() wake_up_at_location = self._wake_up_at_location + self._schedule_next_sleep() if wake_up_at_location: - self.bot.api.set_position(self.wake_up_at_location[0],self.wake_up_at_location[1],self.wake_up_at_location[2]) - self.bot.login() + try: + self.bot.api.set_position(wake_up_at_location[0],wake_up_at_location[1],wake_up_at_location[2]) # Expecting error here + self.bot.login() + except AttributeError: # It will happen if bot starts sleeping, in this case api is not initialized yet + self.bot.wake_location = wake_up_at_location def _process_config(self, config): self.entries = [] @@ -76,7 +79,7 @@ def _process_config(self, config): raw_wake_up_at_location = entry['wake_up_at_location'] if 'wake_up_at_location' in entry else '' if raw_wake_up_at_location: try: - wake_up_at_location = wake_up_at_location.split(',',2) + wake_up_at_location = raw_wake_up_at_location.split(',',2) lat=float(wake_up_at_location[0]) lng=float(wake_up_at_location[1]) if len(wake_up_at_location) == 3: @@ -133,7 +136,7 @@ def _get_next_sleep_schedule(self): diffs = {} for index in range(len(self.entries)): - diff = (next_time-now).total_seconds() + diff = (times[index]-now).total_seconds() if diff >= 0: diffs[index] = diff closest = min(diffs.iterkeys(), key=lambda x: diffs[x]) From 57896adefeabd82191cecc32b7e3ed617ed482ba Mon Sep 17 00:00:00 2001 From: Gobberwart Date: Wed, 24 Aug 2016 09:36:45 +1000 Subject: [PATCH 014/106] Added cell_worker for inventory update Removed update_web_inventory from init.py and created a new worker UpdateLiveInventory in light of feeback from solderzzc. --- configs/config.json.cluster.example | 5 +++++ configs/config.json.example | 5 +++++ configs/config.json.map.example | 5 +++++ configs/config.json.optimizer.example | 5 +++++ configs/config.json.path.example | 5 +++++ configs/config.json.pokemon.example | 5 +++++ pokemongo_bot/__init__.py | 1 - pokemongo_bot/cell_workers/__init__.py | 3 ++- pokemongo_bot/cell_workers/update_web_inventory.py | 12 ++++++++++++ 9 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 pokemongo_bot/cell_workers/update_web_inventory.py diff --git a/configs/config.json.cluster.example b/configs/config.json.cluster.example index 9e80050c2d..3e4ada0e23 100644 --- a/configs/config.json.cluster.example +++ b/configs/config.json.cluster.example @@ -143,6 +143,11 @@ "spin_wait_max": 5 } }, + { "type": "UpdateWebInventory", + "config": { + "enabled": true + } + }, { "type": "FollowCluster", "config": { diff --git a/configs/config.json.example b/configs/config.json.example index 9cdb09fa79..6e9264594d 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -157,6 +157,11 @@ "spin_wait_max": 5 } }, + { "type": "UpdateWebInventory", + "config": { + "enabled": true + } + }, { "type": "MoveToFort", "config": { diff --git a/configs/config.json.map.example b/configs/config.json.map.example index 1c4d2e9aa0..d3135db055 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -143,6 +143,11 @@ "spin_wait_max": 5 } }, + { "type": "UpdateWebInventory", + "config": { + "enabled": true + } + }, { "type": "MoveToMapPokemon", "config": { diff --git a/configs/config.json.optimizer.example b/configs/config.json.optimizer.example index f15ea77db6..db20d35ce0 100644 --- a/configs/config.json.optimizer.example +++ b/configs/config.json.optimizer.example @@ -207,6 +207,11 @@ "spin_wait_max": 5 } }, + { "type": "UpdateWebInventory", + "config": { + "enabled": true + } + }, { "type": "MoveToFort", "config": { diff --git a/configs/config.json.path.example b/configs/config.json.path.example index 41e01eb85d..c0fd9e0ba3 100644 --- a/configs/config.json.path.example +++ b/configs/config.json.path.example @@ -143,6 +143,11 @@ "spin_wait_max": 5 } }, + { "type": "UpdateWebInventory", + "config": { + "enabled": true + } + }, { "type": "FollowPath", "config": { diff --git a/configs/config.json.pokemon.example b/configs/config.json.pokemon.example index b84d130bda..75268c2b0a 100644 --- a/configs/config.json.pokemon.example +++ b/configs/config.json.pokemon.example @@ -143,6 +143,11 @@ "spin_wait_max": 5 } }, + { "type": "UpdateWebInventory", + "config": { + "enabled": true + } + }, { "type": "MoveToFort", "config":{ diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index a262800367..0a17c8fcf9 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -557,7 +557,6 @@ def _register_events(self): def tick(self): self.health_record.heartbeat() self.cell = self.get_meta_cell() - inventory.update_web_inventory() now = time.time() * 1000 diff --git a/pokemongo_bot/cell_workers/__init__.py b/pokemongo_bot/cell_workers/__init__.py index 66df050917..a8175956fd 100644 --- a/pokemongo_bot/cell_workers/__init__.py +++ b/pokemongo_bot/cell_workers/__init__.py @@ -22,4 +22,5 @@ from update_live_inventory import UpdateLiveInventory from catch_pokemon import CatchPokemon from complete_tutorial import CompleteTutorial -from random_pause import RandomPause \ No newline at end of file +from random_pause import RandomPause +from update_web_inventory import UpdateWebInventory diff --git a/pokemongo_bot/cell_workers/update_web_inventory.py b/pokemongo_bot/cell_workers/update_web_inventory.py new file mode 100644 index 0000000000..02b82128f3 --- /dev/null +++ b/pokemongo_bot/cell_workers/update_web_inventory.py @@ -0,0 +1,12 @@ +from pokemongo_bot.base_task import BaseTask +from pokemongo_bot import inventory + + +class UpdateWebInventory(BaseTask): + SUPPORTED_TASK_API_VERSION = 1 + + def initialize(self): + pass + + def work(self): + inventory.update_web_inventory() From 7d561a97facbcc0cbd795de86b35529a0332670c Mon Sep 17 00:00:00 2001 From: Gobberwart Date: Wed, 24 Aug 2016 09:37:19 +1000 Subject: [PATCH 015/106] Separated update_web_inventory from jsonify_inventory As per feedback from @BriceSD --- pokemongo_bot/inventory.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pokemongo_bot/inventory.py b/pokemongo_bot/inventory.py index 7a7c341fb1..0577b65e20 100644 --- a/pokemongo_bot/inventory.py +++ b/pokemongo_bot/inventory.py @@ -1107,6 +1107,14 @@ def update_web_inventory(self): json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("item", None)] json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("pokemon_data", None)] + json_inventory = json_inventory + self.jsonify_inventory() + + with open(web_inventory, "w") as outfile: + json.dump(json_inventory, outfile) + + def jsonify_inventory(self): + json_inventory = [] + for pokedex in self.pokedex.all(): json_inventory.append({"inventory_item_data": {"pokedex_entry": pokedex}}) @@ -1118,10 +1126,9 @@ def update_web_inventory(self): for pokemon in self.pokemons.all(): json_inventory.append({"inventory_item_data": {"pokemon_data": pokemon._data}}) - - with open(web_inventory, "w") as outfile: - json.dump(json_inventory, outfile) - + + return json_inventory + def retrieve_inventories_size(self): """ Retrieves the item inventory size From ba2c3c07c9094eeae9d9b06b753edd09c38ea899 Mon Sep 17 00:00:00 2001 From: Dmitry Ovodov Date: Wed, 24 Aug 2016 10:14:35 +0300 Subject: [PATCH 016/106] Fix test and a little enhancement --- pokemongo_bot/sleep_schedule.py | 9 ++--- pokemongo_bot/test/sleep_schedule_test.py | 40 +++++++++++------------ 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/pokemongo_bot/sleep_schedule.py b/pokemongo_bot/sleep_schedule.py index 0688846e46..bfa4e044fb 100644 --- a/pokemongo_bot/sleep_schedule.py +++ b/pokemongo_bot/sleep_schedule.py @@ -50,11 +50,12 @@ def work(self): wake_up_at_location = self._wake_up_at_location self._schedule_next_sleep() if wake_up_at_location: - try: - self.bot.api.set_position(wake_up_at_location[0],wake_up_at_location[1],wake_up_at_location[2]) # Expecting error here - self.bot.login() - except AttributeError: # It will happen if bot starts sleeping, in this case api is not initialized yet + if hasattr(self.bot, 'api'): # Check if api is already initialized + self.bot.api.set_position(wake_up_at_location[0],wake_up_at_location[1],wake_up_at_location[2]) + else: self.bot.wake_location = wake_up_at_location + if hasattr(self.bot, 'api'): self.bot.login() # Same here + def _process_config(self, config): self.entries = [] diff --git a/pokemongo_bot/test/sleep_schedule_test.py b/pokemongo_bot/test/sleep_schedule_test.py index 05c35afbb6..a0ace8a35f 100644 --- a/pokemongo_bot/test/sleep_schedule_test.py +++ b/pokemongo_bot/test/sleep_schedule_test.py @@ -1,51 +1,51 @@ import unittest from datetime import timedelta, datetime from mock import patch, MagicMock -from pokemongo_bot.cell_workers.sleep_schedule import SleepSchedule +from pokemongo_bot.sleep_schedule import SleepSchedule from tests import FakeBot class SleepScheculeTestCase(unittest.TestCase): - config = {'time': '12:20', 'duration': '01:05', 'time_random_offset': '00:05', 'duration_random_offset': '00:05'} + config = [{'time': '12:20', 'duration': '01:05', 'time_random_offset': '00:05', 'duration_random_offset': '00:05'}] def setUp(self): self.bot = FakeBot() self.worker = SleepSchedule(self.bot, self.config) def test_config(self): - self.assertEqual(self.worker.time.hour, 12) - self.assertEqual(self.worker.time.minute, 20) - self.assertEqual(self.worker.duration, timedelta(hours=1, minutes=5).total_seconds()) - self.assertEqual(self.worker.time_random_offset, timedelta(minutes=5).total_seconds()) - self.assertEqual(self.worker.duration_random_offset, timedelta(minutes=5).total_seconds()) + self.assertEqual(self.worker.entries[0]['time'].hour, 12) + self.assertEqual(self.worker.entries[0]['time'].minute, 20) + self.assertEqual(self.worker.entries[0]['duration'], timedelta(hours=1, minutes=5).total_seconds()) + self.assertEqual(self.worker.entries[0]['time_random_offset'], timedelta(minutes=5).total_seconds()) + self.assertEqual(self.worker.entries[0]['duration_random_offset'], timedelta(minutes=5).total_seconds()) - @patch('pokemongo_bot.cell_workers.sleep_schedule.datetime') + @patch('pokemongo_bot.sleep_schedule.datetime') def test_get_next_time(self, mock_datetime): mock_datetime.now.return_value = datetime(year=2016, month=8, day=01, hour=8, minute=0) - next_time = self.worker._get_next_sleep_schedule() + next_time = self.worker._get_next_sleep_schedule()[0] from_date = datetime(year=2016, month=8, day=1, hour=12, minute=15) to_date = datetime(year=2016, month=8, day=1, hour=12, minute=25) self.assertGreaterEqual(next_time, from_date) self.assertLessEqual(next_time, to_date) - @patch('pokemongo_bot.cell_workers.sleep_schedule.datetime') + @patch('pokemongo_bot.sleep_schedule.datetime') def test_get_next_time_called_near_activation_time(self, mock_datetime): mock_datetime.now.return_value = datetime(year=2016, month=8, day=1, hour=12, minute=25) - next = self.worker._get_next_sleep_schedule() + next = self.worker._get_next_sleep_schedule()[0] from_date = datetime(year=2016, month=8, day=02, hour=12, minute=15) to_date = datetime(year=2016, month=8, day=02, hour=12, minute=25) self.assertGreaterEqual(next, from_date) self.assertLessEqual(next, to_date) - @patch('pokemongo_bot.cell_workers.sleep_schedule.datetime') + @patch('pokemongo_bot.sleep_schedule.datetime') def test_get_next_time_called_when_this_days_time_passed(self, mock_datetime): mock_datetime.now.return_value = datetime(year=2016, month=8, day=1, hour=14, minute=0) - next = self.worker._get_next_sleep_schedule() + next = self.worker._get_next_sleep_schedule()[0] from_date = datetime(year=2016, month=8, day=02, hour=12, minute=15) to_date = datetime(year=2016, month=8, day=02, hour=12, minute=25) @@ -56,12 +56,12 @@ def test_get_next_duration(self): from_seconds = int(timedelta(hours=1).total_seconds()) to_seconds = int(timedelta(hours=1, minutes=10).total_seconds()) - duration = self.worker._get_next_duration() + duration = self.worker._get_next_duration(self.worker.entries[0]) self.assertGreaterEqual(duration, from_seconds) self.assertLessEqual(duration, to_seconds) - @patch('pokemongo_bot.cell_workers.sleep_schedule.sleep') + @patch('pokemongo_bot.sleep_schedule.sleep') def test_sleep(self, mock_sleep): self.worker._next_duration = SleepSchedule.LOG_INTERVAL_SECONDS * 10 self.worker._sleep() @@ -71,7 +71,7 @@ def test_sleep(self, mock_sleep): for arg in calls: self.assertEqual(arg, SleepSchedule.LOG_INTERVAL_SECONDS) - @patch('pokemongo_bot.cell_workers.sleep_schedule.sleep') + @patch('pokemongo_bot.sleep_schedule.sleep') def test_sleep_not_divedable_by_interval(self, mock_sleep): self.worker._next_duration = SleepSchedule.LOG_INTERVAL_SECONDS * 10 + 5 self.worker._sleep() @@ -83,8 +83,8 @@ def test_sleep_not_divedable_by_interval(self, mock_sleep): #Last call must be 5 self.assertEqual(calls[-1], 5) - @patch('pokemongo_bot.cell_workers.sleep_schedule.sleep') - @patch('pokemongo_bot.cell_workers.sleep_schedule.datetime') + @patch('pokemongo_bot.sleep_schedule.sleep') + @patch('pokemongo_bot.sleep_schedule.datetime') def test_call_work_before_schedule(self, mock_datetime, mock_sleep): self.worker._next_sleep = datetime(year=2016, month=8, day=1, hour=12, minute=0) mock_datetime.now.return_value = self.worker._next_sleep - timedelta(minutes=5) @@ -93,8 +93,8 @@ def test_call_work_before_schedule(self, mock_datetime, mock_sleep): self.assertEqual(mock_sleep.call_count, 0) - @patch('pokemongo_bot.cell_workers.sleep_schedule.sleep') - @patch('pokemongo_bot.cell_workers.sleep_schedule.datetime') + @patch('pokemongo_bot.sleep_schedule.sleep') + @patch('pokemongo_bot.sleep_schedule.datetime') def test_call_work_after_schedule(self, mock_datetime, mock_sleep): self.bot.login = MagicMock() self.worker._next_sleep = datetime(year=2016, month=8, day=1, hour=12, minute=0) From 1fd50322e36b6f76d594b6b0a5e6f262df69218b Mon Sep 17 00:00:00 2001 From: LuckyMe4Evers Date: Wed, 24 Aug 2016 12:28:37 +0200 Subject: [PATCH 017/106] Windows Installer upgraded The PokemonGo-Bot-Installer has been updated with an install log, for finding out troubles with installation and there's also added an option to install the Master or Dev Bot --- windows_bat/PokemonGo-Bot-Install.bat | 420 ++++++++++++++++++-------- 1 file changed, 293 insertions(+), 127 deletions(-) diff --git a/windows_bat/PokemonGo-Bot-Install.bat b/windows_bat/PokemonGo-Bot-Install.bat index 1309a0780c..b744fc4586 100755 --- a/windows_bat/PokemonGo-Bot-Install.bat +++ b/windows_bat/PokemonGo-Bot-Install.bat @@ -1,26 +1,27 @@ TITLE PokemonGo-Bot Installer -CLS -@ECHO OFF +cls +@ECHO Off :init -setlocal EnableDelayedExpansion +SETlocal DisableDelayedExpansion path c:\Program Files\Git\cmd;%PATH% path C:\Python27;%PATH% path C:\Python27\Scripts;%PATH% -set DownPathPython=https://www.python.org/ftp/python/2.7.12/ -set DownPathGit=https://github.com/git-for-windows/git/releases/download/v2.9.3.windows.1/ -set DownPathVisual=https://download.microsoft.com/download/7/9/6/796EF2E4-801B-4FC4-AB28-B59FBF6D907B/ -set VisualFName=VCForPython27.msi -set PythonFName86=python-2.7.12.msi -set PythonFName64=python-2.7.12.amd64.msi -set GitFName86=Git-2.9.3-32-bit.exe -set GitFName64=Git-2.9.3-64-bit.exe -set "batchPath=%~0" -for %%k in (%0) do set batchName=%%~nk -set "vbsGetPrivileges=%temp%\OEgetPriv_%batchName%.vbs" - +SET DownPathPython=https://www.python.org/ftp/python/2.7.12/ +SET DownPathGit=https://github.com/git-for-windows/git/releases/download/v2.9.3.windows.1/ +SET DownPathVisual=https://download.microsoft.com/download/7/9/6/796EF2E4-801B-4FC4-AB28-B59FBF6D907B/ +SET VisualFName=VCForPython27.msi +SET PythonFName86=python-2.7.12.msi +SET PythonFName64=python-2.7.12.amd64.msi +SET GitFName86=Git-2.9.3-32-bit.exe +SET GitFName64=Git-2.9.3-64-bit.exe +SET "batchPath=%~0" +FOR %%k in (%0) do SET batchName=%%~nk +SET log=%~dp0%batchname%.log 2>&1 +SET "vbsGetPrivileges=%temp%\OEgetPriv_%batchName%.vbs" +SETlocal EnableDelayedExpansion :checkPrivileges @@ -30,8 +31,8 @@ if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges ) :getPrivileges -if '%1'=='ELEV' (echo ELEV & shift /1 & goto gotPrivileges) -@ECHO Set UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%" +if '%1'=='ELEV' (ECHO ELEV & shift /1 & goto gotPrivileges) +@ECHO SET UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%" @ECHO args = "ELEV " >> "%vbsGetPrivileges%" @ECHO For Each strArg in WScript.Arguments >> "%vbsGetPrivileges%" @ECHO args = args ^& strArg ^& " " >> "%vbsGetPrivileges%" @@ -43,36 +44,70 @@ exit /B :gotPrivileges -setlocal & pushd . +SETlocal & pushd . cd /d %~dp0 if '%1'=='ELEV' (del "%vbsGetPrivileges%" 1>nul 2>nul & shift /1) :detectOS -reg Query "HKLM\Hardware\Description\System\CentralProcessor\0" | find /i "x86" > NUL && set OS=32-BIT || set OS=64-BIT +reg Query "HKLM\Hardware\Description\System\CentralProcessor\0" | find /i "x86" > NUL && SET OS=32-BIT || SET OS=64-BIT + +ECHO.----- Checking OS Architecture ----->%log% +ECHO.>>%log% +ECHO.The computer has "%OS%" architecture.>>%log% +ECHO.>>%log% :CheckInstallPath -CLS -@ECHO --------------------Installation Path-------------------- -@ECHO. -@ECHO. -@ECHO. -set InstallPath= -set /p InstallPath= "Choose an installation folder or press Enter to close:" ||goto:eof -FOR /F "tokens=1-4 delims=/-. " %%G IN ("%InstallPath%") DO (set InstallPath=%%G\%%H\%%I) -set PGBotPath=%InstallPath%\PokemonGo-Bot -set DownPath=%InstallPath%\Install-Files -if not exist %DownPath% md %DownPath% -if "%~dp0"=="%PGBotPath%\windows_bat\" ( +cls +@ECHO.--------------------Installation Path-------------------- +@ECHO. +@ECHO. +@ECHO. +SET InstallPath= +SET /p InstallPath= "Choose an installation folder (example: C:/Test/) or press Enter to close: " ||goto:eof +ECHO.----- Input Path ----->>%log% +ECHO.>>%log% +ECHO.The input Path is "%InstallPath%">>%log% +ECHO.>>%log% +set InstallPath=%InstallPath:/=\% +ECHO.----- Converted Path ----->>%log% +ECHO.>>%log% +ECHO.The converted Path is "%InstallPath%">>%log% +ECHO.>>%log% +SET PGBotPath=%InstallPath%PokemonGo-Bot +SET DownPath=%InstallPath%Install-Files +ECHO.----- Checking Download Path ----->>%log% +ECHO.>>%log% +IF NOT EXIST %DownPath% ( +ECHO.No download folder "%DownPath%" +) else ( +ECHO.%DownPath% exists +)>>%log% +ECHO.>>%log% +IF NOT EXIST %DownPath% md %DownPath% +ECHO.----- Rechecking Download Path ----->>%log% +ECHO.>>%log% +IF NOT EXIST %DownPath% ( +ECHO.No download folder "%DownPath%" +) else ( +ECHO.%DownPath% exists +)>>%log% +ECHO.>>%log% +if %~dp0==%PGBotPath%\windows_bat\ ( COPY "%PGBotPath%\windows_bat\PokemonGo-Bot-Install.bat" %InstallPath% -CALL "%InstallPath%\PokemonGo-Bot-Install.bat" +CALL "%InstallPath%PokemonGo-Bot-Install.bat" exit. ) ELSE ( -@ECHO Installation Path OK! Proceeding! +@ECHO.Installation Path OK^^! Proceeding^^! ) +ECHO.----- Checking Some Paths ----->>%log% +ECHO.>>%log% +ECHO.BatchPath is "%~dp0">>%log% +ECHO.PokemonGo-Bot Path is "%PGBotPath%">>%log% +ECHO.>>%log% @ECHO. @ECHO. @ECHO. @@ -80,8 +115,8 @@ exit. :Menu -CLS -@ECHO --------------------PokemonGo-Bot Installer-------------------- +cls +@ECHO.--------------------PokemonGo-Bot Installer-------------------- @ECHO. @ECHO. @ECHO. @@ -91,7 +126,9 @@ if "%OS%" == "32-BIT" ( @ECHO. 1 - Install 64-Bit software ) @ECHO. -@ECHO. 2 - Install PokemonGo-Bot +@ECHO. 2 - Install PokemonGo-Bot Master Version (Stable) +@ECHO. +@ECHO. 3 - Install PokemonGo-Bot Development Version (Unstable) @ECHO. @ECHO. @ECHO. @@ -99,39 +136,44 @@ if "%OS%" == "32-BIT" ( :_choice -set _ok= -set /p _ok= Choose an option or press Enter to close: ||goto:eof -if "%OS%" == "32-BIT" IF "%_ok%" == "1" SET CHOICE=32Bit&GOTO :32Bit -if "%OS%" == "64-BIT" IF "%_ok%" == "1" SET CHOICE=64Bit&GOTO :64Bit +SET _ok= +SET /p _ok= Choose an option or press Enter to close: ||goto:eof +IF "%OS%" == "32-BIT" IF "%_ok%" == "1" SET CHOICE=32Bit&GOTO :32Bit +IF "%OS%" == "64-BIT" IF "%_ok%" == "1" SET CHOICE=64Bit&GOTO :64Bit IF "%_ok%" == "2" SET CHOICE=InstallBot&GOTO :InstallBot +IF "%_ok%" == "3" SET CHOICE=InstallBot&GOTO :InstallBot GOTO :_choice :32bit -CLS -@ECHO --------------------Installation of required software-------------------- +ECHO.----- Checking Choice and OS ----->>%log% +ECHO.>>%log% +ECHO.Choice was "%_ok%" installing "%OS%" software>>%log% +ECHO.>>%log% +cls +@ECHO.--------------------Installation of required software-------------------- @ECHO. -@ECHO Downloading Git... -if not exist %DownPath%\%GitFName86% call:getit %DownPathGit% %GitFName86% -@ECHO Downloading Python... -if not exist %DownPath%\%PythonFName86% call:getit %DownPathPython% %PythonFName86% -@ECHO Downloading Visual C++ for Python... -if not exist %DownPath%\%VisualFName% call:getit %DownPathVisual% %VisualFName% -@ECHO Installing Git... -if exist %DownPath%\%GitFName86% call:installit %GitFName86% /SILENT -@ECHO Installing Python... -if exist %DownPath%\%PythonFName86% call:installit %PythonFName86% /quiet -@ECHO Installing Visual C++ for Python... -if exist %DownPath%\%VisualFName% call:installit %VisualFName% /quiet +IF NOT EXIST %DownPath%\%GitFName86% @ECHO.Downloading Git... +IF NOT EXIST %DownPath%\%GitFName86% call:getit %DownPathGit% %GitFName86% +IF NOT EXIST %DownPath%\%PythonFName86% @ECHO.Downloading Python... +IF NOT EXIST %DownPath%\%PythonFName86% call:getit %DownPathPython% %PythonFName86% +IF NOT EXIST %DownPath%\%VisualFName% @ECHO.Downloading Visual C++ for Python... +IF NOT EXIST %DownPath%\%VisualFName% call:getit %DownPathVisual% %VisualFName% +@ECHO.Installing Python... +IF EXIST %DownPath%\%PythonFName86% call:installit %PythonFName86% /quiet +@ECHO.Installing Git... +IF EXIST %DownPath%\%GitFName86% call:installit %GitFName86% /SILENT +@ECHO.Installing Visual C++ for Python... +IF EXIST %DownPath%\%VisualFName% call:installit %VisualFName% /quiet @ECHO. @ECHO. @ECHO. -@ECHO Installation of 32-Bit software is finished. +@ECHO.Installation of 32-Bit software is finished. @ECHO. -@ECHO Choose Install PokemonGo-Bot in next screen to complete. +@ECHO.Choose Install PokemonGo-Bot in next screen to complete. @ECHO. -@ECHO Wait 5 seconds or press any key to continue... +@ECHO.Wait 5 seconds or press any key to continue... @ECHO. @ECHO. @ECHO. @@ -141,29 +183,33 @@ goto:Menu :64bit -CLS -@ECHO --------------------Installation of required software-------------------- +ECHO.----- Checking Choice and OS ----->>%log% +ECHO.>>%log% +ECHO.Choice was "%_ok%" installing "%OS%" software>>%log% +ECHO.>>%log% +cls +@ECHO.--------------------Installation of required software-------------------- @ECHO. -@ECHO Downloading Git... -if not exist %DownPath%\%GitFName64% call:getit %DownPathGit% %GitFName64% -@ECHO Downloading Python... -if not exist %DownPath%\%PythonFName64% call:getit %DownPathPython% %PythonFName64% -@ECHO Downloading Visual C++ for Python... -if not exist %DownPath%\%VisualFName% call:getit %DownPathVisual% %VisualFName% -@ECHO Installing Git... -if exist %DownPath%\%GitFName64% call:installit %GitFName64% /SILENT -@ECHO Installing Python... -if exist %DownPath%\%PythonFName64% call:installit %PythonFName64% /quiet -@ECHO Installing Visual C++ for Python... -if exist %DownPath%\%VisualFName% call:installit %VisualFName% /quiet +IF NOT EXIST %DownPath%\%GitFName64% @ECHO.Downloading Git... +IF NOT EXIST %DownPath%\%GitFName64% call:getit %DownPathGit% %GitFName64% +IF NOT EXIST %DownPath%\%PythonFName64% @ECHO.Downloading Python... +IF NOT EXIST %DownPath%\%PythonFName64% call:getit %DownPathPython% %PythonFName64% +IF NOT EXIST %DownPath%\%VisualFName% @ECHO.Downloading Visual C++ for Python... +IF NOT EXIST %DownPath%\%VisualFName% call:getit %DownPathVisual% %VisualFName% +@ECHO.Installing Python... +IF EXIST %DownPath%\%PythonFName64% call:installit %PythonFName64% /quiet +@ECHO.Installing Git... +IF EXIST %DownPath%\%GitFName64% call:installit %GitFName64% /SILENT +@ECHO.Installing Visual C++ for Python... +IF EXIST %DownPath%\%VisualFName% call:installit %VisualFName% /quiet @ECHO. @ECHO. @ECHO. -@ECHO Installation of 64-Bit software is finished. +@ECHO.Installation of 64-Bit software is finished. @ECHO. -@ECHO Choose Install PokemonGo-Bot in next screen to complete. +@ECHO.Choose Install PokemonGo-Bot in next screen to complete. @ECHO. -@ECHO Wait 5 seconds or press any key to continue... +@ECHO.Wait 5 seconds or press any key to continue... @ECHO. @ECHO. @ECHO. @@ -173,93 +219,213 @@ goto:Menu :getit +ECHO.----- Checking Program Downloading ----->>%log% +ECHO.>>%log% +ECHO.Downloading "%~1%~2" to "%DownPath%\%~2">>%log% +ECHO.>>%log% start /wait powershell -Command "Invoke-WebRequest %~1%~2 -OutFile %DownPath%\%~2" goto:eof :installit +ECHO.----- Checking Program Installing ----->>%log% +ECHO.>>%log% +ECHO.Installing "%DownPath%\%~1 %~2">>%log% +ECHO.>>%log% start /wait %DownPath%\%~1 %~2 goto:eof :InstallBot -CLS -@ECHO --------------------Creating Backup-------------------- -@ECHO. -@ECHO. -@ECHO. -if exist %PGBotPath%\encrypt.so COPY %PGBotPath%\encrypt.so %DownPath% -if exist %PGBotPath%\encrypt.dll COPY %PGBotPath%\encrypt.dll %DownPath% -if exist %PGBotPath%\encrypt_64.dll COPY %PGBotPath%\encrypt_64.dll %DownPath% -if exist %PGBotPath%\configs\config.json COPY %PGBotPath%\configs\config.json %DownPath% -if exist %PGBotPath%\web\config\userdata.js COPY %PGBotPath%\web\config\userdata.js %DownPath% +ECHO.----- Checking Choice and Bot Installing ----->>%log% +ECHO.>>%log% +ECHO.Choice was "%_ok%" installing Bot>>%log% +ECHO.>>%log% +cls +@ECHO.--------------------Creating Backup-------------------- +@ECHO. +@ECHO. +@ECHO. +ECHO.----- Checking Creating Backup ----->>%log% +ECHO.>>%log% +IF EXIST %PGBotPath%\encrypt.so ( +ECHO.Copying "%PGBotPath%\encrypt.so" to %DownPath%>>%log% +COPY %PGBotPath%\encrypt.so %DownPath%>>%log% +) else ( +ECHO.No "%PGBotPath%\encrypt.so">>%log% +) +IF EXIST %PGBotPath%\encrypt.dll ( +ECHO.Copying %PGBotPath%\encrypt.dll to %DownPath%>>%log% +COPY %PGBotPath%\encrypt.dll %DownPath%>>%log% +) else ( +ECHO.No "%PGBotPath%\encrypt.dll">>%log% +) +IF EXIST %PGBotPath%\encrypt_64.dll ( +ECHO.Copying "%PGBotPath%\encrypt_64.dll" to %DownPath%>>%log% +COPY %PGBotPath%\encrypt_64.dll %DownPath%>>%log% +) else ( +ECHO.No "%PGBotPath%\encrypt_64.dll">>%log% +) +IF EXIST %PGBotPath%\configs\config.json ( +ECHO.Copying "%PGBotPath%\configs\config.json" to %DownPath%>>%log% +COPY %PGBotPath%\configs\config.json %DownPath%>>%log% +) else ( +ECHO.No "%PGBotPath%\configs\config.json">>%log% +) +IF EXIST %PGBotPath%\web\config\userdata.js ( +ECHO.Copying "%PGBotPath%\web\config\userdata.js" to %DownPath%>>%log% +COPY %PGBotPath%\web\config\userdata.js %DownPath%>>%log% +) else ( +ECHO.No "%PGBotPath%\web\config\userdata.js">>%log% +) +ECHO.>>%log% +cls @ECHO. @ECHO. @ECHO. -@ECHO --------------------Downloading PokemonGo-Bot-------------------- +@ECHO.--------------------Downloading PokemonGo-Bot-------------------- @ECHO. @ECHO. @ECHO. -if exist %PGBotPath% rmdir %PGBotPath% /s /q +ECHO. Be patience... We are working hard to download and install the PokemonGo-Bot. +ECHO.----- Checking Removing Bot Folder ----->>%log% +ECHO.>>%log% +IF EXIST %PGBotPath% rmdir %PGBotPath% /s /q +IF EXIST %PGBotPath% ( +ECHO.Problem %PGBotPath% still exists +) else ( +ECHO.%PGBotPath% is removed +)>>%log% +ECHO.>>%log% +ECHO.----- Checking pip2 install or upgrade ----->>%log% +ECHO.>>%log% +pip2 install --upgrade pip>>%log% +pip2 install --upgrade virtualenv>>%log% +ECHO.>>%log% cd C:\Python27\ -pip2 install --upgrade pip -pip2 install --upgrade virtualenv -git clone --recursive -b master https://github.com/PokemonGoF/PokemonGo-Bot %PGBotPath% -pip2 install -r %PGBotPath%\requirements.txt -@ECHO. -@ECHO. -@ECHO. -@ECHO --------------------Restoring Backup-------------------- -@ECHO. -@ECHO. -@ECHO. -if exist %~dp0\encrypt.so COPY %~dp0\encrypt.so %PGBotPath% -if exist %~dp0\encrypt.dll COPY %~dp0\encrypt.dll %PGBotPath% -if exist %~dp0\encrypt_64.dll COPY %~dp0\encrypt_64.dll %PGBotPath% -if exist %~dp0\config.json COPY %~dp0\config.json %PGBotPath%\configs\ -if exist %~dp0\userdata.js COPY %~dp0\userdata.js %PGBotPath%\web\config\ -if exist %DownPath%\encrypt.so COPY %DownPath%\encrypt.so %PGBotPath% -if exist %DownPath%\encrypt.dll COPY %DownPath%\encrypt.dll %PGBotPath% -if exist %DownPath%\encrypt_64.dll COPY %DownPath%\encrypt_64.dll %PGBotPath% -if exist %DownPath%\config.json COPY %DownPath%\config.json %PGBotPath%\configs\ -if exist %DownPath%\userdata.js COPY %DownPath%\userdata.js %PGBotPath%\web\config\ +ECHO. +ECHO.>>%log% +ECHO.----- Checking Clone installed ----->>%log% +ECHO.>>%log% +if "%_ok%" == "2" ECHO. Install Bot choice was Master>>%log% +if "%_ok%" == "2" git clone --recursive -b master https://github.com/PokemonGoF/PokemonGo-Bot %PGBotPath%>>%log% +if "%_ok%" == "3" ECHO. Install Bot choice was Development>>%log% +if "%_ok%" == "3" git clone --recursive -b dev https://github.com/PokemonGoF/PokemonGo-Bot %PGBotPath%>>%log% +ECHO.>>%log% +IF EXIST %PGBotPath% ECHO.%PGBotPath% has been made>>%log% +ECHO.>>%log% +ECHO.----- Checking second pip2 install or upgrade ----->>%log% +ECHO.>>%log% +pip2 install -r %PGBotPath%\requirements.txt>>%log% +ECHO.>>%log% +@ECHO. +@ECHO. +@ECHO. +@ECHO.--------------------Restoring Backup-------------------- +@ECHO. +@ECHO. +@ECHO. +ECHO.----- Checking Restoring Backup ----->>%log% +ECHO.>>%log% +IF EXIST %~dp0encrypt.so ( +ECHO.Copying %~dp0encrypt.so to %PGBotPath%>>%log% +COPY %~dp0encrypt.so %PGBotPath%>>%log% +) else ( +ECHO.No "%~dp0encrypt.so">>%log% +) +IF EXIST %~dp0encrypt.dll ( +ECHO.Copying %~dp0encrypt.dll to %PGBotPath%>>%log% +COPY %~dp0encrypt.dll %PGBotPath%>>%log% +) else ( +ECHO.No "%~dp0encrypt.dll">>%log% +) +IF EXIST %~dp0encrypt_64.dll ( +ECHO.Copying %~dp0encrypt_64.dll to %PGBotPath%>>%log% +COPY %~dp0encrypt_64.dll %PGBotPath%>>%log% +) else ( +ECHO.No "%~dp0encrypt_64.dll">>%log% +) +IF EXIST %~dp0config.json ( +ECHO.Copying %~dp0config.json to %PGBotPath%\configs\>>%log% +COPY %~dp0config.json %PGBotPath%\configs\>>%log% +) else ( +ECHO.No "%~dp0config.json">>%log% +) +IF EXIST %~dp0userdata.js ( +ECHO.Copying %~dp0userdata.js to %PGBotPath%\web\config\>>%log% +COPY %~dp0userdata.js %PGBotPath%\web\config\>>%log% +) else ( +ECHO.No "%~dp0userdata.js">>%log% +) +IF EXIST %DownPath%\encrypt.so ( +ECHO.Copying %DownPath%\encrypt.so to %PGBotPath%>>%log% +COPY %DownPath%\encrypt.so %PGBotPath%>>%log% +) else ( +ECHO.No "%DownPath%\encrypt.so">>%log% +) +IF EXIST %DownPath%\encrypt.dll ( +ECHO.Copying %DownPath%\encrypt.dll to %PGBotPath%>>%log% +COPY %DownPath%\encrypt.dll %PGBotPath%>>%log% +) else ( +ECHO.No "%DownPath%\encrypt.dll">>%log% +) +IF EXIST %DownPath%\encrypt_64.dll ( +ECHO.Copying %DownPath%\encrypt_64.dll to %PGBotPath%>>%log% +COPY %DownPath%\encrypt_64.dll %PGBotPath%>>%log% +) else ( +ECHO.No "%DownPath%\encrypt_64.dll">>%log% +) +IF EXIST %DownPath%\config.json ( +ECHO.Copying %DownPath%\config.json to %PGBotPath%\configs\>>%log% +COPY %DownPath%\config.json %PGBotPath%\configs\>>%log% +) else ( +ECHO.No "%DownPath%\config.json">>%log% +) +IF EXIST %DownPath%\userdata.js ( +ECHO.Copying %DownPath%\userdata.js to %PGBotPath%\web\config\>>%log% +COPY %DownPath%\userdata.js %PGBotPath%\web\config\>>%log% +) else ( +ECHO.No "%DownPath%\userdata.js">>%log% +) @ECHO. @ECHO. @ECHO. - - +ECHO.>>%Log% +ECHO. ----- End Log ----->>%log% :FinalInstructions -CLS -@ECHO --------------------File customization-------------------- +cls +@ECHO.--------------------File customization-------------------- @ECHO. @ECHO. @ECHO. -@ECHO Before starting the bot, please copy the following files to %PGBotPath% if you dont have them yet. +@ECHO.Before starting the bot, please copy the following files to %PGBotPath% if you dont have them yet. @ECHO. @ECHO. -@ECHO. -@ECHO ---- encrypt.so / encrypt.dll or encrypt_64.dll -@ECHO Get them from our Slack chat! -@ECHO "https://pokemongo-bot.herokuapp.com/" -@ECHO. +IF NOT EXIST %PGBotPath%\encrypt*.* ( +@ECHO.---- encrypt.so / encrypt.dll or encrypt_64.dll +@ECHO. Get them from our Slack chat^^! +@ECHO. "https://pokemongo-bot.herokuapp.com/" +) else ( +ECHO. +) @ECHO. @ECHO. -@ECHO Remember to configure both config.json and userdata.js! +@ECHO.Remember to configure both config.json and userdata.js^^! @ECHO. @ECHO. @ECHO. -@ECHO "%PGBotPath%\configs\config.json" -@ECHO INSTRUCTIONS: -@ECHO "https://github.com/PokemonGoF/PokemonGo-Bot/blob/master/docs/configuration_files.md" +@ECHO."%PGBotPath%\configs\config.json" +@ECHO.INSTRUCTIONS: +@ECHO."https://github.com/PokemonGoF/PokemonGo-Bot/blob/master/docs/configuration_files.md" @ECHO. -@ECHO "%PGBotPath%\web\config\userdata.js" -@ECHO INSTRUCTIONS: -@ECHO "https://github.com/PokemonGoF/PokemonGo-Bot/blob/master/docs/google_map.md" +@ECHO."%PGBotPath%\web\config\userdata.js" +@ECHO.INSTRUCTIONS: +@ECHO."https://github.com/PokemonGoF/PokemonGo-Bot/blob/master/docs/google_map.md" @ECHO. -@ECHO To get an Google Maps API Key: -@ECHO "https://developers.google.com/maps/documentation/javascript/get-api-key" +@ECHO.To get an Google Maps API Key: +@ECHO."https://developers.google.com/maps/documentation/javascript/get-api-key" @ECHO. @ECHO. @ECHO. @@ -269,4 +435,4 @@ CLS :eof ENDLOCAL -exit +exit \ No newline at end of file From 8f0a0a7dec0751aaafe1cfd3f3e7197597afe5a8 Mon Sep 17 00:00:00 2001 From: Pierre Le Gallo Date: Wed, 24 Aug 2016 21:17:33 +0200 Subject: [PATCH 018/106] Patch to update_live_stats to incorpore XP per level XP is now in a json file in data directory test file update_live_stats_test.py to reflect chnage in calculation --- data/xp_per_level.json | 41 +++++++++++ .../cell_workers/update_live_stats.py | 72 +++++++++++++++++-- tests/update_live_stats_test.py | 11 +-- 3 files changed, 112 insertions(+), 12 deletions(-) create mode 100644 data/xp_per_level.json diff --git a/data/xp_per_level.json b/data/xp_per_level.json new file mode 100644 index 0000000000..d603f89f71 --- /dev/null +++ b/data/xp_per_level.json @@ -0,0 +1,41 @@ +[ +[1, 0, 0], +[2, 1000, 1000], +[3, 2000, 3000], +[4, 3000, 6000], +[5, 4000, 10000], +[6, 5000, 15000], +[7, 6000, 21000], +[8, 7000, 28000], +[9, 8000, 36000], +[10, 9000, 45000], +[11, 10000, 55000], +[12, 10000, 65000], +[13, 10000, 75000], +[14, 10000, 85000], +[15, 15000, 100000], +[16, 20000, 120000], +[17, 20000, 140000], +[18, 20000, 160000], +[19, 25000, 185000], +[20, 25000, 210000], +[21, 50000, 260000], +[22, 75000, 335000], +[23, 100000, 435000], +[24, 125000, 560000], +[25, 150000, 710000], +[26, 190000, 900000], +[27, 200000, 1100000], +[28, 250000, 1350000], +[29, 300000, 1650000], +[30, 350000, 2000000], +[31, 500000, 2500000], +[32, 500000, 3000000], +[33, 750000, 3750000], +[34, 1000000, 4750000], +[35, 1250000, 6000000], +[36, 1500000, 7500000], +[37, 2000000, 9500000], +[38, 2500000, 12000000], +[39, 3000000, 15000000], +[40, 5000000, 20000000]] diff --git a/pokemongo_bot/cell_workers/update_live_stats.py b/pokemongo_bot/cell_workers/update_live_stats.py index b903244c47..c50704203c 100644 --- a/pokemongo_bot/cell_workers/update_live_stats.py +++ b/pokemongo_bot/cell_workers/update_live_stats.py @@ -6,6 +6,8 @@ from pokemongo_bot.worker_result import WorkerResult from pokemongo_bot.tree_config_builder import ConfigException +# XP file +import json class UpdateLiveStats(BaseTask): """ @@ -62,6 +64,8 @@ class UpdateLiveStats(BaseTask): """ SUPPORTED_TASK_API_VERSION = 1 + global xp_per_level + def __init__(self, bot, config): """ Initializes the worker. @@ -81,6 +85,64 @@ def __init__(self, bot, config): self.bot.event_manager.register_event('log_stats', parameters=('stats', 'stats_raw')) + # init xp_per_level + global xp_per_level + # If xp_level file exists, load variables from json + # file name should not be hard coded either + xpfile = "data/xp_per_level.json" + try: + with open(xpfile, 'rb') as data: + xp_per_level = json.load(data) + except ValueError: + # log somme warning message + self.emit_event( + 'log_stats', + level='info', + formatted="Unable to read XP level file" + ) + # load default valuesto supplement unknown current_level_xp + xp_per_level = [[1, 0, 0], + [2, 1000, 1000], + [3, 2000, 3000], + [4, 3000, 6000], + [5, 4000, 10000], + [6, 5000, 15000], + [7, 6000, 21000], + [8, 7000, 28000], + [9, 8000, 36000], + [10, 9000, 45000], + [11, 10000, 55000], + [12, 10000, 65000], + [13, 10000, 75000], + [14, 10000, 85000], + [15, 15000, 100000], + [16, 20000, 120000], + [17, 20000, 140000], + [18, 20000, 160000], + [19, 25000, 185000], + [20, 25000, 210000], + [21, 50000, 260000], + [22, 75000, 335000], + [23, 100000, 435000], + [24, 125000, 560000], + [25, 150000, 710000], + [26, 190000, 900000], + [27, 200000, 1100000], + [28, 250000, 1350000], + [29, 300000, 1650000], + [30, 350000, 2000000], + [31, 500000, 2500000], + [32, 500000, 3000000], + [33, 750000, 3750000], + [34, 1000000, 4750000], + [35, 1250000, 6000000], + [36, 1500000, 7500000], + [37, 2000000, 9500000], + [38, 2500000, 12000000], + [39, 3000000, 15000000], + [40, 5000000, 20000000]] + + def initialize(self): pass @@ -173,13 +235,9 @@ def _update_title(self, title, platform): self._compute_next_update() - # hard coded values to supplement unknown current_level_xp - global xp_per_level - xp_per_level = [[0, 0], [1000, 1000], [2000, 3000], [3000, 6000], [4000, 10000], [5000, 15000], [6000, 21000], [7000, 28000], [8000, 36000], [9000, 45000], [10000, 55000], [10000, 65000], [10000, 75000], [10000, 85000], [15000, 100000], [20000, 120000], [20000, 140000], [20000, 160000], [25000, 185000], [25000, 210000], [50000, 260000], [75000, 335000], [100000, 435000], [125000, 560000], [150000, 710000], [190000, 900000], [200000, 1100000], [250000, 1350000], [300000, 1650000], [350000, 2000000], [500000, 2500000], [500000, 3000000], [750000, 3750000], [1000000, 4750000], [1250000, 6000000], [1500000, 7500000], [2000000, 9500000], [2500000, 12000000], [3000000, 15000000], [5000000, 20000000]] - def _get_stats(self, player_stats): - global xp_per_level + global xp_per_level metrics = self.bot.metrics metrics.capture_stats() runtime = metrics.runtime() @@ -188,7 +246,7 @@ def _get_stats(self, player_stats): username = player_data.get('username', '?') distance_travelled = metrics.distance_travelled() current_level = int(player_stats.get('level', 0)) - prev_level_xp = int(xp_per_level[current_level-1][1]) + prev_level_xp = int(xp_per_level[current_level-1][2]) next_level_xp = int(player_stats.get('next_level_xp', 0)) experience = player_stats.get('experience', 0) current_level_xp = experience - prev_level_xp @@ -269,7 +327,7 @@ def _get_stats_line(self, player_stats): username = player_data.get('username', '?') distance_travelled = metrics.distance_travelled() current_level = int(player_stats.get('level', 0)) - prev_level_xp = int(xp_per_level[current_level-1][1]) + prev_level_xp = int(xp_per_level[current_level-1][2]) next_level_xp = int(player_stats.get('next_level_xp', 0)) experience = int(player_stats.get('experience', 0)) current_level_xp = experience - prev_level_xp diff --git a/tests/update_live_stats_test.py b/tests/update_live_stats_test.py index 796be0afc7..fe82d73d16 100644 --- a/tests/update_live_stats_test.py +++ b/tests/update_live_stats_test.py @@ -17,11 +17,12 @@ class UpdateLiveStatsTestCase(unittest.TestCase): 'terminal_log': True, 'terminal_title': False } + # updated to account for XP levels player_stats = { 'level': 25, - 'prev_level_xp': 1250000, - 'next_level_xp': 1400000, - 'experience': 1337500 + 'prev_level_xp': 710000, + 'next_level_xp': 900000, + 'experience': 753700 } def setUp(self): @@ -175,8 +176,8 @@ def test_get_stats_line(self): expected = 'Login | Username | Evolved 12 pokemon | Encountered 130 pokemon | ' \ 'Uptime : 15:42:13 | Caught 120 pokemon | Visited 220 stops | ' \ '42.05km walked | Level 25 | Earned 24,069 Stardust | ' \ - '87,500 / 150,000 XP (58%) | 1,337 XP/h | Threw 145 pokeballs | ' \ - 'Highest CP pokemon : highest_cp | Level 25 (87,500 / 150,000, 58%) | ' \ + '43,700 / 190,000 XP (23%) | 1,337 XP/h | Threw 145 pokeballs | ' \ + 'Highest CP pokemon : highest_cp | Level 25 (43,700 / 190,000, 23%) | ' \ '+424,242 XP | Encountered 3 new pokemon | ' \ 'Most perfect pokemon : most_perfect | ' \ 'Encountered 130 pokemon, 120 caught, 30 released, 12 evolved, ' \ From e9c391cefffa3c651e7404c24638146179c74204 Mon Sep 17 00:00:00 2001 From: Dmitry Ovodov Date: Thu, 25 Aug 2016 01:00:19 +0300 Subject: [PATCH 019/106] Added colored output for RandomAlivePause --- pokemongo_bot/event_handlers/colored_logging_handler.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pokemongo_bot/event_handlers/colored_logging_handler.py b/pokemongo_bot/event_handlers/colored_logging_handler.py index 8fe8559dc7..6fe921e15a 100644 --- a/pokemongo_bot/event_handlers/colored_logging_handler.py +++ b/pokemongo_bot/event_handlers/colored_logging_handler.py @@ -37,6 +37,7 @@ class ColoredLoggingHandler(EventHandler): 'next_egg_incubates': 'yellow', 'next_sleep': 'green', 'next_random_pause': 'green', + 'next_random_alive_pause': 'green', 'no_pokeballs': 'red', 'pokemon_appeared': 'yellow', 'pokemon_capture_failed': 'red', @@ -69,6 +70,7 @@ class ColoredLoggingHandler(EventHandler): 'arrived_at_fort': 'white', 'bot_sleep': 'white', 'bot_random_pause': 'white', + 'bot_random_alive_pause': 'white', 'catchable_pokemon': 'white', 'found_cluster': 'white', 'incubate_try': 'white', From edc15c24c69d67f22b0d9d83e4f6515d112368da Mon Sep 17 00:00:00 2001 From: Loris D'Antonio Date: Thu, 25 Aug 2016 00:35:27 +0200 Subject: [PATCH 020/106] Added new config favorite_locations --- pokecli.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pokecli.py b/pokecli.py index 5a06978029..71f9ef1abe 100644 --- a/pokecli.py +++ b/pokecli.py @@ -587,6 +587,7 @@ def _json_loader(filename): if not config.password and 'password' not in load: config.password = getpass("Password: ") + config.favorite_locations = load.get('favorite_locations', []) config.encrypt_location = load.get('encrypt_location', '') config.catch = load.get('catch', {}) config.release = load.get('release', {}) From 24682b92cfdd4dcad38df811095fed8920a5ae37 Mon Sep 17 00:00:00 2001 From: Loris D'Antonio Date: Thu, 25 Aug 2016 00:43:43 +0200 Subject: [PATCH 021/106] Logic for handling favorite_locations --- pokemongo_bot/__init__.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 7f0047eedd..277e78eb5b 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -1060,6 +1060,12 @@ def _set_starting_position(self): ) def get_pos_by_name(self, location_name): + # Check if given location name, belongs to favorite_locations + favorite_location_coords = self._get_pos_by_fav_location(location_name) + + if favorite_location_coords is not None: + return favorite_location_coords + # Check if the given location is already a coordinate. if ',' in location_name: possible_coordinates = re.findall( @@ -1079,6 +1085,26 @@ def get_pos_by_name(self, location_name): return float(loc.latitude), float(loc.longitude), float(loc.altitude) + def _get_pos_by_fav_location(self, location_name): + + location_name = location_name.lower() + coords = None + + for location in self.config.favorite_locations: + if location.get('name').lower() == location_name: + coords = re.findall( + "[-]?\d{1,3}[.]\d{3,7}", location.get('coords').strip() + ) + if len(coords) >= 2: + self.logger.info('Favorite location found: {} ({})'.format(location_name, coords)) + break + + #TODO: This is real bad + if coords is None: + return coords + else: + return float(coords[0]), float(coords[1]), (float(coords[2]) if len(coords) == 3 else self.alt) + def heartbeat(self): # Remove forts that we can now spin again. now = time.time() From 9c87e8221142e6bd89e239996b1a2290a0c3c1af Mon Sep 17 00:00:00 2001 From: Loris D'Antonio Date: Thu, 25 Aug 2016 00:44:21 +0200 Subject: [PATCH 022/106] Added some test to favorite_locations logic --- tests/location_parser_test.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/location_parser_test.py b/tests/location_parser_test.py index e724adebf8..8718af161c 100644 --- a/tests/location_parser_test.py +++ b/tests/location_parser_test.py @@ -13,9 +13,15 @@ def setUp(self): config = dict( test=False, location='Paris', + favorite_locations=[ + {"name": "Paris", "coords": "23.3333,23.3333"}, + {"name": "Sofia", "coords": "30.000,30.000"} + ], location_cache=False, username='Foobar', ) + self.bot.alt = 8 + self.bot.logger = MagicMock(return_value="") self.bot.updateConfig(config) def test_named_position(self): @@ -24,6 +30,29 @@ def test_named_position(self): self.bot._set_starting_position() self.assertEqual(self.bot.position, position) + def test_find_fav_location(self): + expected_position = (23.3333, 23.3333, 8) + actual_position = self.bot.get_pos_by_name(self.bot.config.location) + self.assertEqual(actual_position, expected_position) + + def test_get_pos_by_fav_location(self): + expected_position = (23.3333,23.3333,8) + actual_position = self.bot._get_pos_by_fav_location(self.bot.config.location) + self.assertEqual(expected_position, actual_position) + + def test_no_favorite_position(self): + result = self.bot._get_pos_by_fav_location("NOT_EXIST") + self.assertEqual(result,None) + + def test_empty_favorite_position(self): + config = dict( + favorite_locations=[], + ) + self.bot.updateConfig(config) + + result = self.bot._get_pos_by_fav_location("Does not matter") + self.assertEqual(result,None) + def test_named_position_utf8(self): position = (42, 42, 0) self.bot.config.location = u"àéùƱǣЊ؍ ข᠃" From dee6e9e92eacd0591b06902b07b8f5c43b868dd6 Mon Sep 17 00:00:00 2001 From: Loris D'Antonio Date: Thu, 25 Aug 2016 00:47:19 +0200 Subject: [PATCH 023/106] Added configuration example --- configs/config.json.cluster.example | 3 +++ configs/config.json.example | 3 +++ configs/config.json.map.example | 3 +++ configs/config.json.optimizer.example | 3 +++ configs/config.json.path.example | 3 +++ configs/config.json.pokemon.example | 3 +++ 6 files changed, 18 insertions(+) diff --git a/configs/config.json.cluster.example b/configs/config.json.cluster.example index 52baa7055b..4cd4a4a6b0 100644 --- a/configs/config.json.cluster.example +++ b/configs/config.json.cluster.example @@ -3,6 +3,9 @@ "username": "YOUR_USERNAME", "password": "YOUR_PASSWORD", "location": "SOME_LOCATION", + "favorite_locations":[ + {"name": "Milan", "coords": "45.472849,9.177567"}, + ], "gmapkey": "GOOGLE_MAPS_API_KEY", "encrypt_location": "", "websocket_server": false, diff --git a/configs/config.json.example b/configs/config.json.example index 29256ebea5..b7da3fa75d 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -3,6 +3,9 @@ "username": "YOUR_USERNAME", "password": "YOUR_PASSWORD", "location": "SOME_LOCATION", + "favorite_locations":[ + {"name": "Milan", "coords": "45.472849,9.177567"}, + ], "gmapkey": "GOOGLE_MAPS_API_KEY", "encrypt_location": "", "websocket_server": false, diff --git a/configs/config.json.map.example b/configs/config.json.map.example index d4abf5e6bb..b93cd93b05 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -3,6 +3,9 @@ "username": "YOUR_USERNAME", "password": "YOUR_PASSWORD", "location": "SOME_LOCATION", + "favorite_locations":[ + {"name": "Milan", "coords": "45.472849,9.177567"}, + ], "gmapkey": "GOOGLE_MAPS_API_KEY", "encrypt_location": "", "websocket_server": false, diff --git a/configs/config.json.optimizer.example b/configs/config.json.optimizer.example index 0e6656ffaa..b9b23b48bc 100644 --- a/configs/config.json.optimizer.example +++ b/configs/config.json.optimizer.example @@ -3,6 +3,9 @@ "username": "YOUR_USERNAME", "password": "YOUR_PASSWORD", "location": "SOME_LOCATION", + "favorite_locations":[ + {"name": "Milan", "coords": "45.472849,9.177567"}, + ], "gmapkey": "GOOGLE_MAPS_API_KEY", "encrypt_location": "", "websocket_server": false, diff --git a/configs/config.json.path.example b/configs/config.json.path.example index a8bf6cb8e2..14e629375d 100644 --- a/configs/config.json.path.example +++ b/configs/config.json.path.example @@ -3,6 +3,9 @@ "username": "YOUR_USERNAME", "password": "YOUR_PASSWORD", "location": "SOME_LOCATION", + "favorite_locations":[ + {"name": "Milan", "coords": "45.472849,9.177567"}, + ], "gmapkey": "GOOGLE_MAPS_API_KEY", "encrypt_location": "", "websocket_server": false, diff --git a/configs/config.json.pokemon.example b/configs/config.json.pokemon.example index df51153b77..8d26343758 100644 --- a/configs/config.json.pokemon.example +++ b/configs/config.json.pokemon.example @@ -3,6 +3,9 @@ "username": "YOUR_USERNAME", "password": "YOUR_PASSWORD", "location": "SOME_LOCATION", + "favorite_locations":[ + {"name": "Milan", "coords": "45.472849,9.177567"}, + ], "gmapkey": "GOOGLE_MAPS_API_KEY", "encrypt_location": "", "websocket_server": false, From 8891d9136433c944a6ad3a754ffc6877e51095fc Mon Sep 17 00:00:00 2001 From: Loris D'Antonio Date: Thu, 25 Aug 2016 00:52:10 +0200 Subject: [PATCH 024/106] Added a note on configuration files --- docs/configuration_files.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/configuration_files.md b/docs/configuration_files.md index d931ee5a7f..b0128ed447 100644 --- a/docs/configuration_files.md +++ b/docs/configuration_files.md @@ -80,6 +80,7 @@ Document the configuration options of PokemonGo-Bot. |`pokemon_bag.show_at_start` | false | At start, bot will show all pokemon in the bag. |`pokemon_bag.show_count` | false | Show amount of each pokemon. |`pokemon_bag.pokemon_info` | [] | Check any config example file to see available settings. +|`favorite_locations` | [] | Allows you to define a collection of locations and coordinates, allowing rapid switch using a "label" on your location config ## Configuring Tasks From dd6e0a16107ad5057a34eb4a17ae6aa5402b1ac5 Mon Sep 17 00:00:00 2001 From: Loris D'Antonio Date: Thu, 25 Aug 2016 01:29:44 +0200 Subject: [PATCH 025/106] Fix JSON Typos --- configs/config.json.cluster.example | 2 +- configs/config.json.example | 2 +- configs/config.json.map.example | 2 +- configs/config.json.optimizer.example | 2 +- configs/config.json.path.example | 2 +- configs/config.json.pokemon.example | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/configs/config.json.cluster.example b/configs/config.json.cluster.example index 4cd4a4a6b0..04ad29b80d 100644 --- a/configs/config.json.cluster.example +++ b/configs/config.json.cluster.example @@ -4,7 +4,7 @@ "password": "YOUR_PASSWORD", "location": "SOME_LOCATION", "favorite_locations":[ - {"name": "Milan", "coords": "45.472849,9.177567"}, + {"name": "Milan", "coords": "45.472849,9.177567"} ], "gmapkey": "GOOGLE_MAPS_API_KEY", "encrypt_location": "", diff --git a/configs/config.json.example b/configs/config.json.example index b7da3fa75d..857ae3cb5a 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -4,7 +4,7 @@ "password": "YOUR_PASSWORD", "location": "SOME_LOCATION", "favorite_locations":[ - {"name": "Milan", "coords": "45.472849,9.177567"}, + {"name": "Milan", "coords": "45.472849,9.177567"} ], "gmapkey": "GOOGLE_MAPS_API_KEY", "encrypt_location": "", diff --git a/configs/config.json.map.example b/configs/config.json.map.example index b93cd93b05..6e6f8e136b 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -4,7 +4,7 @@ "password": "YOUR_PASSWORD", "location": "SOME_LOCATION", "favorite_locations":[ - {"name": "Milan", "coords": "45.472849,9.177567"}, + {"name": "Milan", "coords": "45.472849,9.177567"} ], "gmapkey": "GOOGLE_MAPS_API_KEY", "encrypt_location": "", diff --git a/configs/config.json.optimizer.example b/configs/config.json.optimizer.example index b9b23b48bc..6ee0f93a00 100644 --- a/configs/config.json.optimizer.example +++ b/configs/config.json.optimizer.example @@ -4,7 +4,7 @@ "password": "YOUR_PASSWORD", "location": "SOME_LOCATION", "favorite_locations":[ - {"name": "Milan", "coords": "45.472849,9.177567"}, + {"name": "Milan", "coords": "45.472849,9.177567"} ], "gmapkey": "GOOGLE_MAPS_API_KEY", "encrypt_location": "", diff --git a/configs/config.json.path.example b/configs/config.json.path.example index 14e629375d..e46ea5148e 100644 --- a/configs/config.json.path.example +++ b/configs/config.json.path.example @@ -4,7 +4,7 @@ "password": "YOUR_PASSWORD", "location": "SOME_LOCATION", "favorite_locations":[ - {"name": "Milan", "coords": "45.472849,9.177567"}, + {"name": "Milan", "coords": "45.472849,9.177567"} ], "gmapkey": "GOOGLE_MAPS_API_KEY", "encrypt_location": "", diff --git a/configs/config.json.pokemon.example b/configs/config.json.pokemon.example index 8d26343758..610ab9cc6a 100644 --- a/configs/config.json.pokemon.example +++ b/configs/config.json.pokemon.example @@ -4,7 +4,7 @@ "password": "YOUR_PASSWORD", "location": "SOME_LOCATION", "favorite_locations":[ - {"name": "Milan", "coords": "45.472849,9.177567"}, + {"name": "Milan", "coords": "45.472849,9.177567"} ], "gmapkey": "GOOGLE_MAPS_API_KEY", "encrypt_location": "", From cbd6e8afdcc4e5c14cbb3264629ea4967130a0fa Mon Sep 17 00:00:00 2001 From: Dmitry Ovodov Date: Thu, 25 Aug 2016 02:48:42 +0300 Subject: [PATCH 026/106] Added warning --- pokemongo_bot/tree_config_builder.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pokemongo_bot/tree_config_builder.py b/pokemongo_bot/tree_config_builder.py index a237482fef..03caeba7c8 100644 --- a/pokemongo_bot/tree_config_builder.py +++ b/pokemongo_bot/tree_config_builder.py @@ -48,6 +48,11 @@ def build(self): self.bot.logger.warning('The CatchVisiblePokemon & CatchLuredPokemon tasks have been replaced with ' 'CatchPokemon. CatchPokemon has been enabled with default settings.') + if task_type == 'SleepSchedule': + self.bot.logger.warning('The SleepSchedule task was moved out of the task section. ' + 'See config.json.*example for more information.') + continue + if self._is_plugin_task(task_type): worker = self.plugin_loader.get_class(task_type) else: From daac8bb2d7eb4978d5e2aaa1d9056d3a996b4125 Mon Sep 17 00:00:00 2001 From: Nicholas Date: Thu, 25 Aug 2016 03:11:03 +0300 Subject: [PATCH 027/106] Resolve 4667: Show name of captured pokemons never seen before --- pokecli.py | 4 ++-- pokemongo_bot/metrics.py | 22 ++++++++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/pokecli.py b/pokecli.py index 5a06978029..600ea0449f 100644 --- a/pokecli.py +++ b/pokecli.py @@ -224,9 +224,9 @@ def report_summary(bot): logger.info('Total XP Earned: {} Average: {:.2f}/h'.format(metrics.xp_earned(), metrics.xp_per_hour())) logger.info('Travelled {:.2f}km'.format(metrics.distance_travelled())) logger.info('Visited {} stops'.format(metrics.visits['latest'] - metrics.visits['start'])) - logger.info('Encountered {} pokemon, {} caught, {} released, {} evolved, {} never seen before' + logger.info('Encountered {} pokemon, {} caught, {} released, {} evolved, {} never seen before ({})' .format(metrics.num_encounters(), metrics.num_captures(), metrics.releases, - metrics.num_evolutions(), metrics.num_new_mons())) + metrics.num_evolutions(), metrics.num_new_mons(), metrics.uniq_caught())) logger.info('Threw {} pokeball{}'.format(metrics.num_throws(), '' if metrics.num_throws() == 1 else 's')) logger.info('Earned {} Stardust'.format(metrics.earned_dust())) logger.info('Hatched eggs {}'.format(metrics.hatched_eggs(0))) diff --git a/pokemongo_bot/metrics.py b/pokemongo_bot/metrics.py index 76faeb0728..3e5d479857 100644 --- a/pokemongo_bot/metrics.py +++ b/pokemongo_bot/metrics.py @@ -1,6 +1,6 @@ import time from datetime import timedelta - +from pokemongo_bot.inventory import Pokemons class Metrics(object): @@ -20,9 +20,11 @@ def __init__(self, bot): self.releases = 0 self.highest_cp = {'cp': 0, 'desc': ''} self.most_perfect = {'potential': 0, 'desc': ''} - self.eggs = {'hatched': 0, 'next_hatching_km': 0} + self.uniq_pokemons_caught = None + self.uniq_pokemons_list = None + def runtime(self): return timedelta(seconds=round(time.time() - self.start_time)) @@ -44,6 +46,10 @@ def num_throws(self): def num_captures(self): return self.captures['latest'] - self.captures['start'] + def uniq_caught(self): + # generate pokemon string 'Snorlax, Pikachu' from list of ids + return ', '.join([Pokemons.name_for(pok_id) for pok_id in self.uniq_pokemons_caught]) or '' + def captures_per_hour(self): """ Returns an estimated number of pokemon caught per hour. @@ -95,6 +101,8 @@ def capture_stats(self): request.get_player() response_dict = request.call() try: + uniq_pokemon_list = set() + self.dust['latest'] = response_dict['responses']['GET_PLAYER']['player_data']['currencies'][1]['amount'] if self.dust['start'] < 0: self.dust['start'] = self.dust['latest'] for item in response_dict['responses']['GET_INVENTORY']['inventory_delta']['inventory_items']: @@ -128,6 +136,16 @@ def capture_stats(self): self.evolutions['latest'] = playerdata.get('evolutions', 0) if self.evolutions['start'] < 0: self.evolutions['start'] = self.evolutions['latest'] + elif 'pokedex_entry' in item['inventory_item_data']: + entry = item['inventory_item_data']['pokedex_entry'].get('pokemon_id') + if entry: uniq_pokemon_list.add(entry) + + if not self.uniq_pokemons_list: # make set from pokedex entries on first run + self.uniq_pokemons_list = uniq_pokemon_list + else: + # generate new entries for current bot session + self.uniq_pokemons_caught = uniq_pokemon_list - self.uniq_pokemons_list + except KeyError: # Nothing we can do if there's no player info. return From 4cc56b93daff2a71fb6af35e9179c7e912868c7a Mon Sep 17 00:00:00 2001 From: Simba Zhang Date: Wed, 24 Aug 2016 18:09:03 -0700 Subject: [PATCH 028/106] If don't to share location, go to sea. --- map-chat/javascript/map.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/map-chat/javascript/map.js b/map-chat/javascript/map.js index eae4d88da5..78a0390e65 100644 --- a/map-chat/javascript/map.js +++ b/map-chat/javascript/map.js @@ -33,7 +33,7 @@ var entityMap = { function initialize() { - var defaultLatLng = new google.maps.LatLng(32.078043, 34.774177); // Add the coordinates + var defaultLatLng = new google.maps.LatLng(0.1, 0.1); // Add the coordinates markerImage = { url: 'images/blue_marker.png', @@ -84,7 +84,13 @@ function onPositionUpdate(position) { function onPositionError(err) { // try fallback location provider ipinfo.io or generate random location - $.getJSON("http://ipinfo.io", onFallbackLocationProviderResponse, useRandomLocation); + // $.getJSON("http://ipinfo.io", onFallbackLocationProviderResponse, useRandomLocation); + onFirstPosition({ + "coords": { + latitude: parseFloat(0.1), + longitude: parseFloat(0.1) + } + }); } function onFallbackLocationProviderResponse(ipinfo) { From ab43339d9c570323cc9779ceeb842df9d2344bf8 Mon Sep 17 00:00:00 2001 From: Simba Zhang Date: Wed, 24 Aug 2016 18:45:39 -0700 Subject: [PATCH 029/106] Added back the connected event. --- map-chat/javascript/main.js | 5 ++--- map-chat/javascript/map.js | 6 ++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/map-chat/javascript/main.js b/map-chat/javascript/main.js index 4211dcd1ea..5d89a8d606 100644 --- a/map-chat/javascript/main.js +++ b/map-chat/javascript/main.js @@ -9,10 +9,11 @@ var topic = urlHashTopic ? urlHashTopic : "pgomapcatch/chat"; function initialiseEventBus(){ window.client = mqtt.connect('ws://broker.pikabot.org'); // you add a ws:// url here client.subscribe("pgomapcatch/#"); + client.subscribe("pgochat/chat"); client.on("message", function (topic, payload) { //Materialize.toast(payload, 4000); - if (topic === 'pgomapcatch/chat') { + if (topic === 'pgochat/chat') { displayChatMessageOnMap(payload); Materialize.toast(payload, 5000); @@ -40,8 +41,6 @@ function initialiseEventBus(){ } } }); - - client.publish("pgochat/join", "I just connected to the map!"); } function sendMessage(topic, input) { diff --git a/map-chat/javascript/map.js b/map-chat/javascript/map.js index 78a0390e65..7868964248 100644 --- a/map-chat/javascript/map.js +++ b/map-chat/javascript/map.js @@ -72,6 +72,12 @@ function onFirstPosition(position) { setUserLocation(position.coords.latitude, position.coords.longitude); initialiseEventBus(); map.panTo(userLocation); + var message = {}; + message.lat = position.coords.latitude; + message.lng = position.coords.longitude; + message.text = "I just connected to the map!" + + client.publish("pgochat/chat", JSON.stringify(message)); } function onPositionUpdate(position) { From 745cb3bc493b46afd8644a5bef7b4fb920e8cce9 Mon Sep 17 00:00:00 2001 From: Simba Zhang Date: Wed, 24 Aug 2016 18:51:28 -0700 Subject: [PATCH 030/106] Switch channel. --- map-chat/javascript/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/map-chat/javascript/main.js b/map-chat/javascript/main.js index 5d89a8d606..14821b114b 100644 --- a/map-chat/javascript/main.js +++ b/map-chat/javascript/main.js @@ -68,13 +68,13 @@ $(document).ready(function () { var input = $("#input"); input.keyup(function (e) { if (e.keyCode == 13) { - sendMessage('pgomapcatch/chat', input); + sendMessage('pgochat/chat', input); } }); input.focus(); $("#send-button").click(function () { - sendMessage('pgomapcatch/chat', input); + sendMessage('pgochat/chat', input); }); $("#notification_lever").change(function () { From cc08aac1a0c2578e9d6a2f19cbf6b11dcd0aa23b Mon Sep 17 00:00:00 2001 From: geminiyellow Date: Thu, 25 Aug 2016 12:29:31 +0900 Subject: [PATCH 031/106] fix(map-chat): disable dummy info --- map-chat/javascript/map.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/map-chat/javascript/map.js b/map-chat/javascript/map.js index 7868964248..9e3ed35f3b 100644 --- a/map-chat/javascript/map.js +++ b/map-chat/javascript/map.js @@ -239,7 +239,7 @@ function displayMessageOnMap(msg, olat, olong, sessid, icostr, expir, pokenick) var expiration = expir; var pName = ''; if(typeof pokenick === 'undefined'){ - var pName = " just appeared!
lat: " + olat + " / long: " + olong; + var pName = " just appeared!
lat: " + olat + " / long: " + olong; } else { var pName = "" + pokenick + " just appeared!
lat: " + olat + " / long: " + olong; } @@ -320,9 +320,8 @@ function displayMessageOnMap(msg, olat, olong, sessid, icostr, expir, pokenick) } }); - if (msg.text) { + if (msg.text !== 'undefined') { infoWindow.open(map, marker); - } var timeoutId = setTimeout(function () { infoWindow.close() }, 10000); From 557027d057fe0d4de53f91cafd4c71dc5b44bb8a Mon Sep 17 00:00:00 2001 From: geminiyellow Date: Thu, 25 Aug 2016 13:41:50 +0900 Subject: [PATCH 032/106] fix(map-chat): fix pokemon icon scale --- map-chat/javascript/map.js | 131 +++++++++++++------------------------ 1 file changed, 45 insertions(+), 86 deletions(-) diff --git a/map-chat/javascript/map.js b/map-chat/javascript/map.js index 9e3ed35f3b..55ac5cc11f 100644 --- a/map-chat/javascript/map.js +++ b/map-chat/javascript/map.js @@ -45,7 +45,6 @@ function initialize() { scaledSize: new google.maps.Size(30, 30) }; - var mapOptions = { center: defaultLatLng, zoom: defaultZoom, // The initial zoom level when your map loads (0-20) @@ -135,6 +134,41 @@ function createMessage(text) { text: text }; } + +function setupMarkerAndInfoWindow(msgSessionId, content, position, map, icoOn, icoOff) { + var infoWindow = new google.maps.InfoWindow({ + content: content, + maxWidth: 400, + disableAutoPan: true, + zIndex: infoWindowZIndex + }); + infoWindowZIndex++; + + var marker = new google.maps.Marker({ + position: position, + map: map, + draggable: false, + icon: icoOn, + title: "Click to mute/un-mute User " + msgSessionId + }); + + marker.addListener('click', function () { + if (markersMap[msgSessionId].disabled) { + markersMap[msgSessionId].disabled = false; + marker.setIcon(icoOn); + } else { + markersMap[msgSessionId].disabled = true; + marker.setIcon(icoOff); + infoWindow.close(); + } + }); + + return { + marker: marker, + infoWindow: infoWindow + }; +} + function displayChatMessageOnMap(raw) { var msg = JSON.parse(raw) //console.log(msg) @@ -170,39 +204,15 @@ function displayChatMessageOnMap(raw) { if (existingTimeoutId) { clearTimeout(existingTimeoutId); } - markersMap[msgSessionId].timeoutId = - setTimeout(function () { existingInfoWindow.close() }, 10000); + markersMap[msgSessionId].timeoutId = setTimeout(function () { existingInfoWindow.close() }, 10000); existingInfoWindow.open(map, existingMarker); } } else { // new marker - var infoWindow = new google.maps.InfoWindow({ - content: msg.text, - maxWidth: 400, - disableAutoPan: true, - zIndex: infoWindowZIndex - }); - infoWindowZIndex++; - - var marker = new google.maps.Marker({ - position: newPosition, - map: map, - draggable: false, - icon: markerImage, - title: "Click to mute/un-mute User " + msgSessionId - }); - - marker.addListener('click', function () { - if (markersMap[msgSessionId].disabled) { - markersMap[msgSessionId].disabled = false; - marker.setIcon(markerImage); - } else { - markersMap[msgSessionId].disabled = true; - marker.setIcon(disabledMarkerImage); - infoWindow.close(); - } - }); + var markerWindow = setupMarkerAndInfoWindow(msgSessionId,msg.text, newPosition, map, markerImage, disabledMarkerImage); + var infoWindow = markerWindow.infoWindow; + var marker = markerWindow.marker; - if (msg.text) { + if (msg.text !== 'undefined') { infoWindow.open(map, marker); } @@ -231,7 +241,6 @@ function timeUntil(now, then) { return diff; } - function displayMessageOnMap(msg, olat, olong, sessid, icostr, expir, pokenick) { // @ro: passing values split from incoming payload into two variables for now (lat and long) var newPosition = new google.maps.LatLng(olat, olong); @@ -264,62 +273,12 @@ function displayMessageOnMap(msg, olat, olong, sessid, icostr, expir, pokenick) "$1" ); - if (markersMap[msgSessionId]) { // update existing marker - var infoWindow = new google.maps.InfoWindow({ - content: pName, - maxWidth: 400, - disableAutoPan: true, - zIndex: infoWindowZIndex - }); - infoWindowZIndex++; - - var marker = new google.maps.Marker({ - position: newPosition, - map: map, - draggable: false, - icon: icostr, - icon: { url: icostr, scaledSize: new google.maps.Size(60, 60) }, - title: "Click to mute/un-mute User " + msgSessionId - }); - - marker.addListener('click', function () { - if (markersMap[msgSessionId].disabled) { - markersMap[msgSessionId].disabled = false; - marker.setIcon(icostr); - } else { - markersMap[msgSessionId].disabled = true; - marker.setIcon(disabledMarkerImage); - infoWindow.close(); - } - }); - } else { // new marker - var infoWindow = new google.maps.InfoWindow({ - content: pName, - maxWidth: 400, - disableAutoPan: true, - zIndex: infoWindowZIndex - }); - infoWindowZIndex++; - - var marker = new google.maps.Marker({ - position: newPosition, - map: map, - draggable: false, - icon: { url: icostr, scaledSize: new google.maps.Size(60, 60) }, - title: "Click to mute/un-mute User " + msgSessionId - }); - - marker.addListener('click', function () { - if (markersMap[msgSessionId].disabled) { - markersMap[msgSessionId].disabled = false; - marker.setIcon(icostr); - } else { - markersMap[msgSessionId].disabled = true; - marker.setIcon(icostr); - infoWindow.close(); - } - }); + var icon = { url: icostr, scaledSize: new google.maps.Size(36, 36) }; + var markerMap = setupMarkerAndInfoWindow(msgSessionId, pName, newPosition, map, icon, icon); + var marker = markerMap.marker; + var infoWindow = markerMap.infoWindow; + if (!markersMap[msgSessionId]) { // new marker if (msg.text !== 'undefined') { infoWindow.open(map, marker); } From 720a5f7361407fc4ad87223dadf3772fcc1bc546 Mon Sep 17 00:00:00 2001 From: Ingwar Wirjawan Date: Thu, 25 Aug 2016 12:04:23 +0700 Subject: [PATCH 033/106] fix 4706 (#4710) --- pokemongo_bot/metrics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pokemongo_bot/metrics.py b/pokemongo_bot/metrics.py index 3e5d479857..eff0a29503 100644 --- a/pokemongo_bot/metrics.py +++ b/pokemongo_bot/metrics.py @@ -48,7 +48,7 @@ def num_captures(self): def uniq_caught(self): # generate pokemon string 'Snorlax, Pikachu' from list of ids - return ', '.join([Pokemons.name_for(pok_id) for pok_id in self.uniq_pokemons_caught]) or '' + return ', '.join([Pokemons.name_for(pok_id) for pok_id in self.uniq_pokemons_caught]) if self.uniq_pokemons_caught else '' def captures_per_hour(self): """ From 8e9fe4e067a1bc54b8d5b9854e5f8f6426bd7062 Mon Sep 17 00:00:00 2001 From: =bbiiggppiigg <=bbiiggppiigg@gmail.com> Date: Thu, 25 Aug 2016 15:12:39 +0900 Subject: [PATCH 034/106] update example --- configs/config.json.example | 2 +- pokemongo_bot/__init__.py | 15 +++++++++++++++ .../cell_workers/pokemon_catch_worker.py | 17 +++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/configs/config.json.example b/configs/config.json.example index 52f13e4068..bdb3d58d66 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -248,7 +248,7 @@ "logging_color": true, "daily_catch_limit": 800, "catch": { - "any": {"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or"}, + "any": {"candy_threshold" : 400 ,"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or"}, "// Example of always catching Rattata:": {}, "// Rattata": { "always_catch" : true } }, diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index abd8623930..079c21b492 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -164,6 +164,21 @@ def _register_events(self): self.event_manager.register_event('set_start_location') self.event_manager.register_event('load_cached_location') self.event_manager.register_event('location_cache_ignored') + + # ignore candy above threshold + self.event_manager.register_event( + 'ignore_candy_above_thresold', + parameters=( + 'name', + 'amount', + 'threshold' + ) + ) + + + + + self.event_manager.register_event( 'position_update', parameters=( diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index 8e514cd871..5ed48d227e 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -221,6 +221,23 @@ def _pokemon_matches_config(self, config, pokemon, default_logic='and'): 'iv': False, } + candies = inventory.candies().get(pokemon.pokemon_id).quantity + threshold = pokemon_config.get('candy_threshold', 400) + if( candies > threshold ): + self.emit_event( + 'ignore_candy_above_thresold', + level='info', + formatted='Amount of candies for {name} is {amount}, greater than threshold {threshold}', + data={ + 'name': pokemon.name, + 'amount': candies , + 'threshold' : threshold + } + ) + return False + + + if pokemon_config.get('never_catch', False): return False From ad5829fd66cd8848b0544ab0e1b4037b4dce8d42 Mon Sep 17 00:00:00 2001 From: Matt J Madsen Date: Thu, 25 Aug 2016 01:14:27 -0500 Subject: [PATCH 035/106] Add new pokemon to dex animation delay --- pokemongo_bot/cell_workers/pokemon_catch_worker.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index 8e514cd871..296587c1be 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -78,6 +78,8 @@ def initialize(self): self.catchsim_berry_wait_max = self.catchsim_config.get('berry_wait_max', 3) self.catchsim_changeball_wait_min = self.catchsim_config.get('changeball_wait_min', 2) self.catchsim_changeball_wait_max = self.catchsim_config.get('changeball_wait_max', 3) + self.catchsim_newtodex_wait_min = self.catchsim_config.get('newtodex_wait_min', 20) + self.catchsim_newtodex_wait_max = self.catchsim_config.get('newtodex_wait_max', 30) ############################################################################ @@ -499,6 +501,8 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False): try: inventory.pokemons().add(pokemon) + exp_gain = sum(response_dict['responses']['CATCH_POKEMON']['capture_award']['xp']) + self.emit_event( 'pokemon_caught', formatted='Captured {pokemon}! [CP {cp}] [NCP {ncp}] [Potential {iv}] [{iv_display}] [+{exp} exp]', @@ -508,7 +512,7 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False): 'cp': pokemon.cp, 'iv': pokemon.iv, 'iv_display': pokemon.iv_display, - 'exp': sum(response_dict['responses']['CATCH_POKEMON']['capture_award']['xp']), + 'exp': exp_gain, 'encounter_id': self.pokemon['encounter_id'], 'latitude': self.pokemon['latitude'], 'longitude': self.pokemon['longitude'], @@ -545,6 +549,10 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False): }, outfile) outfile.write('\n') + # if it is a new pokemon to our dex, simulate app animation delay + if exp_gain >= 500: + sleep (randrange(newtodex_wait_min, newtodex_wait_max)) + except IOError as e: self.logger.info('[x] Error while opening location file: %s' % e) From 6ca2a7f4e3faa76bbe327db1d7dd292d7e77a6b3 Mon Sep 17 00:00:00 2001 From: Matt J Madsen Date: Thu, 25 Aug 2016 01:15:40 -0500 Subject: [PATCH 036/106] Added newtodex_wait_min/max --- configs/config.json.cluster.example | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/configs/config.json.cluster.example b/configs/config.json.cluster.example index da847b4663..32067c3520 100644 --- a/configs/config.json.cluster.example +++ b/configs/config.json.cluster.example @@ -147,7 +147,9 @@ "berry_wait_min": 3, "berry_wait_max": 5, "changeball_wait_min": 3, - "changeball_wait_max": 5 + "changeball_wait_max": 5, + "newtodex_wait_min": 20, + "newtodex_wait_max": 30 } } }, From 05083c3c45bfc06be722619145ceacf8d031eb64 Mon Sep 17 00:00:00 2001 From: Matt J Madsen Date: Thu, 25 Aug 2016 01:16:12 -0500 Subject: [PATCH 037/106] Add new pokemon to dex animation delay --- configs/config.json.example | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/configs/config.json.example b/configs/config.json.example index 52f13e4068..be08aa7a67 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -161,7 +161,9 @@ "berry_wait_min": 3, "berry_wait_max": 5, "changeball_wait_min": 3, - "changeball_wait_max": 5 + "changeball_wait_max": 5, + "newtodex_wait_min": 20, + "newtodex_wait_max": 30 } } }, From 4576b3cc91f684e16f92065fce80ad2e29dac743 Mon Sep 17 00:00:00 2001 From: Matt J Madsen Date: Thu, 25 Aug 2016 01:16:54 -0500 Subject: [PATCH 038/106] Add new pokemon to dex animation delay --- configs/config.json.map.example | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/configs/config.json.map.example b/configs/config.json.map.example index 874e759959..9717fca52c 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -147,7 +147,9 @@ "berry_wait_min": 2, "berry_wait_max": 3, "changeball_wait_min": 2, - "changeball_wait_max": 3 + "changeball_wait_max": 3, + "newtodex_wait_min": 20, + "newtodex_wait_max": 30 } } }, From fd11439a4eb907778f3ebba2ce4bc32d304b8f71 Mon Sep 17 00:00:00 2001 From: Matt J Madsen Date: Thu, 25 Aug 2016 01:18:27 -0500 Subject: [PATCH 039/106] Add new pokemon to dex animation delay --- configs/config.json.optimizer.example | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/configs/config.json.optimizer.example b/configs/config.json.optimizer.example index d6680a68f7..315d3bdba2 100644 --- a/configs/config.json.optimizer.example +++ b/configs/config.json.optimizer.example @@ -201,16 +201,18 @@ "normal_rate": 0.1, "spin_success_rate" : 0.6 }, - "catch_simulation": { - "flee_count": 3, - "flee_duration": 2, - "catch_wait_min": 3, - "catch_wait_max": 6, - "berry_wait_min": 3, - "berry_wait_max": 5, - "changeball_wait_min": 3, - "changeball_wait_max": 5 - } + "catch_simulation": { + "flee_count": 3, + "flee_duration": 2, + "catch_wait_min": 3, + "catch_wait_max": 6, + "berry_wait_min": 3, + "berry_wait_max": 5, + "changeball_wait_min": 3, + "changeball_wait_max": 5, + "newtodex_wait_min": 20, + "newtodex_wait_max": 30 + } } }, { From 558c09fea150b6c28428ebc5bb0ba74c596c6c93 Mon Sep 17 00:00:00 2001 From: Matt J Madsen Date: Thu, 25 Aug 2016 01:19:22 -0500 Subject: [PATCH 040/106] Add new pokemon to dex animation delay --- configs/config.json.path.example | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/configs/config.json.path.example b/configs/config.json.path.example index acff64c0bc..305964113d 100644 --- a/configs/config.json.path.example +++ b/configs/config.json.path.example @@ -148,7 +148,9 @@ "berry_wait_min": 3, "berry_wait_max": 5, "changeball_wait_min": 3, - "changeball_wait_max": 5 + "changeball_wait_max": 5, + "newtodex_wait_min": 20, + "newtodex_wait_max": 30 } } }, From 103f2a7086566bfa814177ad1ff8194cbe9b86fb Mon Sep 17 00:00:00 2001 From: Matt J Madsen Date: Thu, 25 Aug 2016 01:21:16 -0500 Subject: [PATCH 041/106] Add new pokemon to dex animation delay --- configs/config.json.pokemon.example | 40 +++++++++++++++-------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/configs/config.json.pokemon.example b/configs/config.json.pokemon.example index 3968270cb0..51793fe2bf 100644 --- a/configs/config.json.pokemon.example +++ b/configs/config.json.pokemon.example @@ -122,10 +122,10 @@ "recycle_force_max": "00:01:00" } }, - { - "type": "CatchPokemon", - "config": { - "enabled": true, + { + "type": "CatchPokemon", + "config": { + "enabled": true, "catch_visible_pokemon": true, "catch_lured_pokemon": true, "min_ultraball_to_keep": 5, @@ -133,22 +133,24 @@ "vip_berry_threshold": 0.9, "treat_unseen_as_vip": true, "catch_throw_parameters": { - "excellent_rate": 0.1, - "great_rate": 0.5, - "nice_rate": 0.3, - "normal_rate": 0.1, - "spin_success_rate" : 0.6 + "excellent_rate": 0.1, + "great_rate": 0.5, + "nice_rate": 0.3, + "normal_rate": 0.1, + "spin_success_rate" : 0.6 }, - "catch_simulation": { - "flee_count": 3, - "flee_duration": 2, - "catch_wait_min": 3, - "catch_wait_max": 6, - "berry_wait_min": 3, - "berry_wait_max": 5, - "changeball_wait_min": 3, - "changeball_wait_max": 5 - } + "catch_simulation": { + "flee_count": 3, + "flee_duration": 2, + "catch_wait_min": 3, + "catch_wait_max": 6, + "berry_wait_min": 3, + "berry_wait_max": 5, + "changeball_wait_min": 3, + "changeball_wait_max": 5, + "newtodex_wait_min": 20, + "newtodex_wait_max": 30 + } } }, { From dad1e26be3137aa8870b94080b33d0140629bbff Mon Sep 17 00:00:00 2001 From: Matt J Madsen Date: Thu, 25 Aug 2016 03:35:33 -0500 Subject: [PATCH 042/106] Fixed variable name --- pokemongo_bot/cell_workers/pokemon_catch_worker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index 296587c1be..cdd98a9c42 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -551,7 +551,7 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False): # if it is a new pokemon to our dex, simulate app animation delay if exp_gain >= 500: - sleep (randrange(newtodex_wait_min, newtodex_wait_max)) + sleep (randrange(catchsim_newtodex_wait_min, catchsim_newtodex_wait_max)) except IOError as e: self.logger.info('[x] Error while opening location file: %s' % e) From 909c367e099f4d2b0b5b321abc10e87bf7fdae21 Mon Sep 17 00:00:00 2001 From: Dmitry Ovodov Date: Thu, 25 Aug 2016 12:59:15 +0300 Subject: [PATCH 043/106] Fix No such file or directory caused by 32f0c5d2969debd2b0b2ba1ebaa0ca6eec49fa0c --- pokemongo_bot/inventory.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/pokemongo_bot/inventory.py b/pokemongo_bot/inventory.py index 0577b65e20..fa2483687d 100644 --- a/pokemongo_bot/inventory.py +++ b/pokemongo_bot/inventory.py @@ -1092,29 +1092,32 @@ def refresh(self): inventory = inventory['responses']['GET_INVENTORY']['inventory_delta']['inventory_items'] for i in (self.pokedex, self.candy, self.items, self.pokemons): i.refresh(inventory) - + self.update_web_inventory() - + def update_web_inventory(self): web_inventory = os.path.join(_base_dir, "web", "inventory-%s.json" % self.bot.config.username) - with open(web_inventory, "r") as infile: - json_inventory = json.load(infile) + if os.path.exists(web_inventory): + with open(web_inventory, "r") as infile: + json_inventory = json.load(infile) + + json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("pokedex_entry", None)] + json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("candy", None)] + json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("item", None)] + json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("pokemon_data", None)] + + json_inventory = json_inventory + self.jsonify_inventory() + else: + json_inventory = self.jsonify_inventory() - json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("pokedex_entry", None)] - json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("candy", None)] - json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("item", None)] - json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("pokemon_data", None)] - - json_inventory = json_inventory + self.jsonify_inventory() - with open(web_inventory, "w") as outfile: json.dump(json_inventory, outfile) def jsonify_inventory(self): json_inventory = [] - + for pokedex in self.pokedex.all(): json_inventory.append({"inventory_item_data": {"pokedex_entry": pokedex}}) From 014438cf85608400ef6316b5d5486493174996d9 Mon Sep 17 00:00:00 2001 From: william dutton Date: Thu, 25 Aug 2016 20:44:13 +1000 Subject: [PATCH 044/106] add event messaging on badge update, include code for equip_badge --- pokemongo_bot/__init__.py | 55 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index abd8623930..7aad2cac26 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -35,6 +35,7 @@ from tree_config_builder import ConfigException, MismatchTaskApiVersion, TreeConfigBuilder from inventory import init_inventory from sys import platform as _platform +from pgoapi.protos.POGOProtos.Enums import BadgeType_pb2 import struct @@ -73,6 +74,7 @@ def __init__(self, config): open(os.path.join(_base_dir, 'data', 'pokemon.json')) ) self.item_list = json.load(open(os.path.join(_base_dir, 'data', 'items.json'))) + # @var Metrics self.metrics = Metrics(self) self.latest_inventory = None self.cell = None @@ -136,6 +138,7 @@ def _setup_event_system(self): if self.config.websocket_remote_control: remote_control = WebsocketRemoteControl(self).start() + # @var EventManager self.event_manager = EventManager(*handlers) self._register_events() if self.config.show_events: @@ -575,6 +578,15 @@ def _register_events(self): self.event_manager.register_event('pokestop_log') self.event_manager.register_event('softban_log') + self.event_manager.register_event( + 'badges', + parameters=('badge', 'level') + ) + self.event_manager.register_event( + 'player_data', + parameters=('player_data', ) + ) + def tick(self): self.health_record.heartbeat() self.cell = self.get_meta_cell() @@ -835,7 +847,7 @@ def get_encryption_lib(self): return full_path def _setup_api(self): - # instantiate pgoapi + # instantiate pgoapi @var ApiWrapper self.api = ApiWrapper(config=self.config) # provide player position on the earth @@ -1147,7 +1159,46 @@ def heartbeat(self): request = self.api.create_request() request.get_player() request.check_awarded_badges() - request.call() + responses = request.call() + + if responses['responses']['GET_PLAYER']['success'] == True: + #we get the player_data anyway, might as well store it + self._player = responses['responses']['GET_PLAYER']['player_data'] + self.event_manager.emit( + 'player_data', + sender=self, + level='debug', + formatted='equipped_badges: {player_data}', + data={'player_data': self._player} + ) + if responses['responses']['CHECK_AWARDED_BADGES']['success'] == True: + #store awarded_badges reponse to be used in a task or part of heartbeat + self._awarded_badges = responses['responses']['CHECK_AWARDED_BADGES'] + + if self._awarded_badges.has_key('awarded_badges'): + #todo: pull out the enum name and put into message + self.event_manager.emit( + 'badges', + sender=self, + level='info', + formatted='awarded badge: {badge}, lvl {level}', + data={'badge': BadgeType_pb2._BADGETYPE.values_by_number[self._awarded_badges['awarded_badges']].name, + 'level' : self._awarded_badges['awarded_badge_levels']} + ) + + #should work but gives errors :'( + #response = self.api.equip_badge(badge_type=self._awarded_badges['awarded_badges']) + response = {'responses' :"awaiting further testing on api call to equip_badge"} + self.event_manager.emit( + 'badges', + sender=self, + level='info', + formatted='equiped badge: {badges}', + data={'badges': response['responses']} + ) + human_behaviour.action_delay(3,10) + + try: self.web_update_queue.put_nowait(True) # do this outside of thread every tick except Queue.Full: From ba0893fd7a927126ea8a46f720d91694fa89127c Mon Sep 17 00:00:00 2001 From: Nikolay Spiridonov Date: Thu, 25 Aug 2016 19:40:16 +0400 Subject: [PATCH 045/106] Update move_to_map_pokemon.py (#4725) Hardcoded get_pokemon_from_social --- pokemongo_bot/cell_workers/move_to_map_pokemon.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index e57cbb5725..bfe02fe88b 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -291,9 +291,11 @@ def work(self): self.update_map_location() self.dump_caught_pokemon() - pokemon_list = self.get_pokemon_from_social() - #Temp works as it, need add more configuration - #pokemon_list = self.get_pokemon_from_map() + if self.bot.config.enable_social: + pokemon_list = self.get_pokemon_from_social() + else: + pokemon_list = self.get_pokemon_from_map() + pokemon_list.sort(key=lambda x: x['dist']) if self.config['mode'] == 'priority': pokemon_list.sort(key=lambda x: x['priority'], reverse=True) From ecfb16a6903d3d4c454f19058ee7de2d2258ad89 Mon Sep 17 00:00:00 2001 From: Walker Lee Date: Fri, 26 Aug 2016 01:14:55 +0800 Subject: [PATCH 046/106] Ignore files in git and docker --- .dockerignore | 10 +++++++++- .gitignore | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.dockerignore b/.dockerignore index b08db7b967..c5726438fb 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,12 @@ .idea .git* **/*config.json -**/*userdata.js \ No newline at end of file +**/*userdata.js +data/caught-*.json +data/cells-*.json +data/deviceid-*.txt +data/last-location-*.json +data/*.db +web/catchable-*.json +web/inventory-*.json +web/location-*.json diff --git a/.gitignore b/.gitignore index 0f969ba7cc..d42bc72861 100644 --- a/.gitignore +++ b/.gitignore @@ -111,6 +111,8 @@ data/last-location*.json data/cells-*.json data/map-caught-*.json data/recent-forts-*.json +data/caught-*.json +data/deviceid-*.txt user_web_catchable # Multiple config From 473240d896b8a4e0adcfe77f9054dc9c4c512a33 Mon Sep 17 00:00:00 2001 From: Simba Zhang Date: Thu, 25 Aug 2016 10:55:54 -0700 Subject: [PATCH 047/106] To allow the real time display info box on pokemon at the time. --- map-chat/javascript/map.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/map-chat/javascript/map.js b/map-chat/javascript/map.js index 55ac5cc11f..8d11d4cb69 100644 --- a/map-chat/javascript/map.js +++ b/map-chat/javascript/map.js @@ -279,9 +279,7 @@ function displayMessageOnMap(msg, olat, olong, sessid, icostr, expir, pokenick) var infoWindow = markerMap.infoWindow; if (!markersMap[msgSessionId]) { // new marker - if (msg.text !== 'undefined') { - infoWindow.open(map, marker); - } + infoWindow.open(map, marker); var timeoutId = setTimeout(function () { infoWindow.close() }, 10000); markersMap[msgSessionId] = { From 9a2eb980a6818cafe6ec5031c35cb15964b5d6b3 Mon Sep 17 00:00:00 2001 From: =bbiiggppiigg <=bbiiggppiigg@gmail.com> Date: Fri, 26 Aug 2016 03:04:21 +0900 Subject: [PATCH 048/106] change default value to false, also make sure that this code is not triggered when threshold is not set thus equals 0 --- pokemongo_bot/cell_workers/pokemon_catch_worker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index 5ed48d227e..1fa2a5f7d2 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -222,8 +222,8 @@ def _pokemon_matches_config(self, config, pokemon, default_logic='and'): } candies = inventory.candies().get(pokemon.pokemon_id).quantity - threshold = pokemon_config.get('candy_threshold', 400) - if( candies > threshold ): + threshold = pokemon_config.get('candy_threshold', False) + if( threshold > 0 and candies > threshold ): self.emit_event( 'ignore_candy_above_thresold', level='info', From 8465a39bade019770d1a0d0a750ac6609c32b69e Mon Sep 17 00:00:00 2001 From: Walker Lee Date: Fri, 26 Aug 2016 02:05:55 +0800 Subject: [PATCH 049/106] Minimize docker image --- Dockerfile | 53 ++++++++++++++++++++++------------------------------- 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/Dockerfile b/Dockerfile index 881fc99981..c9a682cd92 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,43 +12,34 @@ # # docker build --build-arg BUILD_REPO=YourFork/PokemonGo-Bot --build-arg BUILD_BRANCH=6a4580f . -FROM python:2.7.12-alpine +FROM alpine -RUN apk add --update --no-cache alpine-sdk git - -ARG BUILD_BRANCH -ENV BUILD_BRANCH ${BUILD_BRANCH:-master} - -ARG BUILD_REPO -ENV BUILD_REPO ${BUILD_REPO:-PokemonGoF/PokemonGo-Bot} +ARG BUILD_REPO=PokemonGoF/PokemonGo-Bot +ARG BUILD_BRANCH=master +ARG TIMEZONE=Etc/UTC LABEL build_repo=$BUILD_REPO build_branch=$BUILD_BRANCH -ADD https://github.com/$BUILD_REPO/archive/$BUILD_BRANCH.tar.gz . -RUN tar -zxvf $BUILD_BRANCH.tar.gz && mv PokemonGo-Bot-* /usr/src/app && rm $BUILD_BRANCH.tar.gz - WORKDIR /usr/src/app VOLUME ["/usr/src/app/configs", "/usr/src/app/web"] -ARG timezone=Etc/UTC -RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone - -#setup the bot -ADD http://pgoapi.com/pgoencrypt.tar.gz /tmp/ -RUN cd /tmp && tar zxvf pgoencrypt.tar.gz \ - && cd pgoencrypt/src \ - && make \ - && cp libencrypt.so /usr/src/app/encrypt.so \ - && cd /tmp \ - && rm -rf /tmp/pgoencrypt* - -ENV LD_LIBRARY_PATH /usr/src/app - -RUN ln -s /usr/include/locale.h /usr/include/xlocale.h -RUN pip install --no-cache-dir -r requirements.txt - -#remove unused stuff -RUN apk del alpine-sdk\ - && rm -rf /var/cache/apk/* +ADD https://raw.githubusercontent.com/$BUILD_REPO/$BUILD_BRANCH/requirements.txt . +RUN apk -U --no-cache add python py-pip \ + && apk --no-cache add --virtual .build-dependencies python-dev gcc make musl-dev git tzdata \ + && cp -fa /usr/share/zoneinfo/$TIMEZONE /etc/localtime \ + && echo $TIMEZONE > /etc/timezone \ + && wget -q -O- http://pgoapi.com/pgoencrypt.tar.gz | tar zxf - -C /tmp \ + && make -C /tmp/pgoencrypt/src \ + && cp /tmp/pgoencrypt/src/libencrypt.so /usr/src/app/encrypt.so \ + && ln -s locale.h /usr/include/xlocale.h \ + && pip install --no-cache-dir -r requirements.txt \ + && apk del .build-dependencies \ + && rm -rf /var/cache/apk/* /tmp/pgoencrypt /usr/include/xlocale.h \ + && find / -name '*.pyc' -o -name '*.pyo' -exec rm -f {} \; + +RUN apk -U --no-cache add --virtual .install-dependencies wget ca-certificates tar \ + && wget -q -O- https://github.com/$BUILD_REPO/archive/$BUILD_BRANCH.tar.gz | tar zxf - --strip-components=1 -C /usr/src/app \ + && apk del .install-dependencies \ + && rm -rf /var/cache/apk/* ENTRYPOINT ["python", "pokecli.py"] From f642926b018cfc579876b75b1acd03e9260c37d2 Mon Sep 17 00:00:00 2001 From: Alex Yao Date: Thu, 25 Aug 2016 11:16:36 -0700 Subject: [PATCH 050/106] Hotfix for #4714 (#4728) --- pokemongo_bot/cell_workers/pokemon_catch_worker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index cdd98a9c42..18e04adee7 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -551,7 +551,7 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False): # if it is a new pokemon to our dex, simulate app animation delay if exp_gain >= 500: - sleep (randrange(catchsim_newtodex_wait_min, catchsim_newtodex_wait_max)) + sleep (randrange(self.catchsim_newtodex_wait_min, self.catchsim_newtodex_wait_max)) except IOError as e: self.logger.info('[x] Error while opening location file: %s' % e) From c3e1882760da91641c68f66c6a9410299190384d Mon Sep 17 00:00:00 2001 From: Nicholas Date: Thu, 25 Aug 2016 21:25:22 +0300 Subject: [PATCH 051/106] Resolve issue #4227 - MoveToMapPokemon stop catching when VIP --- pokemongo_bot/__init__.py | 1 + pokemongo_bot/cell_workers/move_to_map_pokemon.py | 4 +++- pokemongo_bot/cell_workers/pokemon_catch_worker.py | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 7aad2cac26..2d048970bd 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -100,6 +100,7 @@ def __init__(self, config): self.heartbeat_counter = 0 self.last_heartbeat = time.time() + self.capture_locked = False # lock catching while moving to VIP pokemon def start(self): self._setup_event_system() diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index bfe02fe88b..0fca54c71b 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -325,12 +325,14 @@ def work(self): nearest_fort = self.get_nearest_fort_on_the_way(pokemon) - if nearest_fort is None : + if pokemon['is_vip'] or nearest_fort is None : + self.bot.capture_locked = True # lock catching while moving to vip pokemon or no fort around step_walker = self._move_to(pokemon) if not step_walker.step(): if pokemon['dist'] < Constants.MAX_DISTANCE_POKEMON_IS_REACHABLE: self._encountered(pokemon) + self.bot.capture_locked = False # unlock catch_worker self.add_caught(pokemon) return WorkerResult.SUCCESS else : diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index 18e04adee7..ea62f89f3c 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -241,6 +241,9 @@ def _pokemon_matches_config(self, config, pokemon, default_logic='and'): if pokemon.iv > catch_iv: catch_results['iv'] = True + if self.bot.capture_locked: # seems there is another more preferable pokemon, catching is locked + return False + return LOGIC_TO_FUNCTION[pokemon_config.get('logic', default_logic)](*catch_results.values()) def _should_catch_pokemon(self, pokemon): From d7b47800e033c33f2c2279a90de98f0fb60e6f87 Mon Sep 17 00:00:00 2001 From: Matt J Madsen Date: Thu, 25 Aug 2016 14:41:11 -0500 Subject: [PATCH 052/106] Fix summary for 1st run of fresh acct (#4712) --- pokemongo_bot/metrics.py | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/pokemongo_bot/metrics.py b/pokemongo_bot/metrics.py index eff0a29503..4961a16da6 100644 --- a/pokemongo_bot/metrics.py +++ b/pokemongo_bot/metrics.py @@ -7,15 +7,15 @@ class Metrics(object): def __init__(self, bot): self.bot = bot self.start_time = time.time() - self.dust = {'start': -1, 'latest': -1} - self.xp = {'start': -1, 'latest': -1} - self.distance = {'start': -1, 'latest': -1} - self.encounters = {'start': -1, 'latest': -1} - self.throws = {'start': -1, 'latest': -1} - self.captures = {'start': -1, 'latest': -1} - self.visits = {'start': -1, 'latest': -1} - self.unique_mons = {'start': -1, 'latest': -1} - self.evolutions = {'start': -1, 'latest': -1} + self.dust = {'start': 0, 'latest': 0} + self.xp = {'start': 0, 'latest': 0} + self.distance = {'start': 0, 'latest': 0} + self.encounters = {'start': 0, 'latest': 0} + self.throws = {'start': 0, 'latest': 0} + self.captures = {'start': 0, 'latest': 0} + self.visits = {'start': 0, 'latest': 0} + self.unique_mons = {'start': 0, 'latest': 0} + self.evolutions = {'start': 0, 'latest': 0} self.releases = 0 self.highest_cp = {'cp': 0, 'desc': ''} @@ -111,31 +111,14 @@ def capture_stats(self): playerdata = item['inventory_item_data']['player_stats'] self.xp['latest'] = playerdata.get('experience', 0) - if self.xp['start'] < 0: self.xp['start'] = self.xp['latest'] - self.visits['latest'] = playerdata.get('poke_stop_visits', 0) - if self.visits['start'] < 0: self.visits['start'] = self.visits['latest'] - self.captures['latest'] = playerdata.get('pokemons_captured', 0) - if self.captures['start'] < 0: self.captures['start'] = self.captures['latest'] - self.distance['latest'] = playerdata.get('km_walked', 0) - if self.distance['start'] < 0: self.distance['start'] = self.distance['latest'] - self.encounters['latest'] = playerdata.get('pokemons_encountered', 0) - if self.encounters['start'] < 0: self.encounters['start'] = self.encounters['latest'] - self.throws['latest'] = playerdata.get('pokeballs_thrown', 0) - if self.throws['start'] < 0: self.throws['start'] = self.throws['latest'] - self.unique_mons['latest'] = playerdata.get('unique_pokedex_entries', 0) - if self.unique_mons['start'] < 0: self.unique_mons['start'] = self.unique_mons['latest'] - self.visits['latest'] = playerdata.get('poke_stop_visits', 0) - if self.visits['start'] < 0: self.visits['start'] = self.visits['latest'] - self.evolutions['latest'] = playerdata.get('evolutions', 0) - if self.evolutions['start'] < 0: self.evolutions['start'] = self.evolutions['latest'] elif 'pokedex_entry' in item['inventory_item_data']: entry = item['inventory_item_data']['pokedex_entry'].get('pokemon_id') if entry: uniq_pokemon_list.add(entry) From 1b8cb67f2699c327acdd3797660e273a4ac05f8c Mon Sep 17 00:00:00 2001 From: Ro Date: Thu, 25 Aug 2016 15:46:31 -0400 Subject: [PATCH 053/106] Update main.js (#4733) --- map-chat/javascript/main.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/map-chat/javascript/main.js b/map-chat/javascript/main.js index 14821b114b..14c857acac 100644 --- a/map-chat/javascript/main.js +++ b/map-chat/javascript/main.js @@ -14,11 +14,12 @@ function initialiseEventBus(){ client.on("message", function (topic, payload) { //Materialize.toast(payload, 4000); if (topic === 'pgochat/chat') { - displayChatMessageOnMap(payload); - Materialize.toast(payload, 5000); - + var objx = $.parseJSON(payload); + var message_data = "anonymous: " + objx.text; + displayChatMessageOnMap(payload); + Materialize.toast(message_data, 5000); var msg = JSON.parse(payload); - console.info('[ CHAT]', '(' + msg.lat + ',' + msg.lng + '): ', msg.text); + console.info('[CHAT]', '(' + msg.lat + ',' + msg.lng + '): ', msg.text); } else { //@ro: let's grab the message and split that shit. (simple for now, maybe we could just parse the json instead) var pLoadR = payload.toString(); From dcc190809b018b7c8ad2f96a2d2954c832904d7f Mon Sep 17 00:00:00 2001 From: DeXtroTip Date: Thu, 25 Aug 2016 21:00:01 +0100 Subject: [PATCH 054/106] New task ShowBestPokemon * Task to show best pokemon periodically * Amount of Pokemon configurable at config file * Order setting configurable at config file --- pokemongo_bot/__init__.py | 1 + pokemongo_bot/cell_workers/__init__.py | 1 + .../cell_workers/show_best_pokemon.py | 166 ++++++++++++++++++ 3 files changed, 168 insertions(+) create mode 100644 pokemongo_bot/cell_workers/show_best_pokemon.py diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index abd8623930..48877a8c58 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -400,6 +400,7 @@ def _register_events(self): self.event_manager.register_event('vip_pokemon') self.event_manager.register_event('gained_candy', parameters=('quantity', 'type')) self.event_manager.register_event('catch_limit') + self.event_manager.register_event('show_best_pokemon', parameters=('pokemons')) # level up stuff self.event_manager.register_event( diff --git a/pokemongo_bot/cell_workers/__init__.py b/pokemongo_bot/cell_workers/__init__.py index cf5f63e450..9251b1f45f 100644 --- a/pokemongo_bot/cell_workers/__init__.py +++ b/pokemongo_bot/cell_workers/__init__.py @@ -22,3 +22,4 @@ from random_pause import RandomPause from update_web_inventory import UpdateWebInventory from random_alive_pause import RandomAlivePause +from show_best_pokemon import ShowBestPokemon diff --git a/pokemongo_bot/cell_workers/show_best_pokemon.py b/pokemongo_bot/cell_workers/show_best_pokemon.py new file mode 100644 index 0000000000..59849b173a --- /dev/null +++ b/pokemongo_bot/cell_workers/show_best_pokemon.py @@ -0,0 +1,166 @@ +import ctypes +from datetime import datetime, timedelta + +from pokemongo_bot import inventory +from pokemongo_bot.base_task import BaseTask +from pokemongo_bot.worker_result import WorkerResult +from pokemongo_bot.tree_config_builder import ConfigException + + +class ShowBestPokemon(BaseTask): + """ + Periodically displays the user inventory in the terminal. + + Example config : + { + "type": "UpdateLiveInventory", + "config": { + "enabled": true, + "min_interval": 120, + "show_all_multiple_lines": false, + "items": ["space_info", "pokeballs", "greatballs", "ultraballs", "razzberries", "luckyegg"] + } + } + + min_interval : The minimum interval at which the stats are displayed, + in seconds (defaults to 120 seconds). + The update interval cannot be accurate as workers run synchronously. + show_all_multiple_lines : Logs all items on inventory using multiple lines. + Ignores configuration of 'items' + items : An array of items to display and their display order (implicitly), + see available items below (defaults to []). + + Available items : + 'pokemon_bag' : pokemon in inventory (i.e. 'Pokemon Bag: 100/250') + 'space_info': not an item but shows inventory bag space (i.e. 'Items: 140/350') + 'pokeballs' + 'greatballs' + 'ultraballs' + 'masterballs' + 'razzberries' + 'blukberries' + 'nanabberries' + 'luckyegg' + 'incubator' + 'troydisk' + 'potion' + 'superpotion' + 'hyperpotion' + 'maxpotion' + 'incense' + 'incensespicy' + 'incensecool' + 'revive' + 'maxrevive' + """ + + SUPPORTED_TASK_API_VERSION = 1 + + def initialize(self): + self.next_update = None + self.min_interval = self.config.get('min_interval', 120) + self.amount = self.config.get('amount', 3) + self.order_by = self.config.get('order_by', 'cp') + self.info_to_show = self.config.get('info_to_show', []) + + def work(self): + """ + Displays the items if necessary. + :return: Always returns WorkerResult.SUCCESS. + :rtype: WorkerResult + """ + if not self.info_to_show or not self._should_print(): + return WorkerResult.SUCCESS + + self.pokemons = inventory.pokemons().all() + + line = self._get_pokemons_line() + if not line: + return WorkerResult.SUCCESS + + self.print_pokemons(line) + return WorkerResult.SUCCESS + + def _should_print(self): + """ + Returns a value indicating whether the items should be displayed. + :return: True if the stats should be displayed; otherwise, False. + :rtype: bool + """ + return self.next_update is None or datetime.now() >= self.next_update + + def _compute_next_update(self): + """ + Computes the next update datetime based on the minimum update interval. + :return: Nothing. + :rtype: None + """ + self.next_update = datetime.now() + timedelta(seconds=self.min_interval) + + def print_pokemons(self, pokemons): + """ + Logs the items into the terminal using an event. + :param items: The items to display. + :type items: string + :param is_debug: If True emits event at debug level. + :type is_debug: boolean + :return: Nothing. + :rtype: None + """ + self.emit_event( + 'show_best_pokemon', + formatted="{pokemons}", + data={ + 'pokemons': pokemons + } + ) + + self._compute_next_update() + + + def _get_pokemons_line(self): + """ + Generates a string according to the configuration. + :return: A string containing pokemons and their info, ready to be displayed. + :rtype: string + """ + def get_poke_info(info, pokemon): + poke_info = { + 'cp': pokemon.cp, + 'iv': pokemon.iv, + 'ivcp': pokemon.ivcp, + 'ncp': pokemon.cp_percent, + 'level': pokemon.level, + 'hp': pokemon.hp, + 'dps': pokemon.moveset.dps + } + if info not in poke_info: + raise ConfigException("order by {}' isn't available".format(self.order_by)) + return poke_info[info] + + def get_poke_info_formatted(info, pokemon): + poke_info = { + 'name': pokemon.name, + 'cp': 'CP {}'.format(pokemon.cp), + 'iv_ads': 'A/D/S {}/{}/{}'.format(pokemon.iv_attack, pokemon.iv_defense, pokemon.iv_stamina), + 'iv_pct': 'IV {}'.format(pokemon.iv), + 'ivcp': 'IVCP {}'.format(round(pokemon.ivcp,2)), + 'ncp': 'NCP {}'.format(round(pokemon.cp_percent,2)), + 'level': "Level {}".format(pokemon.level), + 'hp': 'HP {}/{}'.format(pokemon.hp, pokemon.hp_max), + 'moveset': 'Moves: {}'.format(pokemon.moveset), + 'dps': 'DPS {}'.format(round(pokemon.moveset.dps, 2)) + } + if info not in poke_info: + raise ConfigException("info '{}' isn't available for displaying".format(info)) + return poke_info[info] + + info_to_show = ['name'] + self.info_to_show + + pokemons_ordered = sorted(self.pokemons, key=lambda x: get_poke_info(self.order_by, x), reverse=True) + pokemons_ordered = pokemons_ordered[:self.amount] + + poke_info = ['[{}]'.format(', '.join([get_poke_info_formatted(x, p) for x in info_to_show])) for p in pokemons_ordered] + + line = ' | '.join(poke_info) + return line From bb73725a3f58c997f8c23d180c948297868eada4 Mon Sep 17 00:00:00 2001 From: Ro Date: Thu, 25 Aug 2016 16:22:24 -0400 Subject: [PATCH 055/106] Update main.js --- map-chat/javascript/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/map-chat/javascript/main.js b/map-chat/javascript/main.js index 14c857acac..7be811c52a 100644 --- a/map-chat/javascript/main.js +++ b/map-chat/javascript/main.js @@ -15,7 +15,7 @@ function initialiseEventBus(){ //Materialize.toast(payload, 4000); if (topic === 'pgochat/chat') { var objx = $.parseJSON(payload); - var message_data = "anonymous: " + objx.text; + var message_data = "anonymous" + Math.floor(Math.random()*90000) + ": " + objx.text; displayChatMessageOnMap(payload); Materialize.toast(message_data, 5000); var msg = JSON.parse(payload); From 04e77864924f42b5613dad766cfcbd7f69005da7 Mon Sep 17 00:00:00 2001 From: DeXtroTip Date: Thu, 25 Aug 2016 21:24:23 +0100 Subject: [PATCH 056/106] Updated documentation --- docs/configuration_files.md | 51 ++++++++++++++ .../cell_workers/show_best_pokemon.py | 70 ++++++++----------- 2 files changed, 79 insertions(+), 42 deletions(-) diff --git a/docs/configuration_files.md b/docs/configuration_files.md index a17af0550d..58cf2ac885 100644 --- a/docs/configuration_files.md +++ b/docs/configuration_files.md @@ -45,6 +45,7 @@ - [Sleep Schedule Task](#sleep-schedule-task) - [Random Pause](#random-pause) - [Egg Incubator](#egg-incubator) +- [ShowBestPokemon Settings](#showbestpokemon-settings) #Configuration files @@ -704,6 +705,7 @@ Periodically displays the user inventory in the terminal. ### Options [[back to top](#table-of-contents)] + * `min_interval` : The minimum interval at which the stats are displayed, in seconds (defaults to 120 seconds). The update interval cannot be accurate as workers run synchronously. * `show_all_multiple_lines` : Logs all items on inventory using multiple lines. Ignores configuration of 'items' * `items` : An array of items to display and their display order (implicitly), see available items below (defaults to []). @@ -824,4 +826,53 @@ Configure how the bot should use the incubators. } ``` +## ShowBestPokemon +[[back to top](#table-of-contents)] + +### Description +[[back to top](#table-of-contents)] + +Periodically displays the user best pokemon in the terminal. + +### Options +[[back to top](#table-of-contents)] + +* `min_interval` : The minimum interval at which the pokemon are displayed, in seconds (defaults to 120 seconds). The update interval cannot be accurate as workers run synchronously. +* `amount` : Amount of pokemon to show. +* `order_by` : Stat that will be used to get best pokemons. +Available Stats: 'cp', 'iv', 'ivcp', 'ncp', 'dps', 'hp', 'level' +* `info_to_show` : Info to show for each pokemon + +Available `info_to_show` : +``` +'cp', +'iv_ads', +'iv_pct', +'ivcp', +'ncp', +'level', +'hp', +'moveset', +'dps' +``` +### Sample configuration +[[back to top](#table-of-contents)] +```json +{ + "type": "ShowBestPokemon", + "config": { + "enabled": true, + "min_interval": 60, + "amount": 5, + "order_by": "cp", + "info_to_show": ["cp", "ivcp", "dps"] + } +} +``` + +### Example console output +[[back to top](#table-of-contents)] +``` +2016-08-25 21:20:59,642 [ShowBestPokemon] [INFO] [show_best_pokemon] [Tauros, CP 575, IVCP 0.95, DPS 12.04] | [Grimer, CP 613, IVCP 0.93, DPS 13.93] | [Tangela, CP 736, IVCP 0.93, DPS 14.5] | [Staryu, CP 316, IVCP 0.92, DPS 10.75] | [Gastly, CP 224, IVCP 0.9, DPS 11.7] +``` \ No newline at end of file diff --git a/pokemongo_bot/cell_workers/show_best_pokemon.py b/pokemongo_bot/cell_workers/show_best_pokemon.py index 59849b173a..594d167e6c 100644 --- a/pokemongo_bot/cell_workers/show_best_pokemon.py +++ b/pokemongo_bot/cell_workers/show_best_pokemon.py @@ -9,49 +9,38 @@ class ShowBestPokemon(BaseTask): """ - Periodically displays the user inventory in the terminal. + Periodically displays the user best pokemon in the terminal. Example config : { - "type": "UpdateLiveInventory", + "type": "ShowBestPokemon", "config": { "enabled": true, - "min_interval": 120, - "show_all_multiple_lines": false, - "items": ["space_info", "pokeballs", "greatballs", "ultraballs", "razzberries", "luckyegg"] + "min_interval": 60, + "amount": 5, + "order_by": "cp", + "info_to_show": ["cp", "ivcp", "dps"] } } - min_interval : The minimum interval at which the stats are displayed, + min_interval : The minimum interval at which the pokemon are displayed, in seconds (defaults to 120 seconds). The update interval cannot be accurate as workers run synchronously. - show_all_multiple_lines : Logs all items on inventory using multiple lines. - Ignores configuration of 'items' - items : An array of items to display and their display order (implicitly), - see available items below (defaults to []). - - Available items : - 'pokemon_bag' : pokemon in inventory (i.e. 'Pokemon Bag: 100/250') - 'space_info': not an item but shows inventory bag space (i.e. 'Items: 140/350') - 'pokeballs' - 'greatballs' - 'ultraballs' - 'masterballs' - 'razzberries' - 'blukberries' - 'nanabberries' - 'luckyegg' - 'incubator' - 'troydisk' - 'potion' - 'superpotion' - 'hyperpotion' - 'maxpotion' - 'incense' - 'incensespicy' - 'incensecool' - 'revive' - 'maxrevive' + amount : Amount of pokemon to show + order_by : Stat that will be used to get best pokemons + Available Stats: 'cp', 'iv', 'ivcp', 'ncp', 'dps', 'hp', 'level' + info_to_show : Info to show for each pokemon + + Available info_to_show : + 'cp', + 'iv_ads', + 'iv_pct', + 'ivcp', + 'ncp', + 'level', + 'hp', + 'moveset', + 'dps' """ SUPPORTED_TASK_API_VERSION = 1 @@ -65,11 +54,11 @@ def initialize(self): def work(self): """ - Displays the items if necessary. + Displays the pokemon if necessary. :return: Always returns WorkerResult.SUCCESS. :rtype: WorkerResult """ - if not self.info_to_show or not self._should_print(): + if not self.info_to_show or not self.amount or not self._should_print(): return WorkerResult.SUCCESS self.pokemons = inventory.pokemons().all() @@ -83,7 +72,7 @@ def work(self): def _should_print(self): """ - Returns a value indicating whether the items should be displayed. + Returns a value indicating whether the pokemon should be displayed. :return: True if the stats should be displayed; otherwise, False. :rtype: bool """ @@ -99,11 +88,9 @@ def _compute_next_update(self): def print_pokemons(self, pokemons): """ - Logs the items into the terminal using an event. - :param items: The items to display. - :type items: string - :param is_debug: If True emits event at debug level. - :type is_debug: boolean + Logs the pokemon into the terminal using an event. + :param pokemons: The pokemon to display. + :type pokemons: string :return: Nothing. :rtype: None """ @@ -117,7 +104,6 @@ def print_pokemons(self, pokemons): self._compute_next_update() - def _get_pokemons_line(self): """ Generates a string according to the configuration. From db1312a88450e831439a331e4ca67a4892591457 Mon Sep 17 00:00:00 2001 From: Simba Zhang Date: Thu, 25 Aug 2016 13:49:32 -0700 Subject: [PATCH 057/106] Revert "add event messaging on badge update and application delay" --- pokemongo_bot/__init__.py | 55 ++------------------------------------- 1 file changed, 2 insertions(+), 53 deletions(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 2d048970bd..556e9c2e49 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -35,7 +35,6 @@ from tree_config_builder import ConfigException, MismatchTaskApiVersion, TreeConfigBuilder from inventory import init_inventory from sys import platform as _platform -from pgoapi.protos.POGOProtos.Enums import BadgeType_pb2 import struct @@ -74,7 +73,6 @@ def __init__(self, config): open(os.path.join(_base_dir, 'data', 'pokemon.json')) ) self.item_list = json.load(open(os.path.join(_base_dir, 'data', 'items.json'))) - # @var Metrics self.metrics = Metrics(self) self.latest_inventory = None self.cell = None @@ -139,7 +137,6 @@ def _setup_event_system(self): if self.config.websocket_remote_control: remote_control = WebsocketRemoteControl(self).start() - # @var EventManager self.event_manager = EventManager(*handlers) self._register_events() if self.config.show_events: @@ -579,15 +576,6 @@ def _register_events(self): self.event_manager.register_event('pokestop_log') self.event_manager.register_event('softban_log') - self.event_manager.register_event( - 'badges', - parameters=('badge', 'level') - ) - self.event_manager.register_event( - 'player_data', - parameters=('player_data', ) - ) - def tick(self): self.health_record.heartbeat() self.cell = self.get_meta_cell() @@ -848,7 +836,7 @@ def get_encryption_lib(self): return full_path def _setup_api(self): - # instantiate pgoapi @var ApiWrapper + # instantiate pgoapi self.api = ApiWrapper(config=self.config) # provide player position on the earth @@ -1160,46 +1148,7 @@ def heartbeat(self): request = self.api.create_request() request.get_player() request.check_awarded_badges() - responses = request.call() - - if responses['responses']['GET_PLAYER']['success'] == True: - #we get the player_data anyway, might as well store it - self._player = responses['responses']['GET_PLAYER']['player_data'] - self.event_manager.emit( - 'player_data', - sender=self, - level='debug', - formatted='equipped_badges: {player_data}', - data={'player_data': self._player} - ) - if responses['responses']['CHECK_AWARDED_BADGES']['success'] == True: - #store awarded_badges reponse to be used in a task or part of heartbeat - self._awarded_badges = responses['responses']['CHECK_AWARDED_BADGES'] - - if self._awarded_badges.has_key('awarded_badges'): - #todo: pull out the enum name and put into message - self.event_manager.emit( - 'badges', - sender=self, - level='info', - formatted='awarded badge: {badge}, lvl {level}', - data={'badge': BadgeType_pb2._BADGETYPE.values_by_number[self._awarded_badges['awarded_badges']].name, - 'level' : self._awarded_badges['awarded_badge_levels']} - ) - - #should work but gives errors :'( - #response = self.api.equip_badge(badge_type=self._awarded_badges['awarded_badges']) - response = {'responses' :"awaiting further testing on api call to equip_badge"} - self.event_manager.emit( - 'badges', - sender=self, - level='info', - formatted='equiped badge: {badges}', - data={'badges': response['responses']} - ) - human_behaviour.action_delay(3,10) - - + request.call() try: self.web_update_queue.put_nowait(True) # do this outside of thread every tick except Queue.Full: From 45b38c0e095c58ac0b40f03ab5d62c7dfd0d9826 Mon Sep 17 00:00:00 2001 From: DeXtroTip Date: Thu, 25 Aug 2016 22:05:29 +0100 Subject: [PATCH 058/106] Updated config example files --- configs/config.json.cluster.example | 10 ++++++++++ configs/config.json.example | 10 ++++++++++ configs/config.json.map.example | 10 ++++++++++ configs/config.json.optimizer.example | 10 ++++++++++ configs/config.json.path.example | 10 ++++++++++ configs/config.json.pokemon.example | 10 ++++++++++ 6 files changed, 60 insertions(+) diff --git a/configs/config.json.cluster.example b/configs/config.json.cluster.example index 32067c3520..5280829572 100644 --- a/configs/config.json.cluster.example +++ b/configs/config.json.cluster.example @@ -68,6 +68,16 @@ "items": ["pokemon_bag", "space_info", "pokeballs", "greatballs", "ultraballs", "razzberries", "luckyegg"] } }, + { + "type": "ShowBestPokemon", + "config": { + "enabled": true, + "min_interval": 60, + "amount": 5, + "order_by": "cp", + "info_to_show": ["cp", "ivcp", "dps", "hp"] + } + }, { "type": "TransferPokemon", "config": { diff --git a/configs/config.json.example b/configs/config.json.example index be08aa7a67..0e17334c4f 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -80,6 +80,16 @@ "items": ["pokemon_bag", "space_info", "pokeballs", "greatballs", "ultraballs", "razzberries", "luckyegg"] } }, + { + "type": "ShowBestPokemon", + "config": { + "enabled": true, + "min_interval": 60, + "amount": 5, + "order_by": "cp", + "info_to_show": ["cp", "ivcp", "dps", "hp"] + } + }, { "type": "TransferPokemon", "config": { diff --git a/configs/config.json.map.example b/configs/config.json.map.example index 9717fca52c..073b3d45c3 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -68,6 +68,16 @@ "items": ["pokemon_bag", "space_info", "pokeballs", "greatballs", "ultraballs", "razzberries", "luckyegg"] } }, + { + "type": "ShowBestPokemon", + "config": { + "enabled": true, + "min_interval": 60, + "amount": 5, + "order_by": "cp", + "info_to_show": ["cp", "ivcp", "dps", "hp"] + } + }, { "type": "TransferPokemon", "config": { diff --git a/configs/config.json.optimizer.example b/configs/config.json.optimizer.example index 315d3bdba2..0950bfc21c 100644 --- a/configs/config.json.optimizer.example +++ b/configs/config.json.optimizer.example @@ -68,6 +68,16 @@ "items": ["pokemon_bag", "space_info", "pokeballs", "greatballs", "ultraballs", "razzberries", "luckyegg"] } }, + { + "type": "ShowBestPokemon", + "config": { + "enabled": true, + "min_interval": 60, + "amount": 5, + "order_by": "cp", + "info_to_show": ["cp", "ivcp", "dps", "hp"] + } + }, { "type": "PokemonOptimizer", "config": { diff --git a/configs/config.json.path.example b/configs/config.json.path.example index 305964113d..be210e74a8 100644 --- a/configs/config.json.path.example +++ b/configs/config.json.path.example @@ -68,6 +68,16 @@ "items": ["pokemon_bag", "space_info", "pokeballs", "greatballs", "ultraballs", "razzberries", "luckyegg"] } }, + { + "type": "ShowBestPokemon", + "config": { + "enabled": true, + "min_interval": 60, + "amount": 5, + "order_by": "cp", + "info_to_show": ["cp", "ivcp", "dps", "hp"] + } + }, { "type": "TransferPokemon", "config": { diff --git a/configs/config.json.pokemon.example b/configs/config.json.pokemon.example index 51793fe2bf..566590aa2e 100644 --- a/configs/config.json.pokemon.example +++ b/configs/config.json.pokemon.example @@ -68,6 +68,16 @@ "items": ["pokemon_bag", "space_info", "pokeballs", "greatballs", "ultraballs", "razzberries", "luckyegg"] } }, + { + "type": "ShowBestPokemon", + "config": { + "enabled": true, + "min_interval": 60, + "amount": 5, + "order_by": "cp", + "info_to_show": ["cp", "ivcp", "dps", "hp"] + } + }, { "type": "TransferPokemon", "config": { From f1438b1eba14292cf05432ec354bde0810f22e0f Mon Sep 17 00:00:00 2001 From: DeXtroTip Date: Thu, 25 Aug 2016 22:10:52 +0100 Subject: [PATCH 059/106] Fixed documentation --- docs/configuration_files.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/configuration_files.md b/docs/configuration_files.md index 58cf2ac885..aa9f55e0ad 100644 --- a/docs/configuration_files.md +++ b/docs/configuration_files.md @@ -45,7 +45,7 @@ - [Sleep Schedule Task](#sleep-schedule-task) - [Random Pause](#random-pause) - [Egg Incubator](#egg-incubator) -- [ShowBestPokemon Settings](#showbestpokemon-settings) +- [ShowBestPokemon](#showbestpokemon) #Configuration files From 4ceda11f8332b141a2cedeebf1e5cfe70477ba00 Mon Sep 17 00:00:00 2001 From: Simba Zhang Date: Thu, 25 Aug 2016 14:15:09 -0700 Subject: [PATCH 060/106] Changed the duration between heartbeat to 15x60. added persistant data store. --- pokemongo_bot/health_record/bot_event.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pokemongo_bot/health_record/bot_event.py b/pokemongo_bot/health_record/bot_event.py index 55a726049d..6c65b84764 100644 --- a/pokemongo_bot/health_record/bot_event.py +++ b/pokemongo_bot/health_record/bot_event.py @@ -8,11 +8,23 @@ import uuid import requests import time +import shelve +import os +from pokemongo_bot.base_dir import _base_dir class BotEvent(object): def __init__(self, config): self.config = config self.logger = logging.getLogger(__name__) + client_id_file_path = os.path.join(_base_dir, 'data', 'client_id') + saved_info = shelve.open(client_id_file_path) + if saved_info.has_key('client_id'): + self.client_id = saved_info['client_id'] + else: + self.client_id = uuid.uuid4() + saved_info['client_id'] = self.client_id + saved_info.close() + print self.client_id # UniversalAnalytics can be reviewed here: # https://github.com/analytics-pros/universal-analytics-python if self.config.health_record: @@ -32,8 +44,7 @@ def __init__(self, config): context = {} ) - self.client_id = uuid.uuid4() - self.heartbeat_wait = 30 # seconds + self.heartbeat_wait = 15*60 # seconds self.last_heartbeat = time.time() def capture_error(self): From 5c3706ac32bc2f838c9989829d509e945e2442c5 Mon Sep 17 00:00:00 2001 From: Simba Zhang Date: Thu, 25 Aug 2016 14:17:29 -0700 Subject: [PATCH 061/106] removed raw ptint. --- pokemongo_bot/health_record/bot_event.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pokemongo_bot/health_record/bot_event.py b/pokemongo_bot/health_record/bot_event.py index 6c65b84764..cda9bf6c3d 100644 --- a/pokemongo_bot/health_record/bot_event.py +++ b/pokemongo_bot/health_record/bot_event.py @@ -24,7 +24,6 @@ def __init__(self, config): self.client_id = uuid.uuid4() saved_info['client_id'] = self.client_id saved_info.close() - print self.client_id # UniversalAnalytics can be reviewed here: # https://github.com/analytics-pros/universal-analytics-python if self.config.health_record: From cbda2fb8717b66492947a20511ca781319c75457 Mon Sep 17 00:00:00 2001 From: Gobberwart Date: Fri, 26 Aug 2016 07:19:15 +1000 Subject: [PATCH 062/106] Larger times for recycling in example configs Times given in previous examples were too low (0 to 1 minute). Changed to t to 5 minutes. --- configs/config.json.cluster.example | 4 ++-- configs/config.json.example | 4 ++-- configs/config.json.map.example | 4 ++-- configs/config.json.optimizer.example | 4 ++-- configs/config.json.path.example | 4 ++-- configs/config.json.pokemon.example | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/configs/config.json.cluster.example b/configs/config.json.cluster.example index da847b4663..dc421130cf 100644 --- a/configs/config.json.cluster.example +++ b/configs/config.json.cluster.example @@ -119,8 +119,8 @@ "recycle_wait_min": 3, "recycle_wait_max": 5, "recycle_force": true, - "recycle_force_min": "00:00:00", - "recycle_force_max": "00:01:00" + "recycle_force_min": "00:01:00", + "recycle_force_max": "00:05:00" } }, { diff --git a/configs/config.json.example b/configs/config.json.example index 52f13e4068..440e442692 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -131,8 +131,8 @@ "recycle_wait_min": 3, "recycle_wait_max": 5, "recycle_force": true, - "recycle_force_min": "00:00:00", - "recycle_force_max": "00:01:00" + "recycle_force_min": "00:01:00", + "recycle_force_max": "00:05:00" } }, { diff --git a/configs/config.json.map.example b/configs/config.json.map.example index 874e759959..6fcfa8bf74 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -119,8 +119,8 @@ "recycle_wait_min": 1, "recycle_wait_max": 4, "recycle_force": true, - "recycle_force_min": "00:00:00", - "recycle_force_max": "00:01:00" + "recycle_force_min": "00:01:00", + "recycle_force_max": "00:05:00" } }, { diff --git a/configs/config.json.optimizer.example b/configs/config.json.optimizer.example index d6680a68f7..7c11eb714c 100644 --- a/configs/config.json.optimizer.example +++ b/configs/config.json.optimizer.example @@ -180,8 +180,8 @@ "recycle_wait_min": 3, "recycle_wait_max": 5, "recycle_force": true, - "recycle_force_min": "00:00:00", - "recycle_force_max": "00:01:00" + "recycle_force_min": "00:01:00", + "recycle_force_max": "00:05:00" } }, { diff --git a/configs/config.json.path.example b/configs/config.json.path.example index acff64c0bc..8966b21a5c 100644 --- a/configs/config.json.path.example +++ b/configs/config.json.path.example @@ -119,8 +119,8 @@ "recycle_wait_min": 3, "recycle_wait_max": 5, "recycle_force": true, - "recycle_force_min": "00:00:00", - "recycle_force_max": "00:01:00" + "recycle_force_min": "00:01:00", + "recycle_force_max": "00:05:00" } }, { diff --git a/configs/config.json.pokemon.example b/configs/config.json.pokemon.example index 3968270cb0..23ac212a6f 100644 --- a/configs/config.json.pokemon.example +++ b/configs/config.json.pokemon.example @@ -118,8 +118,8 @@ "recycle_wait_min": 3, "recycle_wait_max": 5, "recycle_force": true, - "recycle_force_min": "00:00:00", - "recycle_force_max": "00:01:00" + "recycle_force_min": "00:01:00", + "recycle_force_max": "00:05:00" } }, { From 8dda26e4f828b565be8030d8a6afb80f9763e27b Mon Sep 17 00:00:00 2001 From: Simba Zhang Date: Thu, 25 Aug 2016 14:50:19 -0700 Subject: [PATCH 063/106] Fixed AttributeError when calling capture_state before bot initialed. --- pokemongo_bot/metrics.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pokemongo_bot/metrics.py b/pokemongo_bot/metrics.py index 4961a16da6..79e0b2eca7 100644 --- a/pokemongo_bot/metrics.py +++ b/pokemongo_bot/metrics.py @@ -96,7 +96,10 @@ def released_pokemon(self, count=1): self.releases += count def capture_stats(self): - request = self.bot.api.create_request() + try: + request = self.bot.api.create_request() + except AttributeError: + return request.get_inventory() request.get_player() response_dict = request.call() From dcda7a144508285dfc99d736aab75254bd489edc Mon Sep 17 00:00:00 2001 From: Simba Zhang Date: Thu, 25 Aug 2016 14:52:50 -0700 Subject: [PATCH 064/106] Use persistant client_id for mqtt client. --- pokemongo_bot/__init__.py | 12 +++++++++++- pokemongo_bot/event_handlers/social_handler.py | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 556e9c2e49..65a883d29e 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -11,6 +11,8 @@ import time import Queue import threading +import shelve +import uuid from geopy.geocoders import GoogleV3 from pgoapi import PGoApi @@ -37,7 +39,6 @@ from sys import platform as _platform import struct - class PokemonGoBot(Datastore): @property def position(self): @@ -100,6 +101,15 @@ def __init__(self, config): self.capture_locked = False # lock catching while moving to VIP pokemon + client_id_file_path = os.path.join(_base_dir, 'data', 'client_id') + saved_info = shelve.open(client_id_file_path) + if saved_info.has_key('client_id'): + self.config.client_id = str(saved_info['client_id']) + else: + self.config.client_id = str(uuid.uuid4()) + saved_info['client_id'] = self.config.client_id + saved_info.close() + def start(self): self._setup_event_system() self._setup_logging() diff --git a/pokemongo_bot/event_handlers/social_handler.py b/pokemongo_bot/event_handlers/social_handler.py index acc9e67ee5..927d0d2b58 100644 --- a/pokemongo_bot/event_handlers/social_handler.py +++ b/pokemongo_bot/event_handlers/social_handler.py @@ -43,7 +43,7 @@ class SocialHandler(EventHandler): def __init__(self, bot): self.bot = bot try: - self.mqttc = MyMQTTClass(bot) + self.mqttc = MyMQTTClass(bot, self.bot.config.client_id) self.mqttc.connect_to_mqtt() thread.start_new_thread(self.mqttc.run) except socket_error as serr: From 412cea45a9a4be40990348be06ba51fe05e61322 Mon Sep 17 00:00:00 2001 From: Alex Yao Date: Thu, 25 Aug 2016 14:58:28 -0700 Subject: [PATCH 065/106] Live config update --- configs/config.json.cluster.example | 4 +++ configs/config.json.example | 4 +++ configs/config.json.map.example | 4 +++ configs/config.json.optimizer.example | 4 +++ configs/config.json.path.example | 4 +++ configs/config.json.pokemon.example | 4 +++ docs/configuration_files.md | 2 ++ pokecli.py | 46 ++++++++++++++++++++++----- 8 files changed, 64 insertions(+), 8 deletions(-) diff --git a/configs/config.json.cluster.example b/configs/config.json.cluster.example index 32067c3520..f7a050c5e6 100644 --- a/configs/config.json.cluster.example +++ b/configs/config.json.cluster.example @@ -11,6 +11,10 @@ "websocket_server": false, "heartbeat_threshold": 10, "enable_social": true, + "live_config_update": { + "enabled": false, + "tasks_only": false + }, "tasks": [ { "//NOTE: This task MUST be placed on the top of task list": {}, diff --git a/configs/config.json.example b/configs/config.json.example index be08aa7a67..4ac3c413d0 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -11,6 +11,10 @@ "websocket_server": false, "heartbeat_threshold": 10, "enable_social": true, + "live_config_update": { + "enabled": false, + "tasks_only": false + }, "tasks": [ { "//NOTE: This task MUST be placed on the top of task list": {}, diff --git a/configs/config.json.map.example b/configs/config.json.map.example index 9717fca52c..4ae087f2ee 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -11,6 +11,10 @@ "websocket_server": false, "heartbeat_threshold": 10, "enable_social": true, + "live_config_update": { + "enabled": false, + "tasks_only": false + }, "tasks": [ { "//NOTE: This task MUST be placed on the top of task list": {}, diff --git a/configs/config.json.optimizer.example b/configs/config.json.optimizer.example index 315d3bdba2..dcccbb048e 100644 --- a/configs/config.json.optimizer.example +++ b/configs/config.json.optimizer.example @@ -11,6 +11,10 @@ "websocket_server": false, "heartbeat_threshold": 10, "enable_social": true, + "live_config_update": { + "enabled": false, + "tasks_only": false + }, "tasks": [ { "//NOTE: This task MUST be placed on the top of task list": {}, diff --git a/configs/config.json.path.example b/configs/config.json.path.example index 305964113d..c5567c5cd3 100644 --- a/configs/config.json.path.example +++ b/configs/config.json.path.example @@ -11,6 +11,10 @@ "websocket_server": false, "heartbeat_threshold": 10, "enable_social": true, + "live_config_update": { + "enabled": false, + "tasks_only": false + }, "tasks": [ { "//NOTE: This task MUST be placed on the top of task list": {}, diff --git a/configs/config.json.pokemon.example b/configs/config.json.pokemon.example index 51793fe2bf..a40da1c9ea 100644 --- a/configs/config.json.pokemon.example +++ b/configs/config.json.pokemon.example @@ -11,6 +11,10 @@ "websocket_server": false, "heartbeat_threshold": 10, "enable_social": true, + "live_config_update": { + "enabled": false, + "tasks_only": false + }, "tasks": [ { "//NOTE: This task MUST be placed on the top of task list": {}, diff --git a/docs/configuration_files.md b/docs/configuration_files.md index a17af0550d..db42d08576 100644 --- a/docs/configuration_files.md +++ b/docs/configuration_files.md @@ -81,6 +81,8 @@ Document the configuration options of PokemonGo-Bot. |`pokemon_bag.show_count` | false | Show amount of each pokemon. |`pokemon_bag.pokemon_info` | [] | Check any config example file to see available settings. |`favorite_locations` | [] | Allows you to define a collection of locations and coordinates, allowing rapid switch using a "label" on your location config +| `live_config_update.enabled` | false | Enable live config update +| `live_config_update.tasks_only` | false | True: quick update for Tasks only (without re-login). False: slower update for entire config file. ## Configuring Tasks diff --git a/pokecli.py b/pokecli.py index 3930a082db..5983e33e74 100644 --- a/pokecli.py +++ b/pokecli.py @@ -74,6 +74,18 @@ def handle_sigint(*args): raise SIGINTRecieved signal.signal(signal.SIGINT, handle_sigint) + def initialize_task(bot, config): + tree = TreeConfigBuilder(bot, config.raw_tasks).build() + bot.workers = tree + + def initialize(config): + bot = PokemonGoBot(config) + bot.start() + initialize_task(bot,config) + bot.metrics.capture_stats() + bot.health_record = BotEvent(config) + return bot + def get_commit_hash(): try: hash = subprocess.check_output(['git', 'rev-parse', 'HEAD'], stderr=subprocess.STDOUT)[:-1] @@ -88,7 +100,7 @@ def get_commit_hash(): sys.stdout = codecs.getwriter('utf8')(sys.stdout) sys.stderr = codecs.getwriter('utf8')(sys.stderr) - config = init_config() + config, config_file = init_config() if not config: return @@ -100,12 +112,8 @@ def get_commit_hash(): while not finished: try: - bot = PokemonGoBot(config) - bot.start() - tree = TreeConfigBuilder(bot, config.raw_tasks).build() - bot.workers = tree - bot.metrics.capture_stats() - bot.health_record = health_record + bot = initialize(config) + config_changed = check_mod(config_file) bot.event_manager.emit( 'bot_start', @@ -116,6 +124,12 @@ def get_commit_hash(): while True: bot.tick() + if config.live_config_update_enabled and config_changed(): + logger.info('Config changed! Applying new config.') + config, _ = init_config() + + if config.live_config_update_tasks_only: initialize_task(bot, config) + else: bot = initialize(config) except KeyboardInterrupt: bot.event_manager.emit( @@ -212,6 +226,18 @@ def get_commit_hash(): data={'path': cached_forts_path} ) +def check_mod(config_file): + check_mod.mtime = os.path.getmtime(config_file) + + def compare_mtime(): + mdate = os.path.getmtime(config_file) + if check_mod.mtime == mdate: # mtime didnt change + return False + else: + check_mod.mtime = mdate + return True + + return compare_mtime def report_summary(bot): if bot.metrics.start_time is None: @@ -265,6 +291,7 @@ def _json_loader(filename): if config_arg and os.path.isfile(config_arg): _json_loader(config_arg) + config_file = config_arg elif os.path.isfile(config_file): logger.info('No config argument specified, checking for /configs/config.json') _json_loader(config_file) @@ -596,6 +623,9 @@ def _json_loader(filename): config.daily_catch_limit = load.get('daily_catch_limit', 800) config.vips = load.get('vips', {}) config.sleep_schedule = load.get('sleep_schedule', []) + config.live_config_update = load.get('live_config_update', {}) + config.live_config_update_enabled = config.live_config_update.get('enabled', False) + config.live_config_update_tasks_only = config.live_config_update.get('tasks_only', False) if config.map_object_cache_time < 0.0: parser.error("--map_object_cache_time is out of range! (should be >= 0.0)") @@ -662,7 +692,7 @@ def task_configuration_error(flag_name): raise fix_nested_config(config) - return config + return config, config_file def add_config(parser, json_config, short_flag=None, long_flag=None, **kwargs): if not long_flag: From b2be9f3e50ce2dfcd60fa63e79be1aa7409e1c99 Mon Sep 17 00:00:00 2001 From: Gobberwart Date: Fri, 26 Aug 2016 08:07:58 +1000 Subject: [PATCH 066/106] Remove spaces from Nidorans When generating a new nickname, convert "Nidoran M/F" to "NidoranM/F" --- pokemongo_bot/cell_workers/nickname_pokemon.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pokemongo_bot/cell_workers/nickname_pokemon.py b/pokemongo_bot/cell_workers/nickname_pokemon.py index 331061af4e..84a60c0b06 100644 --- a/pokemongo_bot/cell_workers/nickname_pokemon.py +++ b/pokemongo_bot/cell_workers/nickname_pokemon.py @@ -331,6 +331,10 @@ def _generate_new_nickname(self, pokemon, template): moveset = pokemon.moveset pokemon.name = self._localize(pokemon.name) + + # Remove spaces from Nidoran M/F + pokemon.name = pokemon.name.replace("Nidoran M","NidoranM") + pokemon.name = pokemon.name.replace("Nidoran F","NidoranF") # # Generate new nickname From cc22fe923d249902115816cd0cb466c073c34a73 Mon Sep 17 00:00:00 2001 From: Simba Zhang Date: Thu, 25 Aug 2016 15:12:19 -0700 Subject: [PATCH 067/106] Use different client id for mqtt and health report. --- pokemongo_bot/__init__.py | 7 ++++--- pokemongo_bot/health_record/bot_event.py | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 65a883d29e..6356984025 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -101,13 +101,14 @@ def __init__(self, config): self.capture_locked = False # lock catching while moving to VIP pokemon - client_id_file_path = os.path.join(_base_dir, 'data', 'client_id') + client_id_file_path = os.path.join(_base_dir, 'data', 'mqtt_client_id') saved_info = shelve.open(client_id_file_path) if saved_info.has_key('client_id'): self.config.client_id = str(saved_info['client_id']) else: - self.config.client_id = str(uuid.uuid4()) - saved_info['client_id'] = self.config.client_id + client_uuid = uuid.uuid4() + self.config.client_id = str(client_uuid) + saved_info['client_id'] = client_uuid saved_info.close() def start(self): diff --git a/pokemongo_bot/health_record/bot_event.py b/pokemongo_bot/health_record/bot_event.py index cda9bf6c3d..d406309219 100644 --- a/pokemongo_bot/health_record/bot_event.py +++ b/pokemongo_bot/health_record/bot_event.py @@ -19,10 +19,11 @@ def __init__(self, config): client_id_file_path = os.path.join(_base_dir, 'data', 'client_id') saved_info = shelve.open(client_id_file_path) if saved_info.has_key('client_id'): - self.client_id = saved_info['client_id'] + self.client_id = str(saved_info['client_id']) else: - self.client_id = uuid.uuid4() - saved_info['client_id'] = self.client_id + client_uuid = uuid.uuid4() + self.client_id = str(client_uuid) + saved_info['client_id'] = client_uuid saved_info.close() # UniversalAnalytics can be reviewed here: # https://github.com/analytics-pros/universal-analytics-python From 95430eedd4779f23e36df0351cd244298fbe6a72 Mon Sep 17 00:00:00 2001 From: Stuart Travers Date: Fri, 26 Aug 2016 08:13:36 +1000 Subject: [PATCH 068/106] Larger times for recycling in example configs (#4737) Times given in previous examples were too low (0 to 1 minute). Changed to t to 5 minutes. --- configs/config.json.cluster.example | 4 ++-- configs/config.json.example | 4 ++-- configs/config.json.map.example | 4 ++-- configs/config.json.optimizer.example | 4 ++-- configs/config.json.path.example | 4 ++-- configs/config.json.pokemon.example | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/configs/config.json.cluster.example b/configs/config.json.cluster.example index 32067c3520..0e6d8f0d3f 100644 --- a/configs/config.json.cluster.example +++ b/configs/config.json.cluster.example @@ -119,8 +119,8 @@ "recycle_wait_min": 3, "recycle_wait_max": 5, "recycle_force": true, - "recycle_force_min": "00:00:00", - "recycle_force_max": "00:01:00" + "recycle_force_min": "00:01:00", + "recycle_force_max": "00:05:00" } }, { diff --git a/configs/config.json.example b/configs/config.json.example index be08aa7a67..0131e8b20e 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -131,8 +131,8 @@ "recycle_wait_min": 3, "recycle_wait_max": 5, "recycle_force": true, - "recycle_force_min": "00:00:00", - "recycle_force_max": "00:01:00" + "recycle_force_min": "00:01:00", + "recycle_force_max": "00:05:00" } }, { diff --git a/configs/config.json.map.example b/configs/config.json.map.example index 9717fca52c..3973a7973b 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -119,8 +119,8 @@ "recycle_wait_min": 1, "recycle_wait_max": 4, "recycle_force": true, - "recycle_force_min": "00:00:00", - "recycle_force_max": "00:01:00" + "recycle_force_min": "00:01:00", + "recycle_force_max": "00:05:00" } }, { diff --git a/configs/config.json.optimizer.example b/configs/config.json.optimizer.example index 315d3bdba2..5057f62c43 100644 --- a/configs/config.json.optimizer.example +++ b/configs/config.json.optimizer.example @@ -180,8 +180,8 @@ "recycle_wait_min": 3, "recycle_wait_max": 5, "recycle_force": true, - "recycle_force_min": "00:00:00", - "recycle_force_max": "00:01:00" + "recycle_force_min": "00:01:00", + "recycle_force_max": "00:05:00" } }, { diff --git a/configs/config.json.path.example b/configs/config.json.path.example index 305964113d..0c13391f56 100644 --- a/configs/config.json.path.example +++ b/configs/config.json.path.example @@ -119,8 +119,8 @@ "recycle_wait_min": 3, "recycle_wait_max": 5, "recycle_force": true, - "recycle_force_min": "00:00:00", - "recycle_force_max": "00:01:00" + "recycle_force_min": "00:01:00", + "recycle_force_max": "00:05:00" } }, { diff --git a/configs/config.json.pokemon.example b/configs/config.json.pokemon.example index 51793fe2bf..ab7b9e99c9 100644 --- a/configs/config.json.pokemon.example +++ b/configs/config.json.pokemon.example @@ -118,8 +118,8 @@ "recycle_wait_min": 3, "recycle_wait_max": 5, "recycle_force": true, - "recycle_force_min": "00:00:00", - "recycle_force_max": "00:01:00" + "recycle_force_min": "00:01:00", + "recycle_force_max": "00:05:00" } }, { From 899682802805b107f0bae24f7a66a2f657c283ff Mon Sep 17 00:00:00 2001 From: Simba Zhang Date: Thu, 25 Aug 2016 15:14:41 -0700 Subject: [PATCH 069/106] Save to str format. --- pokemongo_bot/__init__.py | 4 ++-- pokemongo_bot/health_record/bot_event.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 6356984025..842664d7ef 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -104,11 +104,11 @@ def __init__(self, config): client_id_file_path = os.path.join(_base_dir, 'data', 'mqtt_client_id') saved_info = shelve.open(client_id_file_path) if saved_info.has_key('client_id'): - self.config.client_id = str(saved_info['client_id']) + self.config.client_id = saved_info['client_id'] else: client_uuid = uuid.uuid4() self.config.client_id = str(client_uuid) - saved_info['client_id'] = client_uuid + saved_info['client_id'] = self.config.client_id saved_info.close() def start(self): diff --git a/pokemongo_bot/health_record/bot_event.py b/pokemongo_bot/health_record/bot_event.py index d406309219..28d3943a52 100644 --- a/pokemongo_bot/health_record/bot_event.py +++ b/pokemongo_bot/health_record/bot_event.py @@ -19,11 +19,11 @@ def __init__(self, config): client_id_file_path = os.path.join(_base_dir, 'data', 'client_id') saved_info = shelve.open(client_id_file_path) if saved_info.has_key('client_id'): - self.client_id = str(saved_info['client_id']) + self.client_id = saved_info['client_id'] else: client_uuid = uuid.uuid4() self.client_id = str(client_uuid) - saved_info['client_id'] = client_uuid + saved_info['client_id'] = self.client_id saved_info.close() # UniversalAnalytics can be reviewed here: # https://github.com/analytics-pros/universal-analytics-python From 35b634b76cf7155afe72d036d5bad82e513d476c Mon Sep 17 00:00:00 2001 From: Gobberwart Date: Fri, 26 Aug 2016 08:35:40 +1000 Subject: [PATCH 070/106] Create inventory file if it doesn't exist Bugfix --- pokemongo_bot/inventory.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/pokemongo_bot/inventory.py b/pokemongo_bot/inventory.py index fa2483687d..572e089d86 100644 --- a/pokemongo_bot/inventory.py +++ b/pokemongo_bot/inventory.py @@ -1096,21 +1096,32 @@ def refresh(self): self.update_web_inventory() + def init_inventory_outfile(self): + web_inventory = os.path.join(_base_dir, "web", "inventory-%s.json" % self.bot.config.username) + + if not os.path.exists(web_inventory): + json_inventory = [] + + with open(web_inventory, "w") as outfile: + json.dump(json_inventory, outfile) + + def update_web_inventory(self): web_inventory = os.path.join(_base_dir, "web", "inventory-%s.json" % self.bot.config.username) - if os.path.exists(web_inventory): - with open(web_inventory, "r") as infile: - json_inventory = json.load(infile) + if not os.path.exists(web_inventory): + self.init_inventory_outfile() + + with open(web_inventory, "r") as infile: + json_inventory = json.load(infile) - json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("pokedex_entry", None)] - json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("candy", None)] - json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("item", None)] - json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("pokemon_data", None)] + json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("pokedex_entry", None)] + json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("candy", None)] + json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("item", None)] + json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("pokemon_data", None)] - json_inventory = json_inventory + self.jsonify_inventory() - else: - json_inventory = self.jsonify_inventory() + json_inventory = json_inventory + self.jsonify_inventory() + json_inventory = self.jsonify_inventory() with open(web_inventory, "w") as outfile: json.dump(json_inventory, outfile) From 3831ed3804b66bd779157755b79a33d3f82ef7ea Mon Sep 17 00:00:00 2001 From: Alex Yao Date: Thu, 25 Aug 2016 16:10:08 -0700 Subject: [PATCH 071/106] Show current progress + move config into CatchPokemon Task --- pokecli.py | 4 +++- pokemongo_bot/__init__.py | 4 +++- pokemongo_bot/cell_workers/pokemon_catch_worker.py | 14 +++++++------- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/pokecli.py b/pokecli.py index 3930a082db..8e358f606e 100644 --- a/pokecli.py +++ b/pokecli.py @@ -593,7 +593,6 @@ def _json_loader(filename): config.release = load.get('release', {}) config.plugins = load.get('plugins', []) config.raw_tasks = load.get('tasks', []) - config.daily_catch_limit = load.get('daily_catch_limit', 800) config.vips = load.get('vips', {}) config.sleep_schedule = load.get('sleep_schedule', []) @@ -638,6 +637,9 @@ def task_configuration_error(flag_name): if "walk" in load: logger.warning('The walk argument is no longer supported. Please use the walk_max and walk_min variables instead') + if "daily_catch_limit" in load: + logger.warning('The daily_catch_limit argument has been moved into the CatchPokemon Task') + if config.walk_min < 1: parser.error("--walk_min is out of range! (should be >= 1.0)") return None diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 842664d7ef..559ecff3dd 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -400,7 +400,9 @@ def _register_events(self): 'encounter_id', 'latitude', 'longitude', - 'pokemon_id' + 'pokemon_id', + 'daily_catch_limit', + 'caught_last_24_hour', ) ) self.event_manager.register_event( diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index ea62f89f3c..1e4211d5ec 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -60,6 +60,7 @@ def initialize(self): self.berry_threshold = self.config.get('berry_threshold', 0.35) self.vip_berry_threshold = self.config.get('vip_berry_threshold', 0.9) self.treat_unseen_as_vip = self.config.get('treat_unseen_as_vip', DEFAULT_UNSEEN_AS_VIP) + self.daily_catch_limit = self.config.get('daily_catch_limit', 800) self.catch_throw_parameters = self.config.get('catch_throw_parameters', {}) self.catch_throw_parameters_spin_success_rate = self.catch_throw_parameters.get('spin_success_rate', 0.6) @@ -161,10 +162,10 @@ def work(self, response_dict=None): c.execute("SELECT DISTINCT COUNT(encounter_id) FROM catch_log WHERE dated >= datetime('now','-1 day')") result = c.fetchone() + self.caught_last_24_hour = result[0] while True: - max_catch = self.bot.config.daily_catch_limit - if result[0] < max_catch: + if self.caught_last_24_hour < self.daily_catch_limit: # catch that pokemon! encounter_id = self.pokemon['encounter_id'] catch_rate_by_ball = [0] + response['capture_probability']['capture_probability'] # offset so item ids match indces @@ -241,9 +242,6 @@ def _pokemon_matches_config(self, config, pokemon, default_logic='and'): if pokemon.iv > catch_iv: catch_results['iv'] = True - if self.bot.capture_locked: # seems there is another more preferable pokemon, catching is locked - return False - return LOGIC_TO_FUNCTION[pokemon_config.get('logic', default_logic)](*catch_results.values()) def _should_catch_pokemon(self, pokemon): @@ -508,7 +506,7 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False): self.emit_event( 'pokemon_caught', - formatted='Captured {pokemon}! [CP {cp}] [NCP {ncp}] [Potential {iv}] [{iv_display}] [+{exp} exp]', + formatted='Captured {pokemon}! [CP {cp}] [NCP {ncp}] [Potential {iv}] [{iv_display}] ({caught_last_24_hour}/{daily_catch_limit}) [+{exp} exp]', data={ 'pokemon': pokemon.name, 'ncp': round(pokemon.cp_percent, 2), @@ -519,7 +517,9 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False): 'encounter_id': self.pokemon['encounter_id'], 'latitude': self.pokemon['latitude'], 'longitude': self.pokemon['longitude'], - 'pokemon_id': pokemon.pokemon_id + 'pokemon_id': pokemon.pokemon_id, + 'caught_last_24_hour': self.caught_last_24_hour + 1, + 'daily_catch_limit': self.daily_catch_limit } ) From 13995bb1038f0be16983c312d7adf9a9ffa7009f Mon Sep 17 00:00:00 2001 From: Gobberwart Date: Fri, 26 Aug 2016 09:17:31 +1000 Subject: [PATCH 072/106] Minor logic fix Open/write to json file should only occur if new file is created --- pokemongo_bot/inventory.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pokemongo_bot/inventory.py b/pokemongo_bot/inventory.py index 572e089d86..29ea395903 100644 --- a/pokemongo_bot/inventory.py +++ b/pokemongo_bot/inventory.py @@ -1102,8 +1102,8 @@ def init_inventory_outfile(self): if not os.path.exists(web_inventory): json_inventory = [] - with open(web_inventory, "w") as outfile: - json.dump(json_inventory, outfile) + with open(web_inventory, "w") as outfile: + json.dump(json_inventory, outfile) def update_web_inventory(self): From 0bedea3d78407b3313c3ceca90db1a156af63a08 Mon Sep 17 00:00:00 2001 From: Simba Zhang Date: Thu, 25 Aug 2016 16:27:51 -0700 Subject: [PATCH 073/106] To pass the CI build. --- pokemongo_bot/event_handlers/social_handler.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pokemongo_bot/event_handlers/social_handler.py b/pokemongo_bot/event_handlers/social_handler.py index 927d0d2b58..d19f578f73 100644 --- a/pokemongo_bot/event_handlers/social_handler.py +++ b/pokemongo_bot/event_handlers/social_handler.py @@ -34,9 +34,12 @@ def mqtt_on_message(self, mqttc, obj, msg): def publish(self, channel, message): self._mqttc.publish(channel, message) def connect_to_mqtt(self): - self._mqttc.connect("broker.pikabot.org", 1883, 60) - # Enable this line if you are doing the snip code, off stress - self._mqttc.subscribe("pgo/#", 0) + try: + self._mqttc.connect("broker.pikabot.org", 1883, 60) + # Enable this line if you are doing the snip code, off stress + self._mqttc.subscribe("pgo/#", 0) + except TypeError: + return def run(self): self._mqttc.loop_forever() class SocialHandler(EventHandler): From 8408f5431e56309d95076db16c86b0aa2ef044ba Mon Sep 17 00:00:00 2001 From: Dmitry Ovodov Date: Fri, 26 Aug 2016 02:36:42 +0300 Subject: [PATCH 074/106] Decrease number of messages from MoveToFort worker --- pokemongo_bot/event_manager.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pokemongo_bot/event_manager.py b/pokemongo_bot/event_manager.py index 3d759bf666..70be9c16b2 100644 --- a/pokemongo_bot/event_manager.py +++ b/pokemongo_bot/event_manager.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals +from sys import stdout class EventNotRegisteredException(Exception): @@ -24,6 +25,7 @@ class EventManager(object): def __init__(self, *handlers): self._registered_events = dict() self._handlers = list(handlers) or [] + self._last_event = None def event_report(self): for event, parameters in self._registered_events.iteritems(): @@ -51,6 +53,11 @@ def emit(self, event, sender=None, level='info', formatted='', data={}): if event not in self._registered_events: raise EventNotRegisteredException("Event %s not registered..." % event) + if (event == self._last_event) and (event in ["moving_to_fort", "moving_to_lured_fort"]): + stdout.write("\033[1A\033[0K\r") + stdout.flush() + if level == "info" and formatted: self._last_event = event + # verify params match event parameters = self._registered_events[event] if parameters: From edcc2844f28a68e04e4defc23776d6229febd612 Mon Sep 17 00:00:00 2001 From: Official Repo Date: Thu, 25 Aug 2016 20:27:04 -0400 Subject: [PATCH 075/106] removed not needed text from manual install windows, added slackbot dll response --- docs/manual_installation.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/manual_installation.md b/docs/manual_installation.md index 0fc3254c6b..ceaba14ab9 100644 --- a/docs/manual_installation.md +++ b/docs/manual_installation.md @@ -94,7 +94,7 @@ source bin/activate ##### Requirements -- [Python 2.7.x](http://docs.python-guide.org/en/latest/starting/installation/) +- [Python 2.7.x](http://docs.python-guide.org/en/latest/starting/installation/) *Be sure to tick "Add python.exe to Path" during install* - [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) - [Microsoft Visual C++ Compiler for Python 2.7](http://www.microsoft.com/en-us/download/details.aspx?id=44266) @@ -107,8 +107,6 @@ pip2 install --upgrade pip pip2 install --upgrade virtualenv pip2 install --upgrade protobuf==3.0.0b4 git clone --recursive -b dev https://github.com/PokemonGoF/PokemonGo-Bot -pip2 install --upgrade "C:\Python27\PokemonGo-Bot\windows_bat\PyYAML-3.11-cp27-cp27m-win32.whl" -pip2 install --upgrade "C:\Python27\PokemonGo-Bot\windows_bat\PyYAML-3.11-cp27-cp27m-win_amd64.whl" pip2 install --upgrade -r C:/Python27/PokemonGo-Bot/requirements.txt cd C:/Python27/PokemonGo-Bot/ virtualenv . @@ -118,7 +116,7 @@ pip2 install --upgrade -r C:/Python27/PokemonGo-Bot/requirements.txt ##### Get encrypt.so and encrypt.dll or encrypt_64.dll Due to copywrite on the encrypt.so, encrypt.dll and encrypt_64.dll we are not directly hosting it. Please find a copy elsewhere on the internet and compile it yourself. We accept no responsibility should you encounter any problems with files you download elsewhere. -Try asking around our Slack chat! +Try asking around our Slack chat **(Just say the word "encrypt" and Slackbot will give you info)**! Download it to the `C:/Python27/PokemonGo-Bot/` folder From 0f58852adaf76140e13aa15f35f00b9b6e1727a0 Mon Sep 17 00:00:00 2001 From: william dutton Date: Fri, 26 Aug 2016 10:27:53 +1000 Subject: [PATCH 076/106] add badge messages and begin equip system --- pokemongo_bot/__init__.py | 60 ++++++++++++++++++- .../event_handlers/colored_logging_handler.py | 4 +- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 842664d7ef..0acd1b2691 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -37,6 +37,7 @@ from tree_config_builder import ConfigException, MismatchTaskApiVersion, TreeConfigBuilder from inventory import init_inventory from sys import platform as _platform +from pgoapi.protos.POGOProtos.Enums import BadgeType_pb2 import struct class PokemonGoBot(Datastore): @@ -74,6 +75,7 @@ def __init__(self, config): open(os.path.join(_base_dir, 'data', 'pokemon.json')) ) self.item_list = json.load(open(os.path.join(_base_dir, 'data', 'items.json'))) + # @var Metrics self.metrics = Metrics(self) self.latest_inventory = None self.cell = None @@ -148,6 +150,7 @@ def _setup_event_system(self): if self.config.websocket_remote_control: remote_control = WebsocketRemoteControl(self).start() + # @var EventManager self.event_manager = EventManager(*handlers) self._register_events() if self.config.show_events: @@ -587,6 +590,15 @@ def _register_events(self): self.event_manager.register_event('pokestop_log') self.event_manager.register_event('softban_log') + self.event_manager.register_event( + 'badges', + parameters=('badge', 'level') + ) + self.event_manager.register_event( + 'player_data', + parameters=('player_data', ) + ) + def tick(self): self.health_record.heartbeat() self.cell = self.get_meta_cell() @@ -847,7 +859,7 @@ def get_encryption_lib(self): return full_path def _setup_api(self): - # instantiate pgoapi + # instantiate pgoapi @var ApiWrapper self.api = ApiWrapper(config=self.config) # provide player position on the earth @@ -1159,7 +1171,51 @@ def heartbeat(self): request = self.api.create_request() request.get_player() request.check_awarded_badges() - request.call() + responses = request.call() + + if responses['responses']['GET_PLAYER']['success'] == True: + #we get the player_data anyway, might as well store it + self._player = responses['responses']['GET_PLAYER']['player_data'] + self.event_manager.emit( + 'player_data', + sender=self, + level='debug', + formatted='player_data: {player_data}', + data={'player_data': self._player} + ) + if responses['responses']['CHECK_AWARDED_BADGES']['success'] == True: + #store awarded_badges reponse to be used in a task or part of heartbeat + self._awarded_badges = responses['responses']['CHECK_AWARDED_BADGES'] + + if self._awarded_badges.has_key('awarded_badges'): + i = 0 + for badge in self._awarded_badges['awarded_badges'] : + badgelevel = self._awarded_badges['awarded_badge_levels'][i] + badgename = BadgeType_pb2._BADGETYPE.values_by_number[badge].name + i += 1 + self.event_manager.emit( + 'badges', + sender=self, + level='info', + formatted='awarded badge: {badge}, lvl {level}', + data={'badge': badgename, + 'level' : badgelevel } + ) + + #todo move equip badge into its own task once working + #should work but gives errors :'( + #response = self.api.equip_badge(badge_type=self._awarded_badges['awarded_badges']) + response = {'responses': "awaiting further testing on api call to equip_badge"} + self.event_manager.emit( + 'badges', + sender=self, + level='info', + formatted='equiped badge: {badge}', + data={'badge': response['responses']} + ) + human_behaviour.action_delay(3,10) + + try: self.web_update_queue.put_nowait(True) # do this outside of thread every tick except Queue.Full: diff --git a/pokemongo_bot/event_handlers/colored_logging_handler.py b/pokemongo_bot/event_handlers/colored_logging_handler.py index 0ce0a708cf..b15e3d8a8b 100644 --- a/pokemongo_bot/event_handlers/colored_logging_handler.py +++ b/pokemongo_bot/event_handlers/colored_logging_handler.py @@ -66,6 +66,7 @@ class ColoredLoggingHandler(EventHandler): 'path_lap_end': 'green', 'log_stats': 'magenta', 'show_inventory': 'magenta', + 'badges': 'blue', # event names for 'white' still here to remember that these events are already determined its color. 'arrived_at_cluster': 'white', @@ -99,7 +100,8 @@ class ColoredLoggingHandler(EventHandler): 'spun_fort': 'white', 'threw_berry': 'white', 'threw_pokeball': 'white', - 'used_lucky_egg': 'white' + 'used_lucky_egg': 'white', + 'player_data': 'white' } CONTINUOUS_EVENT_NAMES = [ 'catchable_pokemon', From cd2526d6829d3f4bae31df8f5d77c5aa4986b8cc Mon Sep 17 00:00:00 2001 From: DeXtroTip Date: Fri, 26 Aug 2016 01:45:45 +0100 Subject: [PATCH 077/106] Added colored logging --- pokemongo_bot/event_handlers/colored_logging_handler.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pokemongo_bot/event_handlers/colored_logging_handler.py b/pokemongo_bot/event_handlers/colored_logging_handler.py index 0ce0a708cf..cbf3aba7c8 100644 --- a/pokemongo_bot/event_handlers/colored_logging_handler.py +++ b/pokemongo_bot/event_handlers/colored_logging_handler.py @@ -66,6 +66,7 @@ class ColoredLoggingHandler(EventHandler): 'path_lap_end': 'green', 'log_stats': 'magenta', 'show_inventory': 'magenta', + 'show_best_pokemon': 'magenta', # event names for 'white' still here to remember that these events are already determined its color. 'arrived_at_cluster': 'white', From 6ec2e9df06e3e15dd5013a46299fd4f446987f93 Mon Sep 17 00:00:00 2001 From: Gobberwart Date: Fri, 26 Aug 2016 11:31:20 +1000 Subject: [PATCH 078/106] Close inventory file after use --- pokemongo_bot/inventory.py | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/pokemongo_bot/inventory.py b/pokemongo_bot/inventory.py index 29ea395903..7e2e5b90e2 100644 --- a/pokemongo_bot/inventory.py +++ b/pokemongo_bot/inventory.py @@ -1096,35 +1096,26 @@ def refresh(self): self.update_web_inventory() - def init_inventory_outfile(self): - web_inventory = os.path.join(_base_dir, "web", "inventory-%s.json" % self.bot.config.username) - - if not os.path.exists(web_inventory): - json_inventory = [] - - with open(web_inventory, "w") as outfile: - json.dump(json_inventory, outfile) - - def update_web_inventory(self): web_inventory = os.path.join(_base_dir, "web", "inventory-%s.json" % self.bot.config.username) - if not os.path.exists(web_inventory): - self.init_inventory_outfile() - - with open(web_inventory, "r") as infile: - json_inventory = json.load(infile) + if os.path.exists(web_inventory): + with open(web_inventory, "r") as infile: + json_inventory = json.load(infile) + infile.close() - json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("pokedex_entry", None)] - json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("candy", None)] - json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("item", None)] - json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("pokemon_data", None)] + json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("pokedex_entry", None)] + json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("candy", None)] + json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("item", None)] + json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("pokemon_data", None)] - json_inventory = json_inventory + self.jsonify_inventory() - json_inventory = self.jsonify_inventory() + json_inventory = json_inventory + self.jsonify_inventory() + else: + json_inventory = self.jsonify_inventory() with open(web_inventory, "w") as outfile: json.dump(json_inventory, outfile) + infile.close() def jsonify_inventory(self): json_inventory = [] From fe029ad341faac71a32a88be1da76c4dfa92d1ea Mon Sep 17 00:00:00 2001 From: Gobberwart Date: Fri, 26 Aug 2016 11:32:04 +1000 Subject: [PATCH 079/106] Revert "Close inventory file after use" This reverts commit 6ec2e9df06e3e15dd5013a46299fd4f446987f93. --- pokemongo_bot/inventory.py | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/pokemongo_bot/inventory.py b/pokemongo_bot/inventory.py index 7e2e5b90e2..29ea395903 100644 --- a/pokemongo_bot/inventory.py +++ b/pokemongo_bot/inventory.py @@ -1096,26 +1096,35 @@ def refresh(self): self.update_web_inventory() + def init_inventory_outfile(self): + web_inventory = os.path.join(_base_dir, "web", "inventory-%s.json" % self.bot.config.username) + + if not os.path.exists(web_inventory): + json_inventory = [] + + with open(web_inventory, "w") as outfile: + json.dump(json_inventory, outfile) + + def update_web_inventory(self): web_inventory = os.path.join(_base_dir, "web", "inventory-%s.json" % self.bot.config.username) - if os.path.exists(web_inventory): - with open(web_inventory, "r") as infile: - json_inventory = json.load(infile) - infile.close() + if not os.path.exists(web_inventory): + self.init_inventory_outfile() + + with open(web_inventory, "r") as infile: + json_inventory = json.load(infile) - json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("pokedex_entry", None)] - json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("candy", None)] - json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("item", None)] - json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("pokemon_data", None)] + json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("pokedex_entry", None)] + json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("candy", None)] + json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("item", None)] + json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("pokemon_data", None)] - json_inventory = json_inventory + self.jsonify_inventory() - else: - json_inventory = self.jsonify_inventory() + json_inventory = json_inventory + self.jsonify_inventory() + json_inventory = self.jsonify_inventory() with open(web_inventory, "w") as outfile: json.dump(json_inventory, outfile) - infile.close() def jsonify_inventory(self): json_inventory = [] From 5cab1844990b4cac57aaad2fcecc7e343f7bbd74 Mon Sep 17 00:00:00 2001 From: Gobberwart Date: Fri, 26 Aug 2016 11:37:34 +1000 Subject: [PATCH 080/106] Close inventory files after use --- pokemongo_bot/inventory.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pokemongo_bot/inventory.py b/pokemongo_bot/inventory.py index 29ea395903..328d0dbd1b 100644 --- a/pokemongo_bot/inventory.py +++ b/pokemongo_bot/inventory.py @@ -1114,6 +1114,7 @@ def update_web_inventory(self): with open(web_inventory, "r") as infile: json_inventory = json.load(infile) + infile.close() json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("pokedex_entry", None)] json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("candy", None)] From eb0107874eb9cddc830c8dc352106ddcbdf97f65 Mon Sep 17 00:00:00 2001 From: Gobberwart Date: Fri, 26 Aug 2016 11:38:01 +1000 Subject: [PATCH 081/106] Close inventory file after use --- pokemongo_bot/inventory.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pokemongo_bot/inventory.py b/pokemongo_bot/inventory.py index 328d0dbd1b..3413733aa0 100644 --- a/pokemongo_bot/inventory.py +++ b/pokemongo_bot/inventory.py @@ -1126,6 +1126,7 @@ def update_web_inventory(self): with open(web_inventory, "w") as outfile: json.dump(json_inventory, outfile) + outfile.close() def jsonify_inventory(self): json_inventory = [] From 763ae853f64df13df7133d310bb86ac27b66f236 Mon Sep 17 00:00:00 2001 From: =bbiiggppiigg <=bbiiggppiigg@gmail.com> Date: Fri, 26 Aug 2016 11:15:30 +0900 Subject: [PATCH 082/106] Change the default value to -1. Make sure this check is only enabled when threshold is set to a positive value. --- pokemongo_bot/cell_workers/pokemon_catch_worker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index 1fa2a5f7d2..e9c645ee36 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -222,8 +222,8 @@ def _pokemon_matches_config(self, config, pokemon, default_logic='and'): } candies = inventory.candies().get(pokemon.pokemon_id).quantity - threshold = pokemon_config.get('candy_threshold', False) - if( threshold > 0 and candies > threshold ): + threshold = pokemon_config.get('candy_threshold', -1 ) + if( threshold > 0 and candies >= threshold ): self.emit_event( 'ignore_candy_above_thresold', level='info', From 4ad7011182c7f673be34b28dc2a7099e5fb59972 Mon Sep 17 00:00:00 2001 From: Simba Zhang Date: Thu, 25 Aug 2016 20:56:07 -0700 Subject: [PATCH 083/106] infoWindow.open(map, marker); to disable at the time. --- map-chat/javascript/map.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/map-chat/javascript/map.js b/map-chat/javascript/map.js index 8d11d4cb69..4e1e06e8a5 100644 --- a/map-chat/javascript/map.js +++ b/map-chat/javascript/map.js @@ -279,7 +279,8 @@ function displayMessageOnMap(msg, olat, olong, sessid, icostr, expir, pokenick) var infoWindow = markerMap.infoWindow; if (!markersMap[msgSessionId]) { // new marker - infoWindow.open(map, marker); + //disable it for now + //infoWindow.open(map, marker); var timeoutId = setTimeout(function () { infoWindow.close() }, 10000); markersMap[msgSessionId] = { From 3622c032257887e5898778635c7382017879dafe Mon Sep 17 00:00:00 2001 From: Simba Zhang Date: Thu, 25 Aug 2016 21:07:49 -0700 Subject: [PATCH 084/106] Disable shelve for now. --- pokemongo_bot/__init__.py | 22 ++++++++++++---------- pokemongo_bot/health_record/bot_event.py | 20 +++++++++++--------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index dde48eae21..a27292ea2a 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -101,16 +101,18 @@ def __init__(self, config): self.capture_locked = False # lock catching while moving to VIP pokemon - client_id_file_path = os.path.join(_base_dir, 'data', 'mqtt_client_id') - saved_info = shelve.open(client_id_file_path) - if saved_info.has_key('client_id'): - self.config.client_id = saved_info['client_id'] - else: - client_uuid = uuid.uuid4() - self.config.client_id = str(client_uuid) - saved_info['client_id'] = self.config.client_id - saved_info.close() - + #client_id_file_path = os.path.join(_base_dir, 'data', 'mqtt_client_id') + #saved_info = shelve.open(client_id_file_path) + #if saved_info.has_key('client_id'): + # self.config.client_id = saved_info['client_id'] + #else: + # client_uuid = uuid.uuid4() + # self.config.client_id = str(client_uuid) + # saved_info['client_id'] = self.config.client_id + #saved_info.close() + # There's issue report, just disable this part. + client_uuid = uuid.uuid4() + self.config.client_id = str(client_uuid) def start(self): self._setup_event_system() self._setup_logging() diff --git a/pokemongo_bot/health_record/bot_event.py b/pokemongo_bot/health_record/bot_event.py index 28d3943a52..d967b7c0ba 100644 --- a/pokemongo_bot/health_record/bot_event.py +++ b/pokemongo_bot/health_record/bot_event.py @@ -16,15 +16,17 @@ class BotEvent(object): def __init__(self, config): self.config = config self.logger = logging.getLogger(__name__) - client_id_file_path = os.path.join(_base_dir, 'data', 'client_id') - saved_info = shelve.open(client_id_file_path) - if saved_info.has_key('client_id'): - self.client_id = saved_info['client_id'] - else: - client_uuid = uuid.uuid4() - self.client_id = str(client_uuid) - saved_info['client_id'] = self.client_id - saved_info.close() + #client_id_file_path = os.path.join(_base_dir, 'data', 'client_id') + #saved_info = shelve.open(client_id_file_path) + #if saved_info.has_key('client_id'): + # self.client_id = saved_info['client_id'] + #else: + # client_uuid = uuid.uuid4() + # self.client_id = str(client_uuid) + # saved_info['client_id'] = self.client_id + #saved_info.close() + client_uuid = uuid.uuid4() + self.client_id = str(client_uuid) # UniversalAnalytics can be reviewed here: # https://github.com/analytics-pros/universal-analytics-python if self.config.health_record: From f6aca81c53a0f9a4c6cfc8252d9105950b6c664f Mon Sep 17 00:00:00 2001 From: DeXtroTip Date: Fri, 26 Aug 2016 06:06:39 +0100 Subject: [PATCH 085/106] Fixed first egg incubate wrong stats (#4748) --- pokemongo_bot/cell_workers/incubate_eggs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pokemongo_bot/cell_workers/incubate_eggs.py b/pokemongo_bot/cell_workers/incubate_eggs.py index 7b705ceb8c..c794b378be 100644 --- a/pokemongo_bot/cell_workers/incubate_eggs.py +++ b/pokemongo_bot/cell_workers/incubate_eggs.py @@ -135,8 +135,8 @@ def _check_inventory(self, lookup_ids=[]): incubators = [incubators] for incubator in incubators: if 'pokemon_id' in incubator: - start_km = incubator.get('start_km_walked', 9001) - km_walked = incubator.get('target_km_walked', 9001) + start_km = incubator.get('start_km_walked', 0) + km_walked = incubator.get('target_km_walked', 0) temp_used_incubators.append({ "id": incubator.get('id', -1), "km": km_walked, From a279fee95c461d64eec4bffdc0ebef60fc6a67f9 Mon Sep 17 00:00:00 2001 From: william dutton Date: Fri, 26 Aug 2016 15:47:36 +1000 Subject: [PATCH 086/106] move equip_badge and dely into for loop just in case multiple badges come up --- pokemongo_bot/__init__.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index f4583c5578..8dfb1efd6b 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -1209,7 +1209,7 @@ def heartbeat(self): if self._awarded_badges.has_key('awarded_badges'): i = 0 - for badge in self._awarded_badges['awarded_badges'] : + for badge in self._awarded_badges['awarded_badges']: badgelevel = self._awarded_badges['awarded_badge_levels'][i] badgename = BadgeType_pb2._BADGETYPE.values_by_number[badge].name i += 1 @@ -1222,18 +1222,18 @@ def heartbeat(self): 'level' : badgelevel } ) - #todo move equip badge into its own task once working - #should work but gives errors :'( - #response = self.api.equip_badge(badge_type=self._awarded_badges['awarded_badges']) - response = {'responses': "awaiting further testing on api call to equip_badge"} - self.event_manager.emit( - 'badges', - sender=self, - level='info', - formatted='equiped badge: {badge}', - data={'badge': response['responses']} - ) - human_behaviour.action_delay(3,10) + #todo move equip badge into its own task once working + #should work but gives errors :'(s + #response = self.api.equip_badge(badge_type=badge) + response = {'responses': "awaiting further testing on api call to equip_badge"} + self.event_manager.emit( + 'badges', + sender=self, + level='info', + formatted='equiped badge: {badge}', + data={'badge': response['responses']} + ) + human_behaviour.action_delay(3,10) try: From 09403f5ff023f98086f97f647beb344b89188ae0 Mon Sep 17 00:00:00 2001 From: Matt J Madsen Date: Fri, 26 Aug 2016 01:06:09 -0500 Subject: [PATCH 087/106] Fix shelve key error (#4753) --- pokemongo_bot/__init__.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index a27292ea2a..f9c3362de7 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -101,18 +101,16 @@ def __init__(self, config): self.capture_locked = False # lock catching while moving to VIP pokemon - #client_id_file_path = os.path.join(_base_dir, 'data', 'mqtt_client_id') - #saved_info = shelve.open(client_id_file_path) - #if saved_info.has_key('client_id'): - # self.config.client_id = saved_info['client_id'] - #else: - # client_uuid = uuid.uuid4() - # self.config.client_id = str(client_uuid) - # saved_info['client_id'] = self.config.client_id - #saved_info.close() - # There's issue report, just disable this part. - client_uuid = uuid.uuid4() - self.config.client_id = str(client_uuid) + client_id_file_path = os.path.join(_base_dir, 'data', 'mqtt_client_id') + saved_info = shelve.open(client_id_file_path) + key = 'client_id'.encode('utf-8') + if key in saved_info: + self.config.client_id = saved_info[key] + else: + self.config.client_id = str(uuid.uuid4()) + saved_info[key] = self.config.client_id + saved_info.close() + def start(self): self._setup_event_system() self._setup_logging() From 0ec0777df2922c4ef7e634bb852be5d7e3e4b5e4 Mon Sep 17 00:00:00 2001 From: Gobberwart Date: Fri, 26 Aug 2016 17:11:50 +1000 Subject: [PATCH 088/106] Removed incorrect call Removed call to self.jsonify_inventory that results in player_stats disappearing. --- pokemongo_bot/inventory.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pokemongo_bot/inventory.py b/pokemongo_bot/inventory.py index 3413733aa0..eedd9c207d 100644 --- a/pokemongo_bot/inventory.py +++ b/pokemongo_bot/inventory.py @@ -1122,7 +1122,6 @@ def update_web_inventory(self): json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("pokemon_data", None)] json_inventory = json_inventory + self.jsonify_inventory() - json_inventory = self.jsonify_inventory() with open(web_inventory, "w") as outfile: json.dump(json_inventory, outfile) From d313efc4d2cb64040f6ab4ee592dc8499791bb4e Mon Sep 17 00:00:00 2001 From: LuckyMe4Evers Date: Fri, 26 Aug 2016 15:35:21 +0200 Subject: [PATCH 089/106] PokemonGo-Bot-Configurator Added PokemonGo-Bot-Configurator so people can use this to create there config.json and userdata.js. Adapted some config.json.examples files toward the compatible printout of the config.json Added instructions in installation.md --- configs/config.json.cluster.example | 2 +- configs/config.json.example | 2 +- configs/config.json.map.example | 2 +- configs/config.json.pokemon.example | 2 +- docs/installation.md | 5 +- windows_bat/PokemonGo-Bot-Configurator.bat | 244 +++++++++++++++++++++ 6 files changed, 251 insertions(+), 6 deletions(-) create mode 100644 windows_bat/PokemonGo-Bot-Configurator.bat diff --git a/configs/config.json.cluster.example b/configs/config.json.cluster.example index 2cc12c0489..0a606aa84a 100644 --- a/configs/config.json.cluster.example +++ b/configs/config.json.cluster.example @@ -255,7 +255,7 @@ "// Zubat": {"keep_best_cp": 2, "keep_best_iv": 3} }, "vips" : { - "Any pokemon put here directly force to use Berry & Best Ball to capture, to secure the capture rate!": {}, + "Any pokemon put here directly force to use Berry & Best Ball to capture, to secure the capture rate": {}, "any": {"catch_above_cp": 1200, "catch_above_iv": 0.9, "logic": "or" }, "Lapras": {}, "Moltres": {}, diff --git a/configs/config.json.example b/configs/config.json.example index 31d62527a6..80acc11c82 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -286,7 +286,7 @@ "// Zubat": {"keep_best_custom": "iv, cp, hp_max", "amount":2} }, "vips" : { - "Any pokemon put here directly force to use Berry & Best Ball to capture, to secure the capture rate!": {}, + "Any pokemon put here directly force to use Berry & Best Ball to capture, to secure the capture rate": {}, "any": {"catch_above_cp": 1200, "catch_above_iv": 0.9, "logic": "or" }, "Lapras": {}, "Moltres": {}, diff --git a/configs/config.json.map.example b/configs/config.json.map.example index fbf6d22dd5..d925070b03 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -511,7 +511,7 @@ "// Zubat": {"keep_best_cp": 2, "keep_best_iv": 3} }, "vips" : { - "Any pokemon put here directly force to use Berry & Best Ball to capture, to secure the capture rate!": {}, + "Any pokemon put here directly force to use Berry & Best Ball to capture, to secure the capture rate": {}, "any": {"catch_above_cp": 1200, "catch_above_iv": 0.9, "logic": "or" }, "Lapras": {}, "Moltres": {}, diff --git a/configs/config.json.pokemon.example b/configs/config.json.pokemon.example index fff5d8989f..7998020f9c 100644 --- a/configs/config.json.pokemon.example +++ b/configs/config.json.pokemon.example @@ -488,7 +488,7 @@ "Mr. Mime": { "release_below_cp": 650, "release_below_iv": 0.8, "logic": "and" } }, "vips" : { - "Any pokemon put here directly force to use Berry & Best Ball to capture, to secure the capture rate!": {}, + "Any pokemon put here directly force to use Berry & Best Ball to capture, to secure the capture rate": {}, "any": {"catch_above_cp": 1200, "catch_above_iv": 0.9, "logic": "or" }, "Lapras": {}, "Moltres": {}, diff --git a/docs/installation.md b/docs/installation.md index 5b1136ce06..7cc771435b 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -38,11 +38,12 @@ We do recommend Windows users to use [Docker](#docker) this will work much easie 2. Download `encrypt.so` and `encrypt.dll` or `encrypt_64.dll` to the same folder of the `PokemonGo-Bot-Install.bat`. 3. Run `PokemonGo-Bot-install.bat`. After that has been done the bot will be installed. -4. Run `PokemonGo-Bot-Start.bat`. +4. Run `PokemonGo-Bot-Configurator` to create config.json and userdata.js. +5. Run `PokemonGo-Bot-Start.bat`. This will start the bot and the web interface. ### To update the bot -3. Run `PokemonGo-Bot-Start.bat` +1. Run `PokemonGo-Bot-Start.bat` This will check for an update and will start the bot afterwards. # Docker diff --git a/windows_bat/PokemonGo-Bot-Configurator.bat b/windows_bat/PokemonGo-Bot-Configurator.bat new file mode 100644 index 0000000000..36aee8b218 --- /dev/null +++ b/windows_bat/PokemonGo-Bot-Configurator.bat @@ -0,0 +1,244 @@ +TITLE PokemonGo-Bot Configurator +cls +@ECHO Off + +:init +SETLOCAL DisableDelayedExpansion +path c:\Program Files\Git\cmd;%PATH% +path C:\Python27;%PATH% +path C:\Python27\Scripts;%PATH% +SET "batchPath=%~0" +FOR %%k in (%0) do SET batchName=%%~nk +SET "vbsGetPrivileges=%temp%\OEgetPriv_%batchName%.vbs" +SET BatPath=%~dp0 +SET BotPath=%BatPath:~0,-13% +SET ConFigPath=%BotPath%\configs\ +SET UserDataPath=%BotPath%\Web\config\ +SET config=%ConFigPath%config.json +SET UserData=%UserDataPath%userdata.js +SETLOCAL EnableDelayedExpansion + + + +:checkPrivileges +NET FILE 1>NUL 2>NUL +if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges ) + + + +:getPrivileges +if '%1'=='ELEV' (ECHO ELEV & shift /1 & goto gotPrivileges) +@ECHO SET UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%" +@ECHO args = "ELEV " >> "%vbsGetPrivileges%" +@ECHO For Each strArg in WScript.Arguments >> "%vbsGetPrivileges%" +@ECHO args = args ^& strArg ^& " " >> "%vbsGetPrivileges%" +@ECHO Next >> "%vbsGetPrivileges%" +@ECHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >> "%vbsGetPrivileges%" +"%SystemRoot%\System32\WScript.exe" "%vbsGetPrivileges%" %* +exit /B + + + +:gotPrivileges +SETlocal & pushd . +cd /d %~dp0 +if '%1'=='ELEV' (del "%vbsGetPrivileges%" 1>nul 2>nul & shift /1) + +:ConfigStart +ECHO. +ECHO. +ECHO.--------------------PokemonGo-Bot Configurator-------------------- +ECHO. +ECHO. +ECHO. The PokemonGo-Bot Configurator creates the needed config.json and userdata.js +ECHO. +ECHO. It only configures the needed info to start running the PokemonGo-Bot. +ECHO. +ECHO. To fine tune your config.json you will have to edit the file +ECHO. +ECHO. +ECHO. +timeout /t 10 + +:Warning +cls +IF EXIST "%ConFigPath%config.json" ( +color C +ECHO. +ECHO. +ECHO.--------------------PokemonGo-Bot Config Warning-------------------- +ECHO. +ECHO. +ECHO.============================================================================= +ECHO.= = +ECHO.= WARNING - Your existing config.json and/or userdata.js will be overwriten = +ECHO.= = +ECHO.= Press Enter to abort in next screen or make a choice to continue = +ECHO.= = +ECHO.============================================================================= +ECHO. +timeout /t 5 +) ELSE ( +ECHO. +) +:Menu +cls +color 7 +ECHO. +ECHO. +ECHO.--------------------PokemonGo-Bot Config Choice-------------------- +ECHO. +ECHO. First create your config.json and then your userdata.js. +ECHO. +ECHO. 1 - Normal config.json +ECHO. +ECHO. 2 - Cluster config.json +ECHO. +ECHO. 3 - Map config.json +ECHO. +ECHO. 4 - Optimizer config.json +ECHO. +ECHO. 5 - Path config.json +ECHO. +ECHO. 6 - Pokemon config.json +ECHO. +ECHO. 7 - userdata.js +ECHO. +ECHO. + +:_choice +SET _ok= +SET /p _ok= Choose your config.json or press Enter to close: ||goto:eof +IF "%_ok%" == "1" SET CHOICE=Normal&GOTO :Normal +IF "%_ok%" == "2" SET CHOICE=Cluster&GOTO :Cluster +IF "%_ok%" == "3" SET CHOICE=Map&GOTO :Map +IF "%_ok%" == "4" SET CHOICE=Optimizer&GOTO :Optimizer +IF "%_ok%" == "5" SET CHOICE=Path&GOTO :Path +IF "%_ok%" == "6" SET CHOICE=Pokemon&GOTO :Pokemon +IF "%_ok%" == "7" SET CHOICE=UserData&GOTO :UserData +GOTO :_choice + +:Normal +call:ConfigMake %ConFigPath%config.json.example +goto:Menu + +:Cluster +call:ConfigMake %ConFigPath%config.json.cluster.example +goto:Menu + +:Map +call:ConfigMake %ConFigPath%config.json.map.example +goto:Menu + +:Optimizer +call:ConfigMake %ConFigPath%config.json.optimizer.example +goto:Menu + +:Path +call:ConfigMake %ConFigPath%config.json.path.example +goto:Menu + +:Pokemon +call:ConfigMake %ConFigPath%config.json.pokemon.example +goto:Menu + +:ConfigMake +cls +ECHO. +ECHO. +ECHO.--------------------PokemonGo-Bot config.json creator-------------------- +ECHO. +ECHO. +ECHO.{>%config% +SET /p auth_service="What AUTH SERVICE are you using ? google or ptc ?: " +ECHO. "auth_service": "%auth_service%",>>%config% +ECHO. +Set /p YOUR_USERNAME="What's your username ?: " +ECHO. "username": "%YOUR_USERNAME%",>>%config% +ECHO. +SET /p YOUR_PASSWORD="What's your password ?: " +ECHO. "password": "%YOUR_PASSWORD%",>>%config% +ECHO. +SET /p SOME_LOCATION="What's the location you want to search ?: " +ECHO. "location": "%SOME_LOCATION%",>>%config% +ECHO. +ECHO. "favorite_locations":[>>%config% +ECHO. {"name": "Milan", "coords": "45.472849,9.177567"}>>%config% +ECHO. +ECHO.Adding Favorite Locations.... +ECHO. +call:morefav +ECHO. +ECHO. ],>>%config% +SET /p GOOGLE_API="What's your Google Maps API Key ?: " +ECHO. "gmapkey": "%GOOGLE_API%",>>%config% +ECHO. +ECHO. +FOR /F "Skip=9 usebackq delims=" %%a in (`"findstr /n ^^ %~1"`) do ( + set "myVar=%%a" + call :processLine myVar +) +goto :eof + +:processLine +SETLOCAL EnableDelayedExpansion +set "line=!%1!" +set "line=!line:*:=!" +echo(!line!>>%config% +ENDLOCAL +goto :eof + +:morefav +SET _answer= +SET name= +SET coords= +ECHO. +SET /p _answer="Do you want to add more favorite locations (Y/N) ?: " +IF "%_answer%" == "y" goto :favorite +IF "%_answer%" == "n" goto :eof +:favorite +ECHO. +ECHO. +SET /p name="What City do you want to add ?: " +SET /p coords="What coordinates has that City ? (example: 45.472849,9.177567 ): " +ECHO. {"name": "%name%", "coords": "%coords%"}>>%config% +goto:morefav + +:UserData +ECHO. +ECHO. +ECHO.--------------------PokemonGo-Bot userdata.js creator-------------------- +ECHO. +ECHO. +ECHO.// MUST CONFIGURE THE USER ARRAY AND GOOGLE MAPS API KEY.>%UserData% +ECHO.// YOU CAN GET A KEY HERE: https://developers.google.com/maps/documentation/javascript/get-api-key>>%UserData% +ECHO.var userInfo = {>>%UserData% +Set /p users="What's the username to use ?: " +ECHO. users: ["%users%"],>>%UserData% +ECHO. userZoom: true,>>%UserData% +ECHO. zoom: 16,>>%UserData% +ECHO. userFollow: true,>>%UserData% +SET /p API="What's your Google Maps API Key ?: " +ECHO. gMapsAPIKey: "%API%",>>%UserData% +ECHO. botPath: true,>>%UserData% +ECHO. actionsEnabled: false>>%UserData% +ECHO.};>>%UserData% +call:EndUserData +goto:eof + +:EndUserData +cls +ECHO. +ECHO. +ECHO.Your %config% and %UserData% has been made. +ECHO. +ECHO.If you want to customize your %config% then you have to edit him. +ECHO. +ECHO.After that you are ready to start the bot. +ECHO. +ECHO. +timeout /t 10 +goto:eof + +:eof +exit \ No newline at end of file From 5ce5df31603107a3debde8274c7d092c946fa4d2 Mon Sep 17 00:00:00 2001 From: jasper Date: Fri, 26 Aug 2016 17:09:37 +0200 Subject: [PATCH 090/106] Move to map max distance was broken because 'continue' would never trigger with snipe enabled. --- pokemongo_bot/cell_workers/move_to_map_pokemon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index 0fca54c71b..b4b5be3f87 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -132,7 +132,7 @@ def get_pokemon_from_social(self): pokemon['longitude'], ) - if pokemon['dist'] > self.config['max_distance'] and not self.config['snipe']: + if pokemon['dist'] > self.config['max_distance'] or not self.config['snipe']: continue # pokemon not reachable with mean walking speed (by config) From 3071675e14e3884712c6d611a196fb613f521a27 Mon Sep 17 00:00:00 2001 From: jasper Date: Fri, 26 Aug 2016 19:27:32 +0200 Subject: [PATCH 091/106] Channel check for stability @main.js; Readability improvement @social_handler.py --- map-chat/javascript/main.js | 11 ++++------- pokemongo_bot/event_handlers/social_handler.py | 3 ++- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/map-chat/javascript/main.js b/map-chat/javascript/main.js index 7be811c52a..d09e798edc 100644 --- a/map-chat/javascript/main.js +++ b/map-chat/javascript/main.js @@ -20,7 +20,7 @@ function initialiseEventBus(){ Materialize.toast(message_data, 5000); var msg = JSON.parse(payload); console.info('[CHAT]', '(' + msg.lat + ',' + msg.lng + '): ', msg.text); - } else { + } else if (/^pgomapcatch\/all\/catchable/i.test(topic)) { //@ro: let's grab the message and split that shit. (simple for now, maybe we could just parse the json instead) var pLoadR = payload.toString(); var pLoadR2 = pLoadR.split(","); @@ -34,12 +34,9 @@ function initialiseEventBus(){ var icon = path + "0" + ico + ".png" var icostr = icon.toString(); displayMessageOnMap(payload, olat, olong, sessid, icostr, expir, pokenick); - - if (/^pgomapcatch\/all\/catchable/i.test(topic)) { - console.debug('[CATCHABLE]', pokenick, '(' + olat + ',' + olong + ')'); - } else { - console.debug(topic); - } + console.debug('[CATCHABLE]', pokenick, '(' + olat + ',' + olong + ')'); + } else { + console.debug(topic); } }); } diff --git a/pokemongo_bot/event_handlers/social_handler.py b/pokemongo_bot/event_handlers/social_handler.py index d19f578f73..6d850e7321 100644 --- a/pokemongo_bot/event_handlers/social_handler.py +++ b/pokemongo_bot/event_handlers/social_handler.py @@ -70,7 +70,8 @@ def handle_event(self, event, sender, level, formatted_msg, data): #geo_hash = Geohash.encode(data['latitude'], data['longitude'], precision=4) #self.mqttc.publish("pgomapgeo/"+geo_hash+"/"+str(data['pokemon_id']), str(data['latitude'])+","+str(data['longitude'])+","+str(data['encounter_id'])+","+str(data['pokemon_id'])+","+str(data['expiration_timestamp_ms'])+","+str(data['pokemon_name'])) #{u'pokemon_id': 13, u'expiration_timestamp_ms': 1472017713812L, u'longitude': 4.897220519201337, u'latitude': 52.33937206069979, u'spawn_point_id': u'47c60a241ad', u'encounter_id': 13653280540966083917L} - self.mqttc.publish("pgomapcatch/all/catchable/"+str(data['pokemon_id']), str(data['latitude'])+","+str(data['longitude'])+","+str(data['encounter_id'])+","+str(data['pokemon_id'])+","+str(data['expiration_timestamp_ms'])+","+str(data['pokemon_name'])) + data_string = "%s, %s, %s, %s, %s, %s" % (str(data['latitude']), str(data['longitude']), str(data['encounter_id']), str(data['pokemon_id']), str(data['expiration_timestamp_ms']), str(data['pokemon_name'])) + self.mqttc.publish("pgomapcatch/all/catchable/" + str(data['pokemon_id']), data_string) json_data = json.dumps(data) self.mqttc.publish("pgo/all/catchable/"+str(data['pokemon_id']), json_data) From d9aa105af8759888b3fbc3c48043d1d56a10b089 Mon Sep 17 00:00:00 2001 From: Matt J Madsen Date: Fri, 26 Aug 2016 12:42:00 -0500 Subject: [PATCH 092/106] Revert #4712 --- pokemongo_bot/metrics.py | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/pokemongo_bot/metrics.py b/pokemongo_bot/metrics.py index 79e0b2eca7..775258155d 100644 --- a/pokemongo_bot/metrics.py +++ b/pokemongo_bot/metrics.py @@ -7,15 +7,15 @@ class Metrics(object): def __init__(self, bot): self.bot = bot self.start_time = time.time() - self.dust = {'start': 0, 'latest': 0} - self.xp = {'start': 0, 'latest': 0} - self.distance = {'start': 0, 'latest': 0} - self.encounters = {'start': 0, 'latest': 0} - self.throws = {'start': 0, 'latest': 0} - self.captures = {'start': 0, 'latest': 0} - self.visits = {'start': 0, 'latest': 0} - self.unique_mons = {'start': 0, 'latest': 0} - self.evolutions = {'start': 0, 'latest': 0} + self.dust = {'start': -1, 'latest': -1} + self.xp = {'start': -1, 'latest': -1} + self.distance = {'start': -1, 'latest': -1} + self.encounters = {'start': -1, 'latest': -1} + self.throws = {'start': -1, 'latest': -1} + self.captures = {'start': -1, 'latest': -1} + self.visits = {'start': -1, 'latest': -1} + self.unique_mons = {'start': -1, 'latest': -1} + self.evolutions = {'start': -1, 'latest': -1} self.releases = 0 self.highest_cp = {'cp': 0, 'desc': ''} @@ -100,6 +100,7 @@ def capture_stats(self): request = self.bot.api.create_request() except AttributeError: return + request.get_inventory() request.get_player() response_dict = request.call() @@ -108,20 +109,38 @@ def capture_stats(self): self.dust['latest'] = response_dict['responses']['GET_PLAYER']['player_data']['currencies'][1]['amount'] if self.dust['start'] < 0: self.dust['start'] = self.dust['latest'] + for item in response_dict['responses']['GET_INVENTORY']['inventory_delta']['inventory_items']: if 'inventory_item_data' in item: if 'player_stats' in item['inventory_item_data']: playerdata = item['inventory_item_data']['player_stats'] self.xp['latest'] = playerdata.get('experience', 0) + if self.xp['start'] < 0: self.xp['start'] = self.xp['latest'] + self.visits['latest'] = playerdata.get('poke_stop_visits', 0) + if self.visits['start'] < 0: self.visits['start'] = self.visits['latest'] + self.captures['latest'] = playerdata.get('pokemons_captured', 0) + if self.captures['start'] < 0: self.captures['start'] = self.captures['latest'] + self.distance['latest'] = playerdata.get('km_walked', 0) + if self.distance['start'] < 0: self.distance['start'] = self.distance['latest'] + self.encounters['latest'] = playerdata.get('pokemons_encountered', 0) + if self.encounters['start'] < 0: self.encounters['start'] = self.encounters['latest'] + self.throws['latest'] = playerdata.get('pokeballs_thrown', 0) + if self.throws['start'] < 0: self.throws['start'] = self.throws['latest'] + self.unique_mons['latest'] = playerdata.get('unique_pokedex_entries', 0) + if self.unique_mons['start'] < 0: self.unique_mons['start'] = self.unique_mons['latest'] + self.visits['latest'] = playerdata.get('poke_stop_visits', 0) + if self.visits['start'] < 0: self.visits['start'] = self.visits['latest'] + self.evolutions['latest'] = playerdata.get('evolutions', 0) + if self.evolutions['start'] < 0: self.evolutions['start'] = self.evolutions['latest'] elif 'pokedex_entry' in item['inventory_item_data']: entry = item['inventory_item_data']['pokedex_entry'].get('pokemon_id') if entry: uniq_pokemon_list.add(entry) From 0c225a8ae6dbd17c4f5d766eb9ef659983d8ae5d Mon Sep 17 00:00:00 2001 From: jasper Date: Fri, 26 Aug 2016 19:59:29 +0200 Subject: [PATCH 093/106] Remove encounter-id --- pokemongo_bot/event_handlers/social_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pokemongo_bot/event_handlers/social_handler.py b/pokemongo_bot/event_handlers/social_handler.py index 6d850e7321..50cb68135d 100644 --- a/pokemongo_bot/event_handlers/social_handler.py +++ b/pokemongo_bot/event_handlers/social_handler.py @@ -70,7 +70,7 @@ def handle_event(self, event, sender, level, formatted_msg, data): #geo_hash = Geohash.encode(data['latitude'], data['longitude'], precision=4) #self.mqttc.publish("pgomapgeo/"+geo_hash+"/"+str(data['pokemon_id']), str(data['latitude'])+","+str(data['longitude'])+","+str(data['encounter_id'])+","+str(data['pokemon_id'])+","+str(data['expiration_timestamp_ms'])+","+str(data['pokemon_name'])) #{u'pokemon_id': 13, u'expiration_timestamp_ms': 1472017713812L, u'longitude': 4.897220519201337, u'latitude': 52.33937206069979, u'spawn_point_id': u'47c60a241ad', u'encounter_id': 13653280540966083917L} - data_string = "%s, %s, %s, %s, %s, %s" % (str(data['latitude']), str(data['longitude']), str(data['encounter_id']), str(data['pokemon_id']), str(data['expiration_timestamp_ms']), str(data['pokemon_name'])) + data_string = "%s, %s, %s, %s, %s" % (str(data['latitude']), str(data['longitude']), str(data['pokemon_id']), str(data['expiration_timestamp_ms']), str(data['pokemon_name'])) self.mqttc.publish("pgomapcatch/all/catchable/" + str(data['pokemon_id']), data_string) json_data = json.dumps(data) self.mqttc.publish("pgo/all/catchable/"+str(data['pokemon_id']), json_data) From 49b5279f1de7e88d203e269f968e85c4a03ba997 Mon Sep 17 00:00:00 2001 From: Simba Zhang Date: Fri, 26 Aug 2016 11:57:51 -0700 Subject: [PATCH 094/106] Can snipe more than one pokemon in snipe_high_prio_only mode. --- pokemongo_bot/__init__.py | 2 +- .../cell_workers/move_to_map_pokemon.py | 35 ++++++-- .../event_handlers/social_handler.py | 85 +++++++++++++------ 3 files changed, 87 insertions(+), 35 deletions(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index f9c3362de7..a515052b62 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -110,7 +110,7 @@ def __init__(self, config): self.config.client_id = str(uuid.uuid4()) saved_info[key] = self.config.client_id saved_info.close() - + def start(self): self._setup_event_system() self._setup_logging() diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index 0fca54c71b..9964ea6973 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -79,6 +79,11 @@ # Number of seconds to sleep between teleporting to a snipped Pokemon. SNIPE_SLEEP_SEC = 2 +# Max Sniping in chain +SNIPE_MAX_IN_CHAIN = 2 + +# Don't call sniper every time in workers +SNIPE_SKIP_IN_ROUND = 30 class MoveToMapPokemon(BaseTask): """Task for moving a trainer to a Pokemon.""" @@ -94,6 +99,7 @@ def initialize(self): self.walker = self.config.get('walker', 'StepWalker') self.snipe_high_prio_only = self.config.get('snipe_high_prio_only', False) self.snipe_high_prio_threshold = self.config.get('snipe_high_prio_threshold', 400) + self.by_pass_times = 0 data_file = os.path.join(_base_dir, 'map-caught-{}.json'.format(self.bot.config.username)) if os.path.isfile(data_file): @@ -109,8 +115,10 @@ def get_pokemon_from_social(self): pokemon_list = [] now = int(time.time()) + tmp_pokemon_list = self.bot.mqtt_pokemon_list + self.bot.mqtt_pokemon_list = [] - for pokemon in self.bot.mqtt_pokemon_list: + for pokemon in tmp_pokemon_list: pokemon['encounter_id'] = pokemon['encounter_id'] pokemon['spawn_point_id'] = pokemon['spawn_point_id'] pokemon['disappear_time'] = int(pokemon['expiration_timestamp_ms'] / 1000) @@ -140,7 +148,6 @@ def get_pokemon_from_social(self): if pokemon['dist'] > ((pokemon['disappear_time'] - now) * mean_walk_speed) and not self.config['snipe']: continue pokemon_list.append(pokemon) - self.bot.mqtt_pokemon_list = [] return pokemon_list def get_pokemon_from_map(self): try: @@ -289,11 +296,11 @@ def work(self): if (pokeballs_quantity + superballs_quantity + ultraballs_quantity) < self.min_ball: return WorkerResult.SUCCESS - self.update_map_location() self.dump_caught_pokemon() if self.bot.config.enable_social: pokemon_list = self.get_pokemon_from_social() else: + self.update_map_location() pokemon_list = self.get_pokemon_from_map() pokemon_list.sort(key=lambda x: x['dist']) @@ -303,16 +310,32 @@ def work(self): pokemon_list.sort(key=lambda x: x['is_vip'], reverse=True) if len(pokemon_list) < 1: + #print 'No enough pokemon in list to snip' return WorkerResult.SUCCESS pokemon = pokemon_list[0] - + #print 'How many pokemon in list: {}'.format(len(pokemon_list)) if self.config['snipe']: + self.by_pass_times = self.by_pass_times + 1 + if self.by_pass_times < SNIPE_SKIP_IN_ROUND: + return WorkerResult.SUCCESS + self.by_pass_times = 0 if self.snipe_high_prio_only: - if self.snipe_high_prio_threshold < pokemon['priority']: - self.snipe(pokemon) + count = 0 + for pokemon in pokemon_list: + if self.snipe_high_prio_threshold < pokemon['priority']: + self.snipe(pokemon) + count = count +1 + if count >= SNIPE_MAX_IN_CHAIN: + return WorkerResult.SUCCESS + if count is not 1: + time.sleep(SNIPE_SLEEP_SEC*5) + #else: + # print 'this pokemon is not good enough to snip {}'.format(pokemon) + return WorkerResult.SUCCESS else: return self.snipe(pokemon) + return WorkerResult.SUCCESS # check for pokeballs (excluding masterball) # checking again as we may have lost some if we sniped diff --git a/pokemongo_bot/event_handlers/social_handler.py b/pokemongo_bot/event_handlers/social_handler.py index d19f578f73..c9e8ab22ea 100644 --- a/pokemongo_bot/event_handlers/social_handler.py +++ b/pokemongo_bot/event_handlers/social_handler.py @@ -5,57 +5,86 @@ import Geohash import errno import json -from socket import error as socket_error +import time +from socket import error as socket_error +DEBUG_ON = False class MyMQTTClass: def __init__(self, bot, clientid=None): - self._mqttc = mqtt.Client(clientid) - self._mqttc.on_message = self.mqtt_on_message self.bot = bot + self.client_id = clientid self.bot.mqtt_pokemon_list = [] - #self._mqttc.on_connect = self.mqtt_on_connect - #self._mqttc.on_publish = self.mqtt_on_publish - #self._mqttc.on_subscribe = self.mqtt_on_subscribe - #def mqtt_on_connect(self, mqttc, obj, flags, rc): - #print "rc: "+str(rc) + self._mqttc = None + def mqtt_on_connect(self, mqttc, obj, flags, rc): + if DEBUG_ON: + print "rc: "+str(rc) def mqtt_on_message(self, mqttc, obj, msg): - #msg.topic+" "+str(msg.qos)+" "+str(msg.payload) + #msg.topic+" "+str(msg.qos)+" "+str(msg.payload)] pokemon = json.loads(msg.payload) + if DEBUG_ON: + print 'on message: {}'.format(pokemon) if pokemon and 'encounter_id' in pokemon: new_list = [x for x in self.bot.mqtt_pokemon_list if x['encounter_id'] is pokemon['encounter_id']] if not (new_list and len(new_list) > 0): self.bot.mqtt_pokemon_list.append(pokemon) - #def mqtt_on_publish(self, mqttc, obj, mid): - #print "mid: "+str(mid) - #def mqtt_on_subscribe(self, mqttc, obj, mid, granted_qos): - # print "Subscribed: "+str(mid)+" "+str(granted_qos) + def on_disconnect(self,client, userdata, rc): + if DEBUG_ON: + print 'on_disconnect' + if rc != 0: + print("Unexpected disconnection.") + def mqtt_on_publish(self, mqttc, obj, mid): + if DEBUG_ON: + print "mid: "+str(mid) + def mqtt_on_subscribe(self, mqttc, obj, mid, granted_qos): + if DEBUG_ON: + print "Subscribed: "+str(mid)+" "+str(granted_qos) #def mqtt_on_log(self, mqttc, obj, level, string): # print string def publish(self, channel, message): - self._mqttc.publish(channel, message) + if self._mqttc: + self._mqttc.publish(channel, message) def connect_to_mqtt(self): try: - self._mqttc.connect("broker.pikabot.org", 1883, 60) - # Enable this line if you are doing the snip code, off stress - self._mqttc.subscribe("pgo/#", 0) + if DEBUG_ON: + print 'connect again' + self._mqttc = mqtt.Client(None) + if self._mqttc: + self._mqttc.on_message = self.mqtt_on_message + self._mqttc.on_connect = self.mqtt_on_connect + self._mqttc.on_subscribe = self.mqtt_on_subscribe + self._mqttc.on_publish = self.mqtt_on_publish + self._mqttc.on_disconnect = self.on_disconnect + + self._mqttc.connect("broker.pikabot.org", 1883, 60) + # Enable this line if you are doing the snip code, off stress + self._mqttc.subscribe("pgo/#", 1) + # self._mqttc.loop_start() except TypeError: + print 'Connect to mqtter error' return def run(self): - self._mqttc.loop_forever() + while True: + self._mqttc.loop_forever(timeout=30.0, max_packets=100, retry_first_connection=False) + print 'Oops disconnected ?' + time.sleep(20) class SocialHandler(EventHandler): def __init__(self, bot): self.bot = bot - try: - self.mqttc = MyMQTTClass(bot, self.bot.config.client_id) - self.mqttc.connect_to_mqtt() - thread.start_new_thread(self.mqttc.run) - except socket_error as serr: - #if serr.errno == errno.ECONNREFUSED: - # ECONNREFUSED - self.mqttc = None + self.mqttc = None def handle_event(self, event, sender, level, formatted_msg, data): - if self.mqttc == None: - return + if self.mqttc is None: + if DEBUG_ON: + print 'need connect' + try: + self.mqttc = MyMQTTClass(self.bot, self.bot.config.client_id) + self.mqttc.connect_to_mqtt() + self.bot.mqttc = self.mqttc + thread.start_new_thread(self.mqttc.run) + except socket_error as serr: + #if serr.errno == errno.ECONNREFUSED: + # ECONNREFUSED + self.mqttc = None + return #sender_name = type(sender).__name__ #if formatted_msg: # message = "[{}] {}".format(event, formatted_msg) From 45eb202acda34f077fce2ed0dbfc4883ef39de9f Mon Sep 17 00:00:00 2001 From: Matt J Madsen Date: Fri, 26 Aug 2016 14:31:11 -0500 Subject: [PATCH 095/106] Add enable to walker output deduction --- pokecli.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pokecli.py b/pokecli.py index faf8c19c14..82221d0688 100644 --- a/pokecli.py +++ b/pokecli.py @@ -607,6 +607,15 @@ def _json_loader(filename): default=True ) + add_config( + parser, + load, + long_flag="--walker_limit_output", + help="Limit output from walker functions (move_to_fort, position_update, etc)", + type=bool, + default=False + ) + # Start to parse other attrs config = parser.parse_args() if not config.username and 'username' not in load: From b47a5df3f9a5fdb574f70c9da1c9ea997413d0f9 Mon Sep 17 00:00:00 2001 From: Matt J Madsen Date: Fri, 26 Aug 2016 14:34:10 -0500 Subject: [PATCH 096/106] Pass walker_limit_output to EventManager init --- pokemongo_bot/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index a9f7ce2213..da1b2d41d2 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -151,7 +151,7 @@ def _setup_event_system(self): remote_control = WebsocketRemoteControl(self).start() # @var EventManager - self.event_manager = EventManager(*handlers) + self.event_manager = EventManager(self.config.walker_limit_output, *handlers) self._register_events() if self.config.show_events: self.event_manager.event_report() From 81311943249fd8b45e9d95a0c2f0fe4c20e7ccbe Mon Sep 17 00:00:00 2001 From: Matt J Madsen Date: Fri, 26 Aug 2016 14:35:23 -0500 Subject: [PATCH 097/106] Add ability to disable walker output reduction --- pokemongo_bot/event_manager.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pokemongo_bot/event_manager.py b/pokemongo_bot/event_manager.py index 70be9c16b2..e8c5c16eec 100644 --- a/pokemongo_bot/event_manager.py +++ b/pokemongo_bot/event_manager.py @@ -22,10 +22,11 @@ def handle_event(self, event, kwargs): class EventManager(object): - def __init__(self, *handlers): + def __init__(self, limit_output=False, *handlers): self._registered_events = dict() self._handlers = list(handlers) or [] self._last_event = None + self._limit_output = limit_output def event_report(self): for event, parameters in self._registered_events.iteritems(): @@ -53,10 +54,13 @@ def emit(self, event, sender=None, level='info', formatted='', data={}): if event not in self._registered_events: raise EventNotRegisteredException("Event %s not registered..." % event) - if (event == self._last_event) and (event in ["moving_to_fort", "moving_to_lured_fort"]): - stdout.write("\033[1A\033[0K\r") - stdout.flush() - if level == "info" and formatted: self._last_event = event + if self._limit_output: + if (event == self._last_event) and (event in ["moving_to_fort", "moving_to_lured_fort", "position_update"]): + stdout.write("\033[1A\033[0K\r") + stdout.flush() + + if level == "info" and formatted: + self._last_event = event # verify params match event parameters = self._registered_events[event] From 46b4a3170918e9905d5227e96470323c8523707f Mon Sep 17 00:00:00 2001 From: Simba Zhang Date: Fri, 26 Aug 2016 12:41:28 -0700 Subject: [PATCH 098/106] To collect data in 30 round, not discard them before consuming. --- .../cell_workers/move_to_map_pokemon.py | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index 283b0ccd52..898b03c6f5 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -85,6 +85,8 @@ # Don't call sniper every time in workers SNIPE_SKIP_IN_ROUND = 30 +DEBUG_ON = False + class MoveToMapPokemon(BaseTask): """Task for moving a trainer to a Pokemon.""" SUPPORTED_TASK_API_VERSION = 1 @@ -294,10 +296,17 @@ def work(self): ultraballs_quantity = inventory.items().get(ULTRABALL_ID).count if (pokeballs_quantity + superballs_quantity + ultraballs_quantity) < self.min_ball: + if DEBUG_ON: + print 'no enough balls' return WorkerResult.SUCCESS self.dump_caught_pokemon() if self.bot.config.enable_social: + if self.config['snipe']: + self.by_pass_times = self.by_pass_times + 1 + if self.by_pass_times < SNIPE_SKIP_IN_ROUND: + return WorkerResult.SUCCESS + self.by_pass_times = 0 pokemon_list = self.get_pokemon_from_social() else: self.update_map_location() @@ -310,16 +319,14 @@ def work(self): pokemon_list.sort(key=lambda x: x['is_vip'], reverse=True) if len(pokemon_list) < 1: - #print 'No enough pokemon in list to snip' + if DEBUG_ON: + print 'No enough pokemon in list to snip' return WorkerResult.SUCCESS pokemon = pokemon_list[0] - #print 'How many pokemon in list: {}'.format(len(pokemon_list)) + if DEBUG_ON: + print 'How many pokemon in list: {}'.format(len(pokemon_list)) if self.config['snipe']: - self.by_pass_times = self.by_pass_times + 1 - if self.by_pass_times < SNIPE_SKIP_IN_ROUND: - return WorkerResult.SUCCESS - self.by_pass_times = 0 if self.snipe_high_prio_only: count = 0 for pokemon in pokemon_list: @@ -330,8 +337,9 @@ def work(self): return WorkerResult.SUCCESS if count is not 1: time.sleep(SNIPE_SLEEP_SEC*5) - #else: - # print 'this pokemon is not good enough to snip {}'.format(pokemon) + else: + if DEBUG_ON: + print 'this pokemon is not good enough to snip {}'.format(pokemon) return WorkerResult.SUCCESS else: return self.snipe(pokemon) From 8374a254a15783531eb186560166d0c68aba4f3d Mon Sep 17 00:00:00 2001 From: Matt J Madsen Date: Fri, 26 Aug 2016 14:46:52 -0500 Subject: [PATCH 099/106] Add walker_output_limit --- docs/configuration_files.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/configuration_files.md b/docs/configuration_files.md index 2d68b48503..fb79c6530d 100644 --- a/docs/configuration_files.md +++ b/docs/configuration_files.md @@ -73,7 +73,8 @@ Document the configuration options of PokemonGo-Bot. | `action_wait_min` | 1 | Set the minimum time setting for anti-ban time randomizer | `action_wait_max` | 4 | Set the maximum time setting for anti-ban time randomizer | `debug` | false | Let the default value here except if you are developer | -| `test` | false | Let the default value here except if you are developer | | +| `test` | false | Let the default value here except if you are developer | +| `walker_output_limit` | false | Reduce output from walker functions | | | `location_cache` | true | Bot will start at last known location if you do not have location set in the config | | `distance_unit` | km | Set the unit to display distance in (km for kilometers, mi for miles, ft for feet) | | `evolve_cp_min` | 300 | Min. CP for evolve_all function @@ -877,4 +878,4 @@ Available `info_to_show` : [[back to top](#table-of-contents)] ``` 2016-08-25 21:20:59,642 [ShowBestPokemon] [INFO] [show_best_pokemon] [Tauros, CP 575, IVCP 0.95, DPS 12.04] | [Grimer, CP 613, IVCP 0.93, DPS 13.93] | [Tangela, CP 736, IVCP 0.93, DPS 14.5] | [Staryu, CP 316, IVCP 0.92, DPS 10.75] | [Gastly, CP 224, IVCP 0.9, DPS 11.7] -``` \ No newline at end of file +``` From 8929476e3b938e207c78731894b9312a90a467b0 Mon Sep 17 00:00:00 2001 From: Matt J Madsen Date: Fri, 26 Aug 2016 14:47:36 -0500 Subject: [PATCH 100/106] Add walker_output_limit --- configs/config.json.cluster.example | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/config.json.cluster.example b/configs/config.json.cluster.example index 0a606aa84a..b92bc24ec4 100644 --- a/configs/config.json.cluster.example +++ b/configs/config.json.cluster.example @@ -228,6 +228,7 @@ ], "debug": false, "test": false, + "walker_limit_output": false, "health_record": true, "location_cache": true, "distance_unit": "km", From 3e2a2218a9b01d8bf288dc303e49d70f590caeda Mon Sep 17 00:00:00 2001 From: Matt J Madsen Date: Fri, 26 Aug 2016 14:47:54 -0500 Subject: [PATCH 101/106] Add walker_output_limit --- configs/config.json.example | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/config.json.example b/configs/config.json.example index 80acc11c82..c9454243aa 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -257,6 +257,7 @@ "gps_z_noise_range": 12.5, "debug": false, "test": false, + "walker_limit_output": false, "health_record": true, "location_cache": true, "distance_unit": "km", From d9ed6ec2d49bfc6ea262e86df1d1f1c9aa67294b Mon Sep 17 00:00:00 2001 From: Matt J Madsen Date: Fri, 26 Aug 2016 14:48:11 -0500 Subject: [PATCH 102/106] Add walker_output_limit --- configs/config.json.map.example | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/config.json.map.example b/configs/config.json.map.example index d925070b03..217bba62cd 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -484,6 +484,7 @@ ], "debug": false, "test": false, + "walker_limit_output": false, "health_record": true, "location_cache": true, "distance_unit": "km", From 9bd53de019987bf3dd7fbc0572071df37c9814c5 Mon Sep 17 00:00:00 2001 From: Matt J Madsen Date: Fri, 26 Aug 2016 14:48:29 -0500 Subject: [PATCH 103/106] Add walker_output_limit --- configs/config.json.optimizer.example | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/config.json.optimizer.example b/configs/config.json.optimizer.example index 296ebd8236..0ca7a0305c 100644 --- a/configs/config.json.optimizer.example +++ b/configs/config.json.optimizer.example @@ -299,6 +299,7 @@ ], "debug": false, "test": false, + "walker_limit_output": false, "health_record": true, "location_cache": true, "distance_unit": "km", From 6551ebbd1526ef180898c958430cb729611de962 Mon Sep 17 00:00:00 2001 From: Matt J Madsen Date: Fri, 26 Aug 2016 14:48:48 -0500 Subject: [PATCH 104/106] Add walker_output_limit --- configs/config.json.path.example | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/config.json.path.example b/configs/config.json.path.example index 03e9fbf1fb..5a2db81f66 100644 --- a/configs/config.json.path.example +++ b/configs/config.json.path.example @@ -234,6 +234,7 @@ ], "debug": false, "test": false, + "walker_limit_output": false, "health_record": true, "location_cache": true, "distance_unit": "km", From 1121870596c4cc1de7b45b44044201a8f2c59123 Mon Sep 17 00:00:00 2001 From: Matt J Madsen Date: Fri, 26 Aug 2016 14:49:11 -0500 Subject: [PATCH 105/106] Add walker_output_limit --- configs/config.json.pokemon.example | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/config.json.pokemon.example b/configs/config.json.pokemon.example index 7998020f9c..8fb41501c5 100644 --- a/configs/config.json.pokemon.example +++ b/configs/config.json.pokemon.example @@ -237,6 +237,7 @@ ], "debug": false, "test": false, + "walker_limit_output": false, "health_record": true, "location_cache": true, "distance_unit": "km", From 8802496ec06ee0f33dd4c8c48d6d878827594c67 Mon Sep 17 00:00:00 2001 From: Matt J Madsen Date: Fri, 26 Aug 2016 14:50:34 -0500 Subject: [PATCH 106/106] Fixed variable name --- docs/configuration_files.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/configuration_files.md b/docs/configuration_files.md index fb79c6530d..e1a746e0ee 100644 --- a/docs/configuration_files.md +++ b/docs/configuration_files.md @@ -74,7 +74,7 @@ Document the configuration options of PokemonGo-Bot. | `action_wait_max` | 4 | Set the maximum time setting for anti-ban time randomizer | `debug` | false | Let the default value here except if you are developer | | `test` | false | Let the default value here except if you are developer | -| `walker_output_limit` | false | Reduce output from walker functions | | +| `walker_limit_output` | false | Reduce output from walker functions | | | `location_cache` | true | Bot will start at last known location if you do not have location set in the config | | `distance_unit` | km | Set the unit to display distance in (km for kilometers, mi for miles, ft for feet) | | `evolve_cp_min` | 300 | Min. CP for evolve_all function