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

Warning Patch & Login Enhancement #6201

Merged
merged 4 commits into from
Aug 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"heartbeat_threshold": 10,
"enable_social": false,
"check_niantic_api": false,
"solve_captcha": false,
"solve_captcha": false,
"bypass_warning": false,
"live_config_update": {
"enabled": false,
"tasks_only": false
Expand Down
85 changes: 52 additions & 33 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,39 +63,6 @@
if sys.version_info >= (2, 7, 9):
ssl._create_default_https_context = ssl._create_unverified_context

def yes_no( question ):
# raw_input returns the empty string for "enter"
yes = set(['yes','y', 'ye', ''])
no = set(['no','n'])
print question
choice = raw_input().lower()
if choice in yes:
return True
elif choice in no:
return False
else:
print "Please respond with 'yes' or 'no'"
return None

try:
import pkg_resources
pgoapi_version = pkg_resources.get_distribution("pgoapi").version
if pgoapi_version != '2.13.0':
yn=None
while yn==None:
yn = yes_no("Warning: A new pokemon API version is found. Do you want to keep the bot running on your own risk of loosing your account? Y/N")
if not yn:
sys.exit(1)

except pkg_resources.DistributionNotFound:
print 'Seems you forgot to install python modules.'
print 'Run: `pip install -r requirements.txt`'
sys.exit(1)
except ImportError as e:
print e
pass


logging.basicConfig(
level=logging.INFO,
format='%(asctime)s [%(name)10s] [%(levelname)s] %(message)s')
Expand All @@ -117,9 +84,52 @@ def handle_sigint(*args):
def initialize_task(bot, config):
tree = TreeConfigBuilder(bot, config.raw_tasks).build()
bot.workers = tree

def yes_no(question):
# raw_input returns the empty string for "enter"
yes = set(['yes','y', 'ye', ''])
no = set(['no','n'])
print question
choice = raw_input().lower()
if choice in yes:
return True
elif choice in no:
return False
else:
print "Please respond with 'yes' or 'no'"
return None

def initialize(config):
from pokemongo_bot.datastore import Datastore

# Allow user to by pass warning without question
if config.bypass_warning:
bypass_warning = config.bypass_warning
else:
bypass_warning = False

try:
import pkg_resources
pgoapi_version = pkg_resources.get_distribution("pgoapi").version
if pgoapi_version != '2.13.0':
yn=None
while yn==None:
if not bypass_warning:
yn = yes_no("Warning: A new pokemon API version is found.\n Run following command to get latest update: `pip install -r requirements.txt --upgrade` \n Do you want to contine? Y/N")
else:
print "Warning: A new pokemon API version is found.\n Run following command to get latest update: `pip install -r requirements.txt --upgrade` \n You have chose to bypass warning, bot will continue running."
yn = True
time.sleep(5)
if not yn:
sys.exit(1)

except pkg_resources.DistributionNotFound:
print 'Seems you forgot to install python modules.'
print 'Run: `pip install -r requirements.txt`'
sys.exit(1)
except ImportError as e:
print e
pass

ds = Datastore(conn_str='/data/{}.db'.format(config.username))
for directory in ['pokemongo_bot', 'pokemongo_bot/cell_workers']:
Expand Down Expand Up @@ -442,6 +452,15 @@ def _json_loader(filename):
help="hashendpoint",
default=None
)
add_config(
parser,
load,
short_flag="-bp",
long_flag="--bypass_warning",
help="Allow bypass to warning",
type=bool,
default=False
)
add_config(
parser,
load,
Expand Down
109 changes: 75 additions & 34 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from .tree_config_builder import ConfigException
from .tree_config_builder import MismatchTaskApiVersion
from .tree_config_builder import TreeConfigBuilder
from .inventory import init_inventory, player
from .inventory import init_inventory, player, Pokemons
from sys import platform as _platform
from pgoapi.protos.pogoprotos.enums import badge_type_pb2
from pgoapi.exceptions import AuthException, NotLoggedInException, ServerSideRequestThrottlingException, ServerBusyOrOfflineException, NoPlayerPositionSetException, HashingOfflineException
Expand Down Expand Up @@ -140,9 +140,18 @@ def __init__(self, db, config):
self.inventory_refresh_counter = 0
self.last_inventory_refresh = time.time()

# Time when inbox is called
self.get_inbox_time = 0

# Allow user to change hash service
if self.config.hashendpoint:
HashServer.endpoint = self.config.hashendpoint

# Allow user to by pass warning without question
if self.config.bypass_warning:
self.bypass_warning = self.config.bypass_warning
else:
self.bypass_warning = False

# Allow user to use a proxy with the bot
if self.config.proxy:
Expand Down Expand Up @@ -999,6 +1008,30 @@ def check_session(self, position):
self.api.set_position(*position)
self.login()

def yes_no(self,question,warn_type):
# raw_input returns the empty string for "enter"
yes = set(['yes','y', 'ye', ''])
no = set(['no','n'])
self.event_manager.emit(
warn_type,
sender=self,
level='info',
formatted=question
)
choice = raw_input().lower()
if choice in yes:
return True
elif choice in no:
return False
else:
self.event_manager.emit(
warn_type,
sender=self,
level='info',
formatted="Please respond with 'yes' or 'no'"
)
return None

def login(self):
status = {}
retry = 0
Expand All @@ -1013,21 +1046,6 @@ def login(self):
lat, lng = self.position[0:2]
self.api.set_position(lat, lng, self.alt) # or should the alt kept to zero?

def yes_no( question ):
# raw_input returns the empty string for "enter"
yes = set(['yes','y', 'ye', ''])
no = set(['no','n'])
print question
choice = raw_input().lower()
if choice in yes:
return True
elif choice in no:
return False
else:
print "Please respond with 'yes' or 'no'"
return None


while not quit_login:
try:
self.api.login(
Expand Down Expand Up @@ -1131,15 +1149,19 @@ def yes_no( question ):
PGoAPI_version_int = int(PGoAPI_version_tmp)

if PGoAPI_version_int < officialAPI_int:
self.event_manager.emit(
'security_check',
sender=self,
level='info',
formatted="We have detected a Pokemon API Change. Latest Niantic Version is: {}. Program Exiting...".format(officalAPI)
)
yn=None
while yn==None:
yn = yes_no("Warning: A new pokemon API version is found. Do you want to keep the bot running on your own risk of loosing your account? Y/N")
if not self.bypass_warning:
yn = self.yes_no("We have detected a Pokemon API Change. Latest Niantic Version is: {}. Do you want to contine? Y/N".format(officalAPI),"security_check")
else:
self.event_manager.emit(
'security_check',
sender=self,
level='info',
formatted="We have detected a Pokemon API Change. Latest Niantic Version is: {}. You have chose to bypass warning, bot will continue running.".format(officalAPI)
)
yn=True
sleep(5)
if not yn:
sys.exit(1)
else:
Expand Down Expand Up @@ -1276,13 +1298,21 @@ def _print_character_info(self):

if warn:
self.logger.info('')
self.event_manager.emit(
'niantic_warning',
sender=self,
level='warning',
formatted="This account has recieved a warning from Niantic. Bot at own risk."
)
sleep(5) # Pause to allow user to see warning
yn=None
while yn==None:
if not self.bypass_warning:
yn = self.yes_no("This account has recieved a warning from Niantic. Bot at own risk. Do you want to contine? Y/N","niantic_warning")
else:
self.event_manager.emit(
'niantic_warning',
sender=self,
level='warning',
formatted="This account has recieved a warning from Niantic. Bot at own risk. You have chose to bypass warning, bot will continue running."
)
yn=True
sleep(5) # Pause to allow user to see warning
if not yn:
sys.exit(1)

self.logger.info('')

Expand Down Expand Up @@ -1548,7 +1578,11 @@ def heartbeat(self):
request = self.api.create_request()
request.get_player()
request.check_awarded_badges()
request.get_inbox()
if self.get_inbox_time==0:
request.get_inbox(is_history=True, is_reverse=False)
else:
request.get_inbox(is_history=False,is_reverse=True,not_before_ms=self.get_inbox_time)
self.get_inbox_time = int(round(time.time() * 1000))
responses = None
try:
responses = request.call()
Expand All @@ -1570,22 +1604,26 @@ def heartbeat(self):
formatted='player_data: {player_data}',
data={'player_data': self._player}
)

if responses['responses']['GET_INBOX']['result'] == 1:
self._inbox = responses['responses']['GET_INBOX']['inbox']
# self.logger.info("Got inbox messages?")
# self.logger.info("Inbox: %s" % responses['responses']['GET_INBOX'])
# self.logger.info("Inbox: "+format(responses['responses']['GET_INBOX']))
if 'notifications' in self._inbox:
for notification in self._inbox['notifications']:
notification_date = datetime.datetime.fromtimestamp(int(notification['create_timestamp_ms']) / 1e3)
if previous_heartbeat > (int(notification['create_timestamp_ms']) / 1e3):
# Skipp old notifications!
if 2 not in notification['labels']:
continue

if notification['category'] == 'pokemon_hungry':
gym_name = pokemon = 'Unknown'
for variable in notification['variables']:
if variable['name'] == 'GYM_NAME':
gym_name = variable['literal']
if variable['name'] == 'POKEDEX_ENTRY_NUMBER':
pokemon_int = int(variable['key'])
pokemon = Pokemons.name_for(pokemon_int)
if variable['name'] == 'POKEMON_NICKNAME':
pokemon = variable['literal']

Expand All @@ -1606,6 +1644,9 @@ def heartbeat(self):
for variable in notification['variables']:
if variable['name'] == 'GYM_NAME':
gym_name = variable['literal']
if variable['name'] == 'POKEDEX_ENTRY_NUMBER':
pokemon_int = int(variable['key'])
pokemon = Pokemons.name_for(pokemon_int)
if variable['name'] == 'POKEMON_NICKNAME':
pokemon = variable['literal']
if variable['name'] == 'POKECOIN_AWARDED':
Expand Down
8 changes: 4 additions & 4 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ fi
if [ ! -f "$config" ]; then
echo "There's no config file. Please use ./setup.sh -c to create one."
fi
while true
do
#while true
#do
python pokecli.py -af $auth -cf $config
echo `date`" Pokebot "$*" Stopped."
read -p "Press any button or wait 20 seconds to continue.
read -p "Press any button or wait 20 seconds to exit.
" -r -s -n1 -t 20
done
#done
exit 0