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" 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" 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" 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" 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" 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" diff --git a/pokecli.py b/pokecli.py index 05ac6b610f..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 @@ -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! | " + " 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: raise Exception("Google Maps API key over requests limit.") except SIGINTRecieved: @@ -564,6 +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', "slackbot") config.vips = load.get('vips', {}) if config.map_object_cache_time < 0.0: diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index e64abbfd0e..06fcaa36a6 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 @@ -303,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 + " | 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 else: diff --git a/pokemongo_bot/cell_workers/spin_fort.py b/pokemongo_bot/cell_workers/spin_fort.py index 31cb7426f5..4194f0fe0d 100644 --- a/pokemongo_bot/cell_workers/spin_fort.py +++ b/pokemongo_bot/cell_workers/spin_fort.py @@ -15,6 +15,8 @@ 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 SPIN_REQUEST_RESULT_OUT_OF_RANGE = 2 @@ -150,6 +152,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 + " | 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() c.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='softban_log'") 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