Skip to content

Commit

Permalink
Dev merge to master (#2939)
Browse files Browse the repository at this point in the history
* Adding plugin support (#2679)

* Adding plugin support

* Adding an empty __init__.py

* Moving the base task to the project root (#2702)

* Moving the base task to the project root

* Moving the base class more

* Changing the import again

* Adding a heartbeat to the analytics (#2709)

* Adding a heartbeat to the analytics

* Heartbeat every 30 seconds, not every 5

* Don't double track clients

* Fix 'local variable 'bot' referenced before assignment'

* Providing an error if tasks don't work for the given api (#2732)

* Fix for utf8 encoding when catching lured pokemon (#2720)

* Fixing lure pokestop encoding

* fixing lure encoding

* Fix For catchable not being displayed on the web (#2719)

* Fix For catchable not being displayed on the web

* Update catch_visible_pokemon.py

* Added encrypt.so compilation process to Dockerfile (#2695)

* OS Detection for encrypt lib (#2768)

Fix 32bit check, darwin and linux use the same file

Make it a function

Check if file exists, if not show error

Define file_name first

Fix return

Check if file exists, if not show error

Print info about paths

Fix for 32/64bit detection

* Fix Typo in unexpected_response_retry (#2531)

fixes #2525 #2523

* Revert "changing license from MIT to GPLv3"

This reverts commit 69fb64f.

* When the google analytics domain is blocked the bot crashed. (#2764)

With a simple try / except this can be solved.

Fix dirty catch all

* Fixes #2698 - Prevents "Possibly searching too often" error after re-login. (#2771)

* Fixes #2698
- Added api.activate_signature call to prevent issue after re-login.
- Also replaced deprecated log call with event_manager emit to prevent exception being thrown.

* Modified to use OS detected library path as per PR #2768

* Support loading plugins from .zip files (#2766)

* Keep track of how many pokemon released (#2884)

* Setting Library path to work with encrypt.so (#2899)

Setting LD_LIBRARY_PATH on Dockerfile

* ✨ Added login and username to available stats (#2494)

Added a player_data property in PokemonGoBot to access player data from outside
Added unit tests for login and username stats
Added tests for call args when updating the window title
Added a platform-specific test for window title updating on win32 platform

* [dev] small fixes (#2912)

* Fixed emit_event typo

* Update CONTRIBUTORS.md

* Changed initialization location for "bot"

We use bot in main exception on 128

* Update pokecli.py
  • Loading branch information
solderzzc authored Aug 7, 2016
1 parent fddf30d commit 5b3fe3d
Show file tree
Hide file tree
Showing 37 changed files with 367 additions and 745 deletions.
2 changes: 2 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@
* matheussampaio
* Abraxas000
* lucasfevi
* Moonlight-Angel
* mjmadsen
9 changes: 8 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ RUN echo $timezone > /etc/timezone \

RUN apt-get update \
&& apt-get install -y python-protobuf
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

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

ENTRYPOINT ["python", "pokecli.py"]
ENV LD_LIBRARY_PATH /usr/src/app

ENTRYPOINT ["python", "pokecli.py"]
676 changes: 5 additions & 671 deletions LICENSE

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

from pokemongo_bot import PokemonGoBot, TreeConfigBuilder
from pokemongo_bot.health_record import BotEvent
from pokemongo_bot.plugin_loader import PluginLoader

if sys.version_info >= (2, 7, 9):
ssl._create_default_https_context = ssl._create_unverified_context
Expand All @@ -51,6 +52,8 @@
logger.setLevel(logging.INFO)

def main():
bot = False

try:
logger.info('PokemonGO Bot v1.0')
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
Expand All @@ -73,6 +76,7 @@ def main():
tree = TreeConfigBuilder(bot, config.raw_tasks).build()
bot.workers = tree
bot.metrics.capture_stats()
bot.health_record = health_record

bot.event_manager.emit(
'bot_start',
Expand Down Expand Up @@ -384,6 +388,7 @@ def init_config():
config.release = load.get('release', {})
config.action_wait_max = load.get('action_wait_max', 4)
config.action_wait_min = load.get('action_wait_min', 1)
config.plugins = load.get('plugins', [])
config.raw_tasks = load.get('tasks', [])

config.vips = load.get('vips', {})
Expand Down Expand Up @@ -439,6 +444,10 @@ def task_configuration_error(flag_name):
parser.error("--catch_randomize_spin_factor is out of range! (should be 0 <= catch_randomize_spin_factor <= 1)")
return None

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

# create web dir if not exists
try:
os.makedirs(web_dir)
Expand Down
52 changes: 46 additions & 6 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from pgoapi.utilities import f2i, get_cell_ids

import cell_workers
from base_task import BaseTask
from plugin_loader import PluginLoader
from api_wrapper import ApiWrapper
from cell_workers.utils import distance
from event_manager import EventManager
Expand All @@ -25,9 +27,9 @@
from pokemongo_bot.socketio_server.runner import SocketIoRunner
from pokemongo_bot.websocket_remote_control import WebsocketRemoteControl
from worker_result import WorkerResult
from tree_config_builder import ConfigException, TreeConfigBuilder


from tree_config_builder import ConfigException, MismatchTaskApiVersion, TreeConfigBuilder
from sys import platform as _platform
import struct
class PokemonGoBot(object):
@property
def position(self):
Expand All @@ -37,6 +39,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 Down Expand Up @@ -383,6 +394,7 @@ def _register_events(self):
self.event_manager.register_event('unset_pokemon_nickname')

def tick(self):
self.health_record.heartbeat()
self.cell = self.get_meta_cell()
self.tick_count += 1

Expand Down Expand Up @@ -544,11 +556,17 @@ def check_session(self, position):
self.api._auth_provider._ticket_expire / 1000 - time.time()

if remaining_time < 60:
self.logger.info("Session stale, re-logging in", 'yellow')
self.event_manager.emit(
'api_error',
sender=self,
level='info',
formatted='Session stale, re-logging in.'
)
position = self.position
self.api = ApiWrapper()
self.position = position
self.login()
self.api.activate_signature(self.get_encryption_lib())

@staticmethod
def is_numeric(s):
Expand Down Expand Up @@ -588,6 +606,29 @@ def login(self):
formatted="Login successful."
)

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":
# Check if we are on 32 or 64 bit
if sys.maxsize > 2**32:
file_name = 'encrypt_64.dll'
else:
file_name = 'encrypt.dll'

path = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
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 + ' Bot root directory: '+ path)
sys.exit(1)
else:
self.logger.info('Found '+ file_name +'! Platform: ' + _platform + ' Bot root directory: ' + path)

return full_path

def _setup_api(self):
# instantiate pgoapi
self.api = ApiWrapper()
Expand All @@ -599,8 +640,7 @@ def _setup_api(self):
# chain subrequests (methods) into one RPC call

self._print_character_info()

self.api.activate_signature("encrypt.so")
self.api.activate_signature(self.get_encryption_lib())
self.logger.info('')
self.update_inventory()
# send empty map_cells and then our position
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


class BaseTask(object):
TASK_API_VERSION = 1

def __init__(self, bot, config):
self.bot = bot
Expand Down
3 changes: 1 addition & 2 deletions pokemongo_bot/cell_workers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from follow_path import FollowPath
from follow_spiral import FollowSpiral
from collect_level_up_reward import CollectLevelUpReward
from base_task import BaseTask
from follow_cluster import FollowCluster
from sleep_schedule import SleepSchedule
from update_title_stats import UpdateTitleStats
from update_title_stats import UpdateTitleStats
8 changes: 5 additions & 3 deletions pokemongo_bot/cell_workers/catch_lured_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

from pokemongo_bot.cell_workers.utils import fort_details
from pokemongo_bot.cell_workers.pokemon_catch_worker import PokemonCatchWorker
from pokemongo_bot.cell_workers.base_task import BaseTask
from pokemongo_bot.base_task import BaseTask


class CatchLuredPokemon(BaseTask):
SUPPORTED_TASK_API_VERSION = 1

def work(self):
lured_pokemon = self.get_lured_pokemon()
if lured_pokemon:
Expand All @@ -22,15 +24,15 @@ def get_lured_pokemon(self):
details = fort_details(self.bot, fort_id=fort['id'],
latitude=fort['latitude'],
longitude=fort['longitude'])
fort_name = details.get('name', 'Unknown').encode('utf8', 'replace')
fort_name = details.get('name', 'Unknown')

encounter_id = fort.get('lure_info', {}).get('encounter_id', None)

if encounter_id:
result = {
'encounter_id': encounter_id,
'fort_id': fort['id'],
'fort_name': fort_name,
'fort_name': u"{}".format(fort_name),
'latitude': fort['latitude'],
'longitude': fort['longitude']
}
Expand Down
8 changes: 5 additions & 3 deletions pokemongo_bot/cell_workers/catch_visible_pokemon.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import json

from pokemongo_bot.cell_workers.base_task import BaseTask
from pokemongo_bot.base_task import BaseTask
from pokemongo_bot.cell_workers.pokemon_catch_worker import PokemonCatchWorker
from utils import distance


class CatchVisiblePokemon(BaseTask):
SUPPORTED_TASK_API_VERSION = 1

def work(self):
if 'catchable_pokemons' in self.bot.cell and len(self.bot.cell['catchable_pokemons']) > 0:
# Sort all by distance from current pos- eventually this should
Expand All @@ -14,9 +16,9 @@ def work(self):
key=
lambda x: distance(self.bot.position[0], self.bot.position[1], x['latitude'], x['longitude'])
)

user_web_catchable = 'web/catchable-{}.json'.format(self.bot.config.username)
for pokemon in self.bot.cell['catchable_pokemons']:
with open('user_web_catchable', 'w') as outfile:
with open(user_web_catchable, 'w') as outfile:
json.dump(pokemon, outfile)
self.emit_event(
'catchable_pokemon',
Expand Down
4 changes: 3 additions & 1 deletion pokemongo_bot/cell_workers/collect_level_up_reward.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from pokemongo_bot.cell_workers.base_task import BaseTask
from pokemongo_bot.base_task import BaseTask


class CollectLevelUpReward(BaseTask):
SUPPORTED_TASK_API_VERSION = 1

current_level = 0
previous_level = 0

Expand Down
5 changes: 3 additions & 2 deletions pokemongo_bot/cell_workers/evolve_pokemon.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from pokemongo_bot.human_behaviour import sleep
from pokemongo_bot.item_list import Item
from pokemongo_bot.cell_workers.base_task import BaseTask
from pokemongo_bot.base_task import BaseTask


class EvolvePokemon(BaseTask):
SUPPORTED_TASK_API_VERSION = 1

def initialize(self):
self.api = self.bot.api
Expand Down Expand Up @@ -58,7 +59,7 @@ def _should_run(self):
if result is 1: # Request success
self.emit_event(
'used_lucky_egg',
formmated='Used lucky egg ({amount_left} left).',
formatted='Used lucky egg ({amount_left} left).',
data={
'amount_left': lucky_egg_count - 1
}
Expand Down
3 changes: 2 additions & 1 deletion pokemongo_bot/cell_workers/follow_cluster.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from pokemongo_bot.step_walker import StepWalker
from pokemongo_bot.cell_workers.utils import distance
from pokemongo_bot.cell_workers.utils import find_biggest_cluster
from pokemongo_bot.cell_workers.base_task import BaseTask
from pokemongo_bot.base_task import BaseTask

class FollowCluster(BaseTask):
SUPPORTED_TASK_API_VERSION = 1

def initialize(self):
self.is_at_destination = False
Expand Down
4 changes: 3 additions & 1 deletion pokemongo_bot/cell_workers/follow_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
import gpxpy
import gpxpy.gpx
import json
from pokemongo_bot.cell_workers.base_task import BaseTask
from pokemongo_bot.base_task import BaseTask
from pokemongo_bot.cell_workers.utils import distance, i2f, format_dist
from pokemongo_bot.human_behaviour import sleep
from pokemongo_bot.step_walker import StepWalker
from pgoapi.utilities import f2i


class FollowPath(BaseTask):
SUPPORTED_TASK_API_VERSION = 1

def initialize(self):
self.ptr = 0
self._process_config()
Expand Down
4 changes: 3 additions & 1 deletion pokemongo_bot/cell_workers/follow_spiral.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

from pokemongo_bot.cell_workers.utils import distance, format_dist
from pokemongo_bot.step_walker import StepWalker
from pokemongo_bot.cell_workers.base_task import BaseTask
from pokemongo_bot.base_task import BaseTask

class FollowSpiral(BaseTask):
SUPPORTED_TASK_API_VERSION = 1

def initialize(self):
self.steplimit = self.config.get("diameter", 4)
self.step_size = self.config.get("step_size", 70)
Expand Down
4 changes: 3 additions & 1 deletion pokemongo_bot/cell_workers/handle_soft_ban.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
from pgoapi.utilities import f2i

from pokemongo_bot.constants import Constants
from pokemongo_bot.cell_workers.base_task import BaseTask
from pokemongo_bot.base_task import BaseTask
from pokemongo_bot.cell_workers import MoveToFort
from pokemongo_bot.cell_workers.utils import distance
from pokemongo_bot.worker_result import WorkerResult


class HandleSoftBan(BaseTask):
SUPPORTED_TASK_API_VERSION = 1

def work(self):
if not self.should_run():
return
Expand Down
4 changes: 3 additions & 1 deletion pokemongo_bot/cell_workers/incubate_eggs.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from pokemongo_bot.human_behaviour import sleep
from pokemongo_bot.cell_workers.base_task import BaseTask
from pokemongo_bot.base_task import BaseTask


class IncubateEggs(BaseTask):
SUPPORTED_TASK_API_VERSION = 1

last_km_walked = 0

def initialize(self):
Expand Down
3 changes: 2 additions & 1 deletion pokemongo_bot/cell_workers/move_to_fort.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
from pokemongo_bot.constants import Constants
from pokemongo_bot.step_walker import StepWalker
from pokemongo_bot.worker_result import WorkerResult
from pokemongo_bot.cell_workers.base_task import BaseTask
from pokemongo_bot.base_task import BaseTask
from utils import distance, format_dist, fort_details


class MoveToFort(BaseTask):
SUPPORTED_TASK_API_VERSION = 1

def initialize(self):
self.lure_distance = 0
Expand Down
4 changes: 3 additions & 1 deletion pokemongo_bot/cell_workers/move_to_map_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
from pokemongo_bot.cell_workers.utils import distance, format_dist, format_time
from pokemongo_bot.step_walker import StepWalker
from pokemongo_bot.worker_result import WorkerResult
from pokemongo_bot.cell_workers.base_task import BaseTask
from pokemongo_bot.base_task import BaseTask
from pokemongo_bot.cell_workers.pokemon_catch_worker import PokemonCatchWorker


class MoveToMapPokemon(BaseTask):
SUPPORTED_TASK_API_VERSION = 1

def initialize(self):
self.last_map_update = 0
self.pokemon_data = self.bot.pokemon_list
Expand Down
4 changes: 3 additions & 1 deletion pokemongo_bot/cell_workers/nickname_pokemon.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from pokemongo_bot.human_behaviour import sleep
from pokemongo_bot.cell_workers.base_task import BaseTask
from pokemongo_bot.base_task import BaseTask

class NicknamePokemon(BaseTask):
SUPPORTED_TASK_API_VERSION = 1

def initialize(self):
self.template = self.config.get('nickname_template','').lower().strip()
if self.template == "{name}":
Expand Down
Loading

0 comments on commit 5b3fe3d

Please sign in to comment.