From e6fe3e384645f6f3095db4f0f2665b78ada0158d Mon Sep 17 00:00:00 2001 From: Ro Date: Sat, 20 Aug 2016 14:04:34 -0400 Subject: [PATCH 01/15] Ban Notifications (Slack) PokemonCatchWorker --- pokemongo_bot/cell_workers/pokemon_catch_worker.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index e64abbfd0e..eaa226a2e4 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -14,6 +14,7 @@ from pokemongo_bot.datastore import Datastore from pokemongo_bot.base_dir import _base_dir from datetime import datetime, timedelta +from slackclient import SlackClient CATCH_STATUS_SUCCESS = 1 CATCH_STATUS_FAILED = 2 @@ -295,6 +296,11 @@ def _use_berry(self, berry_id, berry_count, encounter_id, catch_rate_by_ball, cu source = str("PokemonCatchWorker") status = str("Possible Softban") conn.execute('''INSERT INTO softban_log (status, source) VALUES (?, ?)''', (status, source)) + token = "xoxb-71319834775-Hz8nfKTma7Oo0oFlwUfMi4Ps" + sc = SlackClient(token) + sendto = "@" + self.bot.config.slackname + greeting= status + " | " + source + print sc.api_call("chat.postMessage", username='pokemongobot', icon_emoji=':pokeball:', channel=sendto, text=greeting) break else: self.emit_event( From 81edbe8cb827f63246aae39f695d549e20e7f47f Mon Sep 17 00:00:00 2001 From: Ro Date: Sat, 20 Aug 2016 14:19:19 -0400 Subject: [PATCH 02/15] Update requirements.txt (slack notif) --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 6bfc11dd2e..853243cdd4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -24,3 +24,4 @@ raven==5.23.0 demjson==2.2.4 greenlet==0.4.9 yoyo-migrations==5.0.3 +slackclient==1.0.1 From 4420e9975fe236c9537010b3c2135877deaaf8c6 Mon Sep 17 00:00:00 2001 From: Ro Date: Sat, 20 Aug 2016 14:24:08 -0400 Subject: [PATCH 03/15] Update pokemon_catch_worker.py --- pokemongo_bot/cell_workers/pokemon_catch_worker.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index eaa226a2e4..4a8dde13cf 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -296,11 +296,6 @@ def _use_berry(self, berry_id, berry_count, encounter_id, catch_rate_by_ball, cu source = str("PokemonCatchWorker") status = str("Possible Softban") conn.execute('''INSERT INTO softban_log (status, source) VALUES (?, ?)''', (status, source)) - token = "xoxb-71319834775-Hz8nfKTma7Oo0oFlwUfMi4Ps" - sc = SlackClient(token) - sendto = "@" + self.bot.config.slackname - greeting= status + " | " + source - print sc.api_call("chat.postMessage", username='pokemongobot', icon_emoji=':pokeball:', channel=sendto, text=greeting) break else: self.emit_event( @@ -309,6 +304,12 @@ def _use_berry(self, berry_id, berry_count, encounter_id, catch_rate_by_ball, cu level='info', formatted="softban_log table not found, skipping log" ) + if self.bot.config.slackname: + token = "xoxb-71319834775-Hz8nfKTma7Oo0oFlwUfMi4Ps" + sc = SlackClient(token) + sendto = "@" + self.bot.config.slackname + greeting= status + " | " + source + print sc.api_call("chat.postMessage", username='pokemongobot', icon_emoji=':pokeball:', channel=sendto, text=greeting) # unknown status code else: From 8b7fec9b53cd84676c2d0adb286e62dd9359955a Mon Sep 17 00:00:00 2001 From: Ro Date: Sat, 20 Aug 2016 14:25:17 -0400 Subject: [PATCH 04/15] spin_fort.py slack notifcations --- pokemongo_bot/cell_workers/spin_fort.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pokemongo_bot/cell_workers/spin_fort.py b/pokemongo_bot/cell_workers/spin_fort.py index 31cb7426f5..2741a39d6e 100644 --- a/pokemongo_bot/cell_workers/spin_fort.py +++ b/pokemongo_bot/cell_workers/spin_fort.py @@ -15,6 +15,7 @@ from pokemongo_bot.base_dir import _base_dir from utils import distance, format_time, fort_details from pokemongo_bot.datastore import Datastore +from slackclient import SlackClient SPIN_REQUEST_RESULT_SUCCESS = 1 SPIN_REQUEST_RESULT_OUT_OF_RANGE = 2 @@ -150,6 +151,12 @@ def work(self): 'softban', formatted='Probably got softban.' ) + if self.bot.config.slackname: + token = "xoxb-71319834775-Hz8nfKTma7Oo0oFlwUfMi4Ps" + sc = SlackClient(token) + sendto = "@" + self.bot.config.slackname + greeting= status + " | " + source + print sc.api_call("chat.postMessage", username='pokemongobot', icon_emoji=':pokeball:', channel=sendto, text=greeting) with self.bot.database as conn: c = conn.cursor() c.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='softban_log'") From 908d9d199df430c17ac833732383828c01026316 Mon Sep 17 00:00:00 2001 From: Ro Date: Sat, 20 Aug 2016 14:26:16 -0400 Subject: [PATCH 05/15] Update config.json.cluster.example --- 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 604f4d7b36..e574e3976b 100644 --- a/configs/config.json.cluster.example +++ b/configs/config.json.cluster.example @@ -7,6 +7,7 @@ "encrypt_location": "", "websocket_server": false, "heartbeat_threshold": 10, + "slackname": "", "tasks": [ { "type": "HandleSoftBan" From 3d6960aef161de1e862fcad24239893ce9849667 Mon Sep 17 00:00:00 2001 From: Ro Date: Sat, 20 Aug 2016 14:26:20 -0400 Subject: [PATCH 06/15] Update config.json.example --- configs/config.json.example | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/config.json.example b/configs/config.json.example index 5a2a7b7a83..0edd59c909 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -7,6 +7,7 @@ "encrypt_location": "", "websocket_server": false, "heartbeat_threshold": 10, + "slackname": "", "tasks": [ { "type": "HandleSoftBan" From 63e442334c9ce7167f62353ec6bb25cda57c92f5 Mon Sep 17 00:00:00 2001 From: Ro Date: Sat, 20 Aug 2016 14:26:23 -0400 Subject: [PATCH 07/15] Update config.json.map.example --- 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 dab997683c..8e3b6593d2 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -7,6 +7,7 @@ "encrypt_location": "", "websocket_server": false, "heartbeat_threshold": 10, + "slackname": "", "tasks": [ { "type": "HandleSoftBan" From ea2de9bc5d966bafe43f3404ac15c5612dd9cb50 Mon Sep 17 00:00:00 2001 From: Ro Date: Sat, 20 Aug 2016 14:26:26 -0400 Subject: [PATCH 08/15] Update config.json.optimizer.example --- 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 dfc84f97b4..ff125e4692 100644 --- a/configs/config.json.optimizer.example +++ b/configs/config.json.optimizer.example @@ -7,6 +7,7 @@ "encrypt_location": "", "websocket_server": false, "heartbeat_threshold": 10, + "slackname": "", "tasks": [ { "type": "HandleSoftBan" From cad9fefc216859cff49d14964c1e9cacf85546f0 Mon Sep 17 00:00:00 2001 From: Ro Date: Sat, 20 Aug 2016 14:26:31 -0400 Subject: [PATCH 09/15] Update config.json.path.example --- 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 7612b5a264..f24b58121a 100644 --- a/configs/config.json.path.example +++ b/configs/config.json.path.example @@ -7,6 +7,7 @@ "encrypt_location": "", "websocket_server": false, "heartbeat_threshold": 10, + "slackname": "", "tasks": [ { "type": "HandleSoftBan" From 23033006f543de17bf0710a0643231b3009e30ab Mon Sep 17 00:00:00 2001 From: Ro Date: Sat, 20 Aug 2016 14:26:35 -0400 Subject: [PATCH 10/15] Update config.json.pokemon.example --- 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 306893bc0b..13cfb1349c 100644 --- a/configs/config.json.pokemon.example +++ b/configs/config.json.pokemon.example @@ -7,6 +7,7 @@ "encrypt_location": "", "websocket_server": false, "heartbeat_threshold": 10, + "slackname": "", "tasks": [ { "type": "HandleSoftBan" From 446186e50ca61d444dc7f84811383b1587b71230 Mon Sep 17 00:00:00 2001 From: Ro Date: Sat, 20 Aug 2016 14:27:36 -0400 Subject: [PATCH 11/15] pokecli.py slack variable --- pokecli.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pokecli.py b/pokecli.py index 05ac6b610f..dfd91c5b12 100644 --- a/pokecli.py +++ b/pokecli.py @@ -564,6 +564,7 @@ def _json_loader(filename): config.plugins = load.get('plugins', []) config.raw_tasks = load.get('tasks', []) config.daily_catch_limit = load.get('daily_catch_limit', 800) + config.slackname = load.get('slackname', "") config.vips = load.get('vips', {}) if config.map_object_cache_time < 0.0: From 1425321a399bb0b963994198a7718596bd68d32e Mon Sep 17 00:00:00 2001 From: Ro Date: Sat, 20 Aug 2016 14:44:37 -0400 Subject: [PATCH 12/15] Update pokecli.py --- pokecli.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pokecli.py b/pokecli.py index dfd91c5b12..87c044df93 100644 --- a/pokecli.py +++ b/pokecli.py @@ -49,6 +49,7 @@ from pokemongo_bot.health_record import BotEvent from pokemongo_bot.plugin_loader import PluginLoader from pokemongo_bot.api_wrapper import PermaBannedException +from slackclient import SlackClient try: from demjson import jsonlint @@ -159,6 +160,13 @@ def get_commit_hash(): level='info', formatted='Probably permabanned, Game Over ! Play again at https://club.pokemon.com/us/pokemon-trainer-club/sign-up/' ) + if bot.config.slackname: + token = "xoxb-71319834775-Hz8nfKTma7Oo0oFlwUfMi4Ps" + sc = SlackClient(token) + sendto = "@" + bot.config.slackname + greeting = "*Permanent Ban Detected!*" + print sc.api_call("chat.postMessage", username='pokemongobot', icon_emoji=':pokeball:', channel=sendto, text=greeting) + except GeocoderQuotaExceeded: raise Exception("Google Maps API key over requests limit.") except SIGINTRecieved: @@ -564,7 +572,7 @@ def _json_loader(filename): config.plugins = load.get('plugins', []) config.raw_tasks = load.get('tasks', []) config.daily_catch_limit = load.get('daily_catch_limit', 800) - config.slackname = load.get('slackname', "") + config.slackname = load.get('slackname', "slackbot") config.vips = load.get('vips', {}) if config.map_object_cache_time < 0.0: From da93caa4203ac8115e972619fb6fe9ca8f729cd5 Mon Sep 17 00:00:00 2001 From: Ro Date: Sat, 20 Aug 2016 14:52:02 -0400 Subject: [PATCH 13/15] Update pokemon_catch_worker.py --- 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 4a8dde13cf..06fcaa36a6 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -308,7 +308,7 @@ def _use_berry(self, berry_id, berry_count, encounter_id, catch_rate_by_ball, cu token = "xoxb-71319834775-Hz8nfKTma7Oo0oFlwUfMi4Ps" sc = SlackClient(token) sendto = "@" + self.bot.config.slackname - greeting= status + " | " + source + greeting= status + " | " + source + " | Username: (*" + self.bot.config.username + "*) " + " | Date/Time: " + str(datetime.now()) print sc.api_call("chat.postMessage", username='pokemongobot', icon_emoji=':pokeball:', channel=sendto, text=greeting) # unknown status code From fba8496e0ad7ca43763965aa1511839a7262ce81 Mon Sep 17 00:00:00 2001 From: Ro Date: Sat, 20 Aug 2016 14:52:41 -0400 Subject: [PATCH 14/15] Update spin_fort.py --- pokemongo_bot/cell_workers/spin_fort.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pokemongo_bot/cell_workers/spin_fort.py b/pokemongo_bot/cell_workers/spin_fort.py index 2741a39d6e..4194f0fe0d 100644 --- a/pokemongo_bot/cell_workers/spin_fort.py +++ b/pokemongo_bot/cell_workers/spin_fort.py @@ -15,6 +15,7 @@ from pokemongo_bot.base_dir import _base_dir from utils import distance, format_time, fort_details from pokemongo_bot.datastore import Datastore +from datetime import datetime, timedelta from slackclient import SlackClient SPIN_REQUEST_RESULT_SUCCESS = 1 @@ -155,7 +156,7 @@ def work(self): token = "xoxb-71319834775-Hz8nfKTma7Oo0oFlwUfMi4Ps" sc = SlackClient(token) sendto = "@" + self.bot.config.slackname - greeting= status + " | " + source + greeting= status + " | " + source + " | Username: (*" + self.bot.config.username + "*) " + " | Date/Time: " + str(datetime.now()) print sc.api_call("chat.postMessage", username='pokemongobot', icon_emoji=':pokeball:', channel=sendto, text=greeting) with self.bot.database as conn: c = conn.cursor() From 854469bd49a9b2af87ad1636d2f2ac4de7d60668 Mon Sep 17 00:00:00 2001 From: Ro Date: Sat, 20 Aug 2016 14:53:07 -0400 Subject: [PATCH 15/15] Update pokecli.py --- pokecli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pokecli.py b/pokecli.py index 87c044df93..23b2bfc24c 100644 --- a/pokecli.py +++ b/pokecli.py @@ -38,7 +38,7 @@ import signal import string import subprocess -from datetime import timedelta +from datetime import datetime, timedelta from getpass import getpass from pgoapi.exceptions import NotLoggedInException, ServerSideRequestThrottlingException, ServerBusyOrOfflineException from geopy.exc import GeocoderQuotaExceeded @@ -164,7 +164,7 @@ def get_commit_hash(): token = "xoxb-71319834775-Hz8nfKTma7Oo0oFlwUfMi4Ps" sc = SlackClient(token) sendto = "@" + bot.config.slackname - greeting = "*Permanent Ban Detected!*" + greeting = "Permanent Ban Detected! | " + " Username: (*" + bot.config.username + "*) " + " | Date/Time: " + str(datetime.now()) print sc.api_call("chat.postMessage", username='pokemongobot', icon_emoji=':pokeball:', channel=sendto, text=greeting) except GeocoderQuotaExceeded: