Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Softban/Permban Slack Notifications #4400

Merged
merged 15 commits into from
Aug 20, 2016
1 change: 1 addition & 0 deletions configs/config.json.cluster.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"encrypt_location": "",
"websocket_server": false,
"heartbeat_threshold": 10,
"slackname": "",
"tasks": [
{
"type": "HandleSoftBan"
Expand Down
1 change: 1 addition & 0 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"encrypt_location": "",
"websocket_server": false,
"heartbeat_threshold": 10,
"slackname": "",
"tasks": [
{
"type": "HandleSoftBan"
Expand Down
1 change: 1 addition & 0 deletions configs/config.json.map.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"encrypt_location": "",
"websocket_server": false,
"heartbeat_threshold": 10,
"slackname": "",
"tasks": [
{
"type": "HandleSoftBan"
Expand Down
1 change: 1 addition & 0 deletions configs/config.json.optimizer.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"encrypt_location": "",
"websocket_server": false,
"heartbeat_threshold": 10,
"slackname": "",
"tasks": [
{
"type": "HandleSoftBan"
Expand Down
1 change: 1 addition & 0 deletions configs/config.json.path.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"encrypt_location": "",
"websocket_server": false,
"heartbeat_threshold": 10,
"slackname": "",
"tasks": [
{
"type": "HandleSoftBan"
Expand Down
1 change: 1 addition & 0 deletions configs/config.json.pokemon.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"encrypt_location": "",
"websocket_server": false,
"heartbeat_threshold": 10,
"slackname": "",
"tasks": [
{
"type": "HandleSoftBan"
Expand Down
11 changes: 10 additions & 1 deletion pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions pokemongo_bot/cell_workers/pokemon_catch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions pokemongo_bot/cell_workers/spin_fort.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'")
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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