Skip to content

Commit

Permalink
Softban Tracker (#4299)
Browse files Browse the repository at this point in the history
* Log softbans + source / date to database

* Log softbans + source / date to database

* Update __init__.py

* Update colored_logging_handler.py

* Create softban_log.py

* re-add new berry stuff
  • Loading branch information
BreezeRo authored and solderzzc committed Aug 20, 2016
1 parent a5f8491 commit a5cab06
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ def _register_events(self):
self.event_manager.register_event('login_log')
self.event_manager.register_event('transfer_log')
self.event_manager.register_event('pokestop_log')
self.event_manager.register_event('softban_log')

def tick(self):
self.health_record.heartbeat()
Expand Down
5 changes: 5 additions & 0 deletions pokemongo_bot/cell_workers/migrations/softban_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from yoyo import step

step(
"CREATE TABLE IF NOT EXISTS softban_log (status text, source text, dated datetime DEFAULT CURRENT_TIMESTAMP)"
)
18 changes: 18 additions & 0 deletions pokemongo_bot/cell_workers/pokemon_catch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,24 @@ def _use_berry(self, berry_id, berry_count, encounter_id, catch_rate_by_ball, cu
level='warning',
formatted='Failed to use berry. You may be softbanned.'
)
with self.bot.database as conn:
c = conn.cursor()
c.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='softban_log'")
result = c.fetchone()

while True:
if result[0] == 1:
source = str("PokemonCatchWorker")
status = str("Possible Softban")
conn.execute('''INSERT INTO softban_log (status, source) VALUES (?, ?)''', (status, source))
break
else:
self.emit_event(
'softban_log',
sender=self,
level='info',
formatted="softban_log table not found, skipping log"
)

# unknown status code
else:
Expand Down
19 changes: 19 additions & 0 deletions pokemongo_bot/cell_workers/spin_fort.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,25 @@ def work(self):
'softban',
formatted='Probably got softban.'
)
with self.bot.database as conn:
c = conn.cursor()
c.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='softban_log'")
result = c.fetchone()

while True:
if result[0] == 1:
source = str("PokemonCatchWorker")
status = str("Possible Softban")
conn.execute('''INSERT INTO softban_log (status, source) VALUES (?, ?)''', (status, source))
break
else:
self.emit_event(
'softban_log',
sender=self,
level='info',
formatted="softban_log table not found, skipping log"
)
break
else:
self.bot.fort_timeouts[fort["id"]] = (time.time() + 300) * 1000 # Don't spin for 5m
return WorkerResult.ERROR
Expand Down
1 change: 1 addition & 0 deletions pokemongo_bot/event_handlers/colored_logging_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class ColoredLoggingHandler(EventHandler):
'position_update': 'white',
'set_start_location': 'white',
'softban_fix': 'white',
'softban_log': 'magenta',
'softban_fix_done': 'white',
'spun_fort': 'white',
'threw_berry': 'white',
Expand Down

0 comments on commit a5cab06

Please sign in to comment.