Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
85f7607
Adding plugin support (#2679)
elicwhite Aug 7, 2016
f114be6
Moving the base task to the project root (#2702)
elicwhite Aug 7, 2016
0b319bc
Adding a heartbeat to the analytics (#2709)
elicwhite Aug 7, 2016
1c369a4
Don't double track clients
elicwhite Aug 7, 2016
e16b5ea
Fix 'local variable 'bot' referenced before assignment'
elicwhite Aug 7, 2016
e93431c
Providing an error if tasks don't work for the given api (#2732)
elicwhite Aug 7, 2016
d5bb09f
Fix for utf8 encoding when catching lured pokemon (#2720)
dkim1000 Aug 7, 2016
420c1be
Fix For catchable not being displayed on the web (#2719)
AcorpBG Aug 7, 2016
77200af
Added encrypt.so compilation process to Dockerfile (#2695)
Aug 7, 2016
e927195
OS Detection for encrypt lib (#2768)
brantje Aug 7, 2016
4f7888b
Fix Typo in unexpected_response_retry (#2531)
peter-bonanni Aug 7, 2016
e8f804a
Revert "changing license from MIT to GPLv3"
douglascamata Aug 7, 2016
27cf678
Merge branch 'dev' of github.com:PokemonGoF/PokemonGo-Bot into dev
douglascamata Aug 7, 2016
4eb7b38
When the google analytics domain is blocked the bot crashed. (#2764)
brantje Aug 7, 2016
6960f35
Fixes #2698 - Prevents "Possibly searching too often" error after re-…
geek-man Aug 7, 2016
eeecbc6
Support loading plugins from .zip files (#2766)
elicwhite Aug 7, 2016
2750255
Keep track of how many pokemon released (#2884)
bixuanzju Aug 7, 2016
823ba83
Setting Library path to work with encrypt.so (#2899)
bernardoVale Aug 7, 2016
fc4e802
:sparkles: Added login and username to available stats (#2494)
Aug 7, 2016
e5b7eda
[dev] small fixes (#2912)
mjmadsen Aug 7, 2016
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
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