Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:PokemonGoF/PokemonGo-Bot into faetur…
Browse files Browse the repository at this point in the history
…e/xp-improvements
  • Loading branch information
douglascamata committed Aug 8, 2016
2 parents 8de542a + 5fb1f04 commit bb931f4
Show file tree
Hide file tree
Showing 27 changed files with 611 additions and 85 deletions.
2 changes: 2 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Please check configuration at http://jsonlint.com/ before posting an issue.

### Expected Behavior


Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ var/
.pydevproject
.settings/

# Cloud9 Users
.c9/

# Installer logs
pip-log.txt
pip-delete-this-directory.txt
Expand Down Expand Up @@ -86,6 +89,8 @@ celerybeat-schedule
# virtualenv
venv/
ENV/
local/
share/

# Spyder project settings
.spyderproject
Expand Down
3 changes: 3 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@
* matheussampaio
* Abraxas000
* lucasfevi
* Moonlight-Angel
* mjmadsen
* nikofil
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ RUN cd /tmp && wget "http://pgoapi.com/pgoencrypt.tar.gz" \
&& tar zxvf pgoencrypt.tar.gz \
&& cd pgoencrypt/src \
&& make \
&& cp libencrypt.so /usr/src/app/encrypt.so
&& cp libencrypt.so /usr/src/app/encrypt.so \
&& cd /tmp \
&& rm -rf /tmp/pgoencrypt*

VOLUME ["/usr/src/app/web"]

ENV LD_LIBRARY_PATH /usr/src/app

ENTRYPOINT ["python", "pokecli.py"]
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

# PokemonGo-Bot
# PokemonGo-Bot (Working)
PokemonGo bot is a project created by the [PokemonGoF](https://github.com/PokemonGoF) team.
The project is currently setup in two main branches. `dev` and `master`.


## Where to get the dll/so ?
You need grab them from internet.
## Please submit PR to [Dev branch](https://github.com/PokemonGoF/PokemonGo-Bot/tree/dev)

We use [Slack](https://slack.com) as a web chat. [Click here to join the chat!](https://pokemongo-bot.herokuapp.com)
You can count on the community in #help channel.

## Table of Contents
- [Features](#features)
Expand Down Expand Up @@ -64,10 +63,11 @@ To ensure that all updates are documented - [@eggins](https://github.com/eggins)

## Credits
- [tejado](https://github.com/tejado) many thanks for the API
- [U6 Group](http://pgoapi.com) for the U6
- [Mila432](https://github.com/Mila432/Pokemon_Go_API) for the login secrets
- [elliottcarlson](https://github.com/elliottcarlson) for the Google Auth PR
- [AeonLucid](https://github.com/AeonLucid/POGOProtos) for improved protos
- [AHAAAAAAA](https://github.com/AHAAAAAAA/PokemonGo-Map) for parts of the s2sphere stuff


[![Analytics](https://ga-beacon.appspot.com/UA-81468120-1/welcome-page-dev)](https://github.com/igrigorik/ga-beacon)
[![Analytics](https://ga-beacon.appspot.com/UA-81468120-1/welcome-page-master)](https://github.com/igrigorik/ga-beacon)
1 change: 1 addition & 0 deletions configs/config.json.cluster.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"password": "YOUR_PASSWORD",
"location": "SOME_LOCATION",
"gmapkey": "GOOGLE_MAPS_API_KEY",
"libencrypt_location": "",
"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 @@ -4,6 +4,7 @@
"password": "YOUR_PASSWORD",
"location": "SOME_LOCATION",
"gmapkey": "GOOGLE_MAPS_API_KEY",
"libencrypt_location": "",
"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 @@ -4,6 +4,7 @@
"password": "YOUR_PASSWORD",
"location": "SOME_LOCATION",
"gmapkey": "GOOGLE_MAPS_API_KEY",
"libencrypt_location": "",
"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 @@ -4,6 +4,7 @@
"password": "YOUR_PASSWORD",
"location": "SOME_LOCATION",
"gmapkey": "GOOGLE_MAPS_API_KEY",
"libencrypt_location": "",
"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 @@ -4,6 +4,7 @@
"password": "YOUR_PASSWORD",
"location": "SOME_LOCATION",
"gmapkey": "GOOGLE_MAPS_API_KEY",
"libencrypt_location": "",
"tasks": [
{
"type": "HandleSoftBan"
Expand Down
File renamed without changes.
36 changes: 28 additions & 8 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
from pokemongo_bot.health_record import BotEvent
from pokemongo_bot.plugin_loader import PluginLoader

try:
from demjson import jsonlint
except ImportError:
# Run `pip install -r requirements.txt` to fix this
jsonlint = None

if sys.version_info >= (2, 7, 9):
ssl._create_default_https_context = ssl._create_unverified_context

Expand All @@ -52,8 +58,9 @@
logger.setLevel(logging.INFO)

def main():
bot = False

try:
bot = False
logger.info('PokemonGO Bot v1.0')
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
sys.stderr = codecs.getwriter('utf8')(sys.stderr)
Expand Down Expand Up @@ -103,7 +110,7 @@ def main():
'api_error',
sender=bot,
level='info',
formmated='Log logged in, reconnecting in {:s}'.format(wait_time)
formatted='Log logged in, reconnecting in {:d}'.format(wait_time)
)
time.sleep(wait_time)
except ServerBusyOrOfflineException:
Expand All @@ -129,7 +136,7 @@ def main():
if bot:
report_summary(bot)

raise e
raise

def report_summary(bot):
if bot.metrics.start_time is None:
Expand Down Expand Up @@ -161,16 +168,28 @@ def init_config():
# If config file exists, load variables from json
load = {}

def _json_loader(filename):
try:
with open(filename, 'rb') as data:
load.update(json.load(data))
except ValueError:
if jsonlint:
with open(filename, 'rb') as data:
lint = jsonlint()
rc = lint.main(['-v', filename])

logger.critical('Error with configuration file')
sys.exit(-1)

# Select a config file code
parser.add_argument("-cf", "--config", help="Config File to use")
config_arg = parser.parse_known_args() and parser.parse_known_args()[0].config or None

if config_arg and os.path.isfile(config_arg):
with open(config_arg) as data:
load.update(json.load(data))
_json_loader(config_arg)
elif os.path.isfile(config_file):
logger.info('No config argument specified, checking for /configs/config.json')
with open(config_file) as data:
load.update(json.load(data))
_json_loader(config_file)
else:
logger.info('Error: No /configs/config.json or specified config')

Expand Down Expand Up @@ -383,6 +402,7 @@ def init_config():
if not config.password and 'password' not in load:
config.password = getpass("Password: ")

config.encrypt_location = load.get('encrypt_location','')
config.catch = load.get('catch', {})
config.release = load.get('release', {})
config.action_wait_max = load.get('action_wait_max', 4)
Expand Down Expand Up @@ -445,7 +465,7 @@ def task_configuration_error(flag_name):

plugin_loader = PluginLoader()
for plugin in config.plugins:
plugin_loader.load_path(plugin)
plugin_loader.load_plugin(plugin)

# create web dir if not exists
try:
Expand Down
70 changes: 63 additions & 7 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import sys
import struct
import time
import Queue
import threading

from geopy.geocoders import GoogleV3
from pgoapi import PGoApi
Expand Down Expand Up @@ -42,6 +44,15 @@ def position(self):
def position(self, position_tuple):
self.api._position_lat, self.api._position_lng, self.api._position_alt = position_tuple

@property
def player_data(self):
"""
Returns the player data as received from the API.
:return: The player data.
:rtype: dict
"""
return self._player

def __init__(self, config):
self.config = config
self.fort_timeouts = dict()
Expand All @@ -63,6 +74,11 @@ def __init__(self, config):
# Make our own copy of the workers for this instance
self.workers = []

# Theading setup for file writing
self.web_update_queue = Queue.Queue(maxsize=1)
self.web_update_thread = threading.Thread(target=self.update_web_location_worker)
self.web_update_thread.start()

def start(self):
self._setup_event_system()
self._setup_logging()
Expand Down Expand Up @@ -243,7 +259,7 @@ def _register_events(self):
)
)
self.event_manager.register_event(
'pokemon_fled',
'pokemon_escaped',
parameters=('pokemon',)
)
self.event_manager.register_event(
Expand Down Expand Up @@ -387,6 +403,35 @@ def _register_events(self):
)
self.event_manager.register_event('unset_pokemon_nickname')

# Move To map pokemon
self.event_manager.register_event(
'move_to_map_pokemon_fail',
parameters=('message',)
)
self.event_manager.register_event(
'move_to_map_pokemon_updated_map',
parameters=('lat', 'lon')
)
self.event_manager.register_event(
'move_to_map_pokemon_teleport_to',
parameters=('poke_name', 'poke_dist', 'poke_lat', 'poke_lon',
'disappears_in')
)
self.event_manager.register_event(
'move_to_map_pokemon_encounter',
parameters=('poke_name', 'poke_dist', 'poke_lat', 'poke_lon',
'disappears_in')
)
self.event_manager.register_event(
'move_to_map_pokemon_move_towards',
parameters=('poke_name', 'poke_dist', 'poke_lat', 'poke_lon',
'disappears_in')
)
self.event_manager.register_event(
'move_to_map_pokemon_teleport_back',
parameters=('last_lat', 'last_lon')
)

def tick(self):
self.health_record.heartbeat()
self.cell = self.get_meta_cell()
Expand Down Expand Up @@ -606,7 +651,6 @@ def login(self):
)

def get_encryption_lib(self):
file_name = ''
if _platform == "linux" or _platform == "linux2" or _platform == "darwin":
file_name = 'encrypt.so'
elif _platform == "Windows" or _platform == "win32" or _platform == "cygwin":
Expand All @@ -616,16 +660,19 @@ def get_encryption_lib(self):
else:
file_name = 'encrypt.dll'

path = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
full_path = path + '/'+ file_name
if self.config.encrypt_location == '':
path = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
else:
path = self.config.encrypt_location

full_path = path + '/'+ file_name
if not os.path.isfile(full_path):
self.logger.error(file_name + ' is not found! Please place it in the bots root directory.')
self.logger.info('Platform: '+ _platform)
self.logger.info('Bot root directory: '+ path)
sys.exit(1)
else:
self.logger.info('Found '+ file_name +'! Platform: ' + _platform + ' Bot root directory: ' + path)
self.logger.info('Found '+ file_name +'! Platform: ' + _platform + ' Encrypt.so directory: ' + path)

return full_path

Expand Down Expand Up @@ -716,7 +763,8 @@ def _print_character_info(self):
self.logger.info(
'Potion: ' + str(items_stock[101]) +
' | SuperPotion: ' + str(items_stock[102]) +
' | HyperPotion: ' + str(items_stock[103]))
' | HyperPotion: ' + str(items_stock[103]) +
' | MaxPotion: ' + str(items_stock[104]))

self.logger.info(
'Incense: ' + str(items_stock[401]) +
Expand Down Expand Up @@ -944,7 +992,15 @@ def heartbeat(self):
request.get_player()
request.check_awarded_badges()
request.call()
self.update_web_location() # updates every tick
try:
self.web_update_queue.put_nowait(True) # do this outside of thread every tick
except Queue.Full:
pass

def update_web_location_worker(self):
while True:
self.web_update_queue.get()
self.update_web_location()

def get_inventory_count(self, what):
response_dict = self.get_inventory()
Expand Down
Loading

0 comments on commit bb931f4

Please sign in to comment.