Skip to content

Commit

Permalink
Merge pull request #6007 from davidakachaos/resume_balls_limiter
Browse files Browse the repository at this point in the history
[CatchLimiter] Resume at X balls
  • Loading branch information
pogarek authored Apr 10, 2017
2 parents f029c05 + fcea2f5 commit 40bc57b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 13 additions & 3 deletions pokemongo_bot/cell_workers/catch_limiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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)
Expand All @@ -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):
Expand Down

0 comments on commit 40bc57b

Please sign in to comment.