Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/DBa2016/PokemonGo-Bot into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
DBa2016 committed Aug 28, 2016
2 parents af985e8 + 007f02a commit ec35ab2
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 23 deletions.
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
# PokemonGo-Bot
PokemonGo bot is a project created by the [PokemonGoF](https://github.com/PokemonGoF) team.

## Table of Contents
- [Installation](https://github.com/PokemonGoF/PokemonGo-Bot/blob/dev/docs/installation.md)
- [Documentation](https://github.com/PokemonGoF/PokemonGo-Bot/blob/dev/docs/)
- [Support](#support)
- [help](#configuration-issueshelp)
- [bugs](#bugs--issues)
- [Feature request](#feature-requests)
- [Pull Requests](#pull-requests)
- [Features](#features)
- [Credits](#credits)

The project is currently setup in two main branches.
- `dev` also known as `beta` - This is where the latest features are, but you may also experience some issues with stability/crashes
- `master` also known as `stable` - The bot 'should' be stable on this branch, and is generally well tested

## [Desktop version](https://github.com/PokemonGoF/PokemonGo-Bot-Desktop)

## Support
###Configuration issues/help
### Configuration issues/help
If you need any help please don't create an issue as we have a great community on Slack. You can count on the community in [#help](https://pokemongo-bot.slack.com/messages/help/) channel.
- [Click here to signup (first time only)](https://pokemongo-bot.herokuapp.com)
- [Join if you're already a member](https://pokemongo-bot.slack.com/messages/general/).
Expand All @@ -23,12 +32,6 @@ While you're there vote on other feature requests to let the devs know what is m
###[Pull Requests](https://github.com/PokemonGoF/PokemonGo-Bot/pulls)
If you'd like to make your own changes, make sure you follow the pull request template, and ensure your PR is made against the 'dev' branch

## Table of Contents
- [Installation](https://github.com/PokemonGoF/PokemonGo-Bot/blob/dev/docs/installation.md)
- [Documentation](https://github.com/PokemonGoF/PokemonGo-Bot/blob/dev/docs/)
- [Features](#features)
- [Credits](#credits)

## Features
- [x] GPS Location configuration
- [x] Search Pokestops
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 @@ -180,6 +180,7 @@
"config": {
"enabled": true,
"address": "http://localhost:5000",
"//NOTE: Change the max_distance to adjust the max sniping range (km)": {},
"max_distance": 500,
"min_ball": 50,
"prioritize_vips": true,
Expand Down
37 changes: 35 additions & 2 deletions docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
- [Random Pause](#random-pause)
- [Egg Incubator](#egg-incubator)
- [ShowBestPokemon](#showbestpokemon)
- [Telegram Task](#telegram-task)

#Configuration files

Expand Down Expand Up @@ -85,7 +86,7 @@ Document the configuration options of PokemonGo-Bot.
|`favorite_locations` | [] | Allows you to define a collection of locations and coordinates, allowing rapid switch using a "label" on your location config
| `live_config_update.enabled` | false | Enable live config update
| `live_config_update.tasks_only` | false | True: quick update for Tasks only (without re-login). False: slower update for entire config file.

| `enable_social` | true | True: to chat with other pokemon go bot users [more information](https://github.com/PokemonGoF/PokemonGo-Bot/pull/4596)

## Logging configuration
[[back to top](#table-of-contents)]
Expand Down Expand Up @@ -550,7 +551,7 @@ This task will fetch current pokemon spawns from /raw_data of an PokemonGo-Map i
* `prioritize_vips` - Will prioritize vips in distance and priority mode above all normal pokemon if set to true
* `min_time` - Minimum time the pokemon has to be available before despawn
* `min_ball` - Minimum amount of balls required to run task
* `max_distance` - Maximum distance the pokemon is allowed to be when walking, ignored when sniping
* `max_distance` - Maximum distance the pokemon is allowed to be when sniping. (km)
* `snipe`:
- `True` - Will teleport to target pokemon, encounter it, teleport back then catch it
- `False` - Will walk normally to the pokemon
Expand All @@ -572,6 +573,7 @@ This task will fetch current pokemon spawns from /raw_data of an PokemonGo-Map i
"type": "MoveToMapPokemon",
"config": {
"address": "http://localhost:5000",
"//NOTE: Change the max_distance to adjust the max sniping range (km)": {},
"max_distance": 500,
"min_time": 60,
"min_ball": 50,
Expand Down Expand Up @@ -912,3 +914,34 @@ Available `info_to_show` :
```
2016-08-25 21:20:59,642 [ShowBestPokemon] [INFO] [show_best_pokemon] [Tauros, CP 575, IVCP 0.95, DPS 12.04] | [Grimer, CP 613, IVCP 0.93, DPS 13.93] | [Tangela, CP 736, IVCP 0.93, DPS 14.5] | [Staryu, CP 316, IVCP 0.92, DPS 10.75] | [Gastly, CP 224, IVCP 0.9, DPS 11.7]
```

## Telegram Task
[[back to top](#table-of-contents)]

### Description
[[back to top](#table-of-contents)]

[Telegram bot](https://telegram.org/) Announcer Level up, pokemon cought

Bot answer on command '/info' self stats.

### Options

* `telegram_token` : bot token (getting [there](https://core.telegram.org/bots#6-botfather) - one token per bot)
* `master` : id (without quotes) or username (in quotes, first character @) of bot owner, who will gett announces.
* `alert_catch` : array of pokemons, which will be announced on catch. if first array item `all` - announce all pokemons.

### Sample configuration
[[back to top](#table-of-contents)]
```json
{
"type": "TelegramTask",
"config": {
"enabled": true,
"master": 12345678,
"//master": "@username",
"alert_catch": ["Lapras","Dragonite"],
"//alert_catch": ["all"]
}
}
```
6 changes: 4 additions & 2 deletions docs/manual_installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ mv pgoencrypt/src/libencrypt.so encrypt.so
```bash
cp configs/config.json.example configs/config.json
vi configs/config.json
cp configs/auth.json.example configs/auth.json
vi configs/auth.json
```
####
- make shure your git repo is up to date
Expand All @@ -78,15 +80,15 @@ pip install -r requirements.txt
####
- finaly start the bot
```bash
./run.sh configs/config.json
./run.sh
```
####
- after reboot or closing the terminal at every new start go into the folder of the PokemonGo-Bot by going into the folder where you startet installing it an then
```bash
cd PokemonGo-Bot
#activate virtualenv and start
source bin/activate
./run.sh configs/config.json
./run.sh
```


Expand Down
8 changes: 8 additions & 0 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ def _register_events(self):
self.event_manager.register_event('set_start_location')
self.event_manager.register_event('load_cached_location')
self.event_manager.register_event('location_cache_ignored')

self.event_manager.register_event('debug')

# ignore candy above threshold
self.event_manager.register_event(
Expand Down Expand Up @@ -592,6 +594,12 @@ def _register_events(self):
'moving_to_pokemon_throught_fort',
parameters=('fort_name', 'distance','poke_name','poke_dist')
)
self.event_manager.register_event(
'move_to_map_pokemon',
parameters=('message')
)



# cached recent_forts
self.event_manager.register_event('loaded_cached_forts')
Expand Down
23 changes: 18 additions & 5 deletions pokemongo_bot/cell_workers/move_to_map_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
Moves a trainer to a Pokemon.
Events:
move_to_map_pokemon
When a generic message is logged
Returns:
message: Log message.
move_to_map_pokemon_fail
When the worker fails.
Returns:
Expand Down Expand Up @@ -83,7 +88,7 @@
SNIPE_MAX_IN_CHAIN = 2

# Don't call sniper every time in workers
SNIPE_SKIP_IN_ROUND = 30
SNIPE_SKIP_IN_ROUND = 5

DEBUG_ON = False

Expand Down Expand Up @@ -130,7 +135,13 @@ def get_pokemon_from_social(self):
pokemon['is_vip'] = pokemon['name'] in self.bot.config.vips

if pokemon['name'] not in self.config['catch']:
if DEBUG_ON:
self._emit_failure("Not catching {}".format(pokemon['name']))
continue
else:
if DEBUG_ON:
self._emit_log("Catching {}".format(pokemon['name']))


if self.was_caught(pokemon):
continue
Expand Down Expand Up @@ -300,14 +311,16 @@ def work(self):

if (pokeballs_quantity + superballs_quantity + ultraballs_quantity) < self.min_ball:
if DEBUG_ON:
print 'no enough balls'
self._emit_log("Not enough balls to start sniping (have {}, {} needed)".format(pokeballs_quantity + superballs_quantity + ultraballs_quantity, self.min_ball))
return WorkerResult.SUCCESS

self.dump_caught_pokemon()
if self.bot.config.enable_social:
if self.config['snipe']:
self.by_pass_times = self.by_pass_times + 1
if self.by_pass_times < SNIPE_SKIP_IN_ROUND:
if DEBUG_ON:
self._emit_log("Skipping pass {}".format(self.by_pass_times))
return WorkerResult.SUCCESS
self.by_pass_times = 0
pokemon_list = self.get_pokemon_from_social()
Expand All @@ -323,12 +336,12 @@ def work(self):

if len(pokemon_list) < 1:
if DEBUG_ON:
print 'No enough pokemon in list to snip'
self._emit_log("No pokemons in list to snipe")
return WorkerResult.SUCCESS

pokemon = pokemon_list[0]
if DEBUG_ON:
print 'How many pokemon in list: {}'.format(len(pokemon_list))
self._emit_log('How many pokemon in list: {}'.format(len(pokemon_list)))
if self.config['snipe']:
if self.snipe_high_prio_only:
count = 0
Expand All @@ -342,7 +355,7 @@ def work(self):
time.sleep(SNIPE_SLEEP_SEC*5)
else:
if DEBUG_ON:
print 'this pokemon is not good enough to snip {}'.format(pokemon)
self._emit_log('this pokemon is not good enough to snipe {}'.format(pokemon))
return WorkerResult.SUCCESS
else:
return self.snipe(pokemon)
Expand Down
2 changes: 2 additions & 0 deletions pokemongo_bot/cell_workers/pokemon_catch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False):
min_ultraball_to_keep = self.min_ultraball_to_keep

used_berry = False
original_catch_rate_by_ball = catch_rate_by_ball
while True:

# find lowest available ball
Expand Down Expand Up @@ -492,6 +493,7 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False):
data={'pokemon': pokemon.name}
)
used_berry = False
catch_rate_by_ball = original_catch_rate_by_ball

# sleep according to flee_count and flee_duration config settings
# randomly chooses a number of times to 'show' wobble animation between 1 and flee_count
Expand Down
17 changes: 16 additions & 1 deletion pokemongo_bot/cell_workers/telegram_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
from pokemongo_bot.base_task import BaseTask
from pokemongo_bot.base_dir import _base_dir
from pokemongo_bot.event_handlers import TelegramHandler

from pprint import pprint
import re

class TelegramTask(BaseTask):
SUPPORTED_TASK_API_VERSION = 1
update_id = None
Expand Down Expand Up @@ -37,8 +41,19 @@ def work(self):
self.update_id = update.update_id+1
if update.message:
self.logger.info("message from {} ({}): {}".format(update.message.from_user.username, update.message.from_user.id, update.message.text))
if self.config.get('master',None) and self.config.get('master',None)<>update.message.from_user.id:
if self.config.get('master',None) and self.config.get('master',None) not in [update.message.from_user.id, "@{}".format(update.message.from_user.username)]:
self.emit_event(
'debug',
formatted="Master wrong: expecting {}, got {}({})".format(self.config.get('master',None), update.message.from_user.username, update.message.from_user.id))
continue
else:
if not re.match(r'^[0-9]+$', "{}".format(self.config['master'])): # master was not numeric...
self.config['master'] = update.message.chat_id
idx = (i for i,v in enumerate(self.bot.event_manager._handlers) if type(v) is TelegramHandler).next()
self.bot.event_manager._handlers[idx] = TelegramHandler(self.tbot,self.config['master'], self.config.get('alert_catch'))



if update.message.text == "/info":
stats = self._get_player_stats()
if stats:
Expand Down
17 changes: 13 additions & 4 deletions pokemongo_bot/event_handlers/telegram_handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from pokemongo_bot.event_manager import EventHandler
import thread
import re

DEBUG_ON = False

Expand All @@ -9,15 +10,23 @@ def __init__(self, tbot,master,pokemons):
self.tbot = tbot
self.master=master
self.pokemons=pokemons
self.whoami="TelegramHandler"

def handle_event(self, event, sender, level, formatted_msg, data):
if self.master:
if not re.match(r'^[0-9]+$', str(self.master)):
return
master = self.master

if event == 'level_up':
self.tbot.sendMessage(chat_id=self.master, parse_mode='Markdown', text="level up ({})".format(data["current_level"]))
msg = "level up ({})".format(data["current_level"])
elif event == 'pokemon_caught':
if data["pokemon"] in self.pokemons or self.pokemons[0]=="all":
self.tbot.sendMessage(chat_id=self.master, parse_mode='Markdown',
text="Caught {} CP: {}, IV: {}".format(data["pokemon"],data["cp"],data["iv"])
)
msg = "Caught {} CP: {}, IV: {}".format(data["pokemon"],data["cp"],data["iv"])
else:
return
else:
return
self.tbot.sendMessage(chat_id=master, parse_mode='Markdown', text=msg)


0 comments on commit ec35ab2

Please sign in to comment.