Skip to content

Commit

Permalink
Merge pull request #5550 from kolinkorr839/continue_spin_fort
Browse files Browse the repository at this point in the history
When daily spin limit is reached, let it continue working instead of …
  • Loading branch information
Gobberwart authored Sep 26, 2016
2 parents 8e6a156 + cebe496 commit ec893ec
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ If you do not want any data to be gathered, you can turn off this feature by set
* bruno-kenji
* Gobberwart
* javajohnHub
* kolinkorr839

## Disclaimer
©2016 Niantic, Inc. ©2016 Pokémon. ©1995–2016 Nintendo / Creatures Inc. / GAME FREAK inc. © 2016 Pokémon/Nintendo Pokémon and Pokémon character names are trademarks of Nintendo. The Google Maps Pin is a trademark of Google Inc. and the trade dress in the product design is a trademark of Google Inc. under license to The Pokémon Company. Other trademarks are the property of their respective owners.
Expand Down
3 changes: 3 additions & 0 deletions docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ The behaviors of the bot are configured via the `tasks` key in the `config.json`
* `enable`: Disable or enable this task.
* `spin_wait_min`: Default 3 | Minimum wait time after fort spin
* `spin_wait_max`: Default 5 | Maximum wait time after fort spin
* `daily_spin_limit`: Default 2000 | Daily spin limit
* `min_interval`: Default 120 | When daily spin limit is reached, how often should the warning message be shown
* `exit_on_limit_reached`: Default `True` | Code will exits if daily_spin_limit is reached
* HandleSoftBan
* IncubateEggs
* `enable`: Disable or enable this task.
Expand Down
32 changes: 28 additions & 4 deletions pokemongo_bot/cell_workers/spin_fort.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import unicode_literals
from __future__ import absolute_import

from datetime import datetime, timedelta
import sys
import time

Expand All @@ -27,9 +28,14 @@ def __init__(self, bot, config):
super(SpinFort, self).__init__(bot, config)

def initialize(self):
# 10 seconds from current time
self.next_update = datetime.now() + timedelta(0, 10)

self.ignore_item_count = self.config.get("ignore_item_count", False)
self.spin_wait_min = self.config.get("spin_wait_min", 2)
self.spin_wait_max = self.config.get("spin_wait_max", 3)
self.min_interval = int(self.config.get('min_interval', 120))
self.exit_on_limit_reached = self.config.get("exit_on_limit_reached", True)

def should_run(self):
has_space_for_loot = inventory.Items.has_space_for_loot()
Expand All @@ -40,9 +46,23 @@ def should_run(self):
)
return self.ignore_item_count or has_space_for_loot


def work(self):
forts = self.get_forts_in_range()

with self.bot.database as conn:
c = conn.cursor()
c.execute("SELECT DISTINCT COUNT(pokestop) FROM pokestop_log WHERE dated >= datetime('now','-1 day')")
if c.fetchone()[0] >= self.config.get('daily_spin_limit', 2000):
if self.exit_on_limit_reached:
self.emit_event('spin_limit', formatted='WARNING! You have reached your daily spin limit')
sys.exit(2)

if datetime.now() >= self.next_update:
self.emit_event('spin_limit', formatted='WARNING! You have reached your daily spin limit')
self._compute_next_update()
return WorkerResult.SUCCESS

if not self.should_run() or len(forts) == 0:
return WorkerResult.SUCCESS

Expand Down Expand Up @@ -98,10 +118,6 @@ def work(self):
c = conn.cursor()
c.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='pokestop_log'")
result = c.fetchone()
c.execute("SELECT DISTINCT COUNT(pokestop) FROM pokestop_log WHERE dated >= datetime('now','-1 day')")
if c.fetchone()[0] >= self.config.get('daily_spin_limit', 2000):
self.emit_event('spin_limit', formatted='WARNING! You have reached your daily spin limit')
sys.exit(2)
while True:
if result[0] == 1:
conn.execute('''INSERT INTO pokestop_log (pokestop, exp, items) VALUES (?, ?, ?)''', (fort_name, str(experience_awarded), str(items_awarded)))
Expand Down Expand Up @@ -229,3 +245,11 @@ def get_items_awarded_from_fort_spinned(self, response_dict):
# TODO : Refactor this class, hide the inventory update right after the api call
def _update_inventory(self, item_awarded):
inventory.items().get(item_awarded['item_id']).add(item_awarded['item_count'])

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)

0 comments on commit ec893ec

Please sign in to comment.