From fcea2f51c03dcc83749c3a76619a7ad79de49f6e Mon Sep 17 00:00:00 2001 From: David Westerink Date: Mon, 10 Apr 2017 14:32:08 +0200 Subject: [PATCH] Added resume at balls --- docs/configuration_files.md | 1 + pokemongo_bot/cell_workers/catch_limiter.py | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/configuration_files.md b/docs/configuration_files.md index 791f8cca32..610a7eedb5 100644 --- a/docs/configuration_files.md +++ b/docs/configuration_files.md @@ -201,6 +201,7 @@ The behaviors of the bot are configured via the `tasks` key in the `config.json` * Catch Limiter * `enabled`: Default false | Enable/disable the task * `min_balls`: Default 20 | Minimum balls on hand before catch tasks enabled + * `resume_at_balls`: Default 100 | When this number of balls is reached, immediately resume catching * `duration`: Default 15 | Length of time to disable catch tasks * EvolvePokemon * `enable`: Disable or enable this task. diff --git a/pokemongo_bot/cell_workers/catch_limiter.py b/pokemongo_bot/cell_workers/catch_limiter.py index ee79bda8a5..4d84f27e47 100644 --- a/pokemongo_bot/cell_workers/catch_limiter.py +++ b/pokemongo_bot/cell_workers/catch_limiter.py @@ -16,7 +16,8 @@ def __init__(self, bot, config): self.bot = bot self.config = config self.enabled = self.config.get("enabled",False) - self.min_balls = self.config.get("min_balls",20) + self.min_balls = self.config.get("min_balls", 20) + self.resume_at_balls = self.config.get("resume_at_balls", 100) self.duration = self.config.get("duration",15) if not hasattr(self.bot, "catch_resume_at"): self.bot.catch_resume_at = None @@ -26,7 +27,7 @@ def work(self): now = datetime.now() balls_on_hand = self.get_pokeball_count() - + # If resume time has passed, resume catching tasks if self.bot.catch_disabled and now >= self.bot.catch_resume_at: if balls_on_hand > self.min_balls: @@ -37,6 +38,15 @@ def work(self): ) self.bot.catch_disabled = False + # If currently not catching, but balls >= resume_at_balls + if self.bot.catch_disabled and balls_on_hand >= self.resume_at_balls: + self.emit_event( + 'catch_limit_off', + formatted="Resume time hasn't passed yet, bu balls on hand ({}) exceeds threshold {}. Re-enabling catch tasks.". + format(balls_on_hand, self.resume_at_balls) + ) + self.bot.catch_disabled = False + # If balls_on_hand less than threshold, pause catching tasks for duration minutes if not self.bot.catch_disabled and balls_on_hand <= self.min_balls: self.bot.catch_resume_at = now + timedelta(minutes = self.duration) @@ -46,7 +56,7 @@ def work(self): formatted="Balls on hand ({}) has reached threshold {}. Disabling catch tasks until {} or balls on hand > threshold (whichever is later).". format(balls_on_hand, self.min_balls, self.bot.catch_resume_at.strftime("%H:%M:%S")) ) - + return WorkerResult.SUCCESS def get_pokeball_count(self):