Skip to content

Commit

Permalink
Merge pull request #6159 from PokemonGoF/dev
Browse files Browse the repository at this point in the history
Dev merge to master
  • Loading branch information
solderzzc authored Jul 28, 2017
2 parents 003a2b2 + c912a52 commit e974e27
Show file tree
Hide file tree
Showing 19 changed files with 677 additions and 161 deletions.
228 changes: 228 additions & 0 deletions MultiBot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
#encoding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import gzip
import json
import multiprocessing
import os
import platform
import re
import shutil
import sys
import threading
import time
from time import gmtime, strftime, sleep
from threading import *
import requests

Null = ""
proxyCur = 0
hashkeyCur = 0
accountNum = 0
try:
os.rmdir('configs/temp')
except:
pass
try:
os.mkdir('configs/temp')
except:
pass
AccountLock = Semaphore(value=1)
screen_lock = Semaphore(value=1)
MultiBotConfig = json.loads(open('configs/MultiBotConfig.json').read())

def getProxy():
try:
while True:
try:
with open('configs/' + MultiBotConfig[u'ProxyFile']) as proxyFile:
proxyAll = proxyFile.readlines()
proxyNum = sum(1 for line in open('configs/' + MultiBotConfig[u'ProxyFile']))
global proxyCur
global proxy
proxy = proxyAll[proxyCur].replace('\n', '').replace('\r', '')
proxies = {"http": "http://" + proxy, "https": "https://" + proxy}
proxyCur += 1
if proxyCur >= proxyNum:
proxyCur = 0
headers = {'user-agent': 'Niantic App'}
if requests.get('https://pgorelease.nianticlabs.com/plfe/', headers=headers, proxies=proxies).status_code == 200:
headers = {'user-agent': 'pokemongo/1 CFNetwork/758.5.3 Darwin/15.6.0'}
if requests.get('https://sso.pokemon.com/', headers=headers, proxies=proxies).status_code == 200:
return proxy
else:
Lprint ("Proxy is Banned")
else:
Lprint ("Proxy is Banned")

except Exception as e:
Lprint (e)
pass
except KeyboardInterrupt:
stop()
except IOError:
Lprint ('configs/{} does not exist'.format(MultiBotConfig[u'ProxyFile']))
except KeyboardInterrupt:
stop()

try:
Accounts = []
with open('configs/' + MultiBotConfig[u'AccountsFile']) as f:
for line in f:
line = line.replace('\n', '').replace('\r', '').replace(',', '.')
Accounts.append(line)
except IOError:
Lprint ('configs/{} does not exist'.format(MultiBotConfig[u'AccountsFile']))
except KeyboardInterrupt:
stop()

def getHashKey():
try:
with open('configs/' + MultiBotConfig[u'HashKeyFile']) as hashkeyFile:
hashkeyAll = hashkeyFile.readlines()
hashkeyNum = sum(1 for line in open('configs/' + MultiBotConfig[u'HashKeyFile']))-1
global hashkeyCur
global hashkey
if hashkeyCur is hashkeyNum:
hashkeyCur = 0
hashkeyCur += 1
return hashkeyAll[hashkeyCur].replace('\n', '').replace('\r', '')
except IOError:
Lprint ('configs/{} does not exist'.format(MultiBotConfig[u'HashKeyFile']))
except KeyboardInterrupt:
stop()

def stop():
Lprint ('Interrupted stopping')
try:
sys.exit(0)
except SystemExit:
os._exit(0)



def AccountManager(Account=None):
AccountLock.acquire()
global Accounts
if Account is None:
AccountTemp = Accounts[0]
del Accounts[0]
AccountLock.release()
return AccountTemp
else:
Accounts.append(Account)
AccountLock.release()

def Lprint (content):
content = "{0} {1}".format(strftime("%Y-%m-%d %H:%M:%S"), content)
screen_lock.acquire()
print (content)
screen_lock.release()

def MakeConf(CurThread, username, password):
try:
jsonData = json.loads(open('configs/' + MultiBotConfig[u'AuthJsonFile']).read())
jsonData[u'username'] = username
jsonData[u'password'] = password
jsonData[u'hashkey'] = getHashKey()

with open('configs/temp/auth-' + str(CurThread) + '.json', 'w') as s:
s.write(json.dumps(jsonData))
s.close()

jsonData = json.loads(open('configs/' + MultiBotConfig[u'ConfigJsonFile']).read())
if MultiBotConfig[u'CompleteTutorialNickName']:
for i in range(len(jsonData[u'tasks'])):
try:
if jsonData[u'tasks'][i][u'config'][u'nickname']:
jsonData[u'tasks'][i][u'config'][u'nickname'] = username.replace('_', '')
except KeyboardInterrupt:
stop()
except:
pass
if MultiBotConfig[u'WebSocket'][u'start_embedded_server']:
try:
if jsonData[u'websocket'][u'server_url']:
jsonData[u'websocket'][u'server_url'] = MultiBotConfig[u'WebSocket'][u'IP'] + ':' + str(MultiBotConfig[u'WebSocket'][u'Port'] + CurThread)
except KeyboardInterrupt:
stop()
except:
jsonData.items().append("{u'websocket':,{u'server_url': u'" + MultiBotConfig[u'WebSocket'][u'IP'] + ":" + str(MultiBotConfig[u'WebSocket'][u'Port'] + CurThread) + "u'start_embedded_server': True}")



with open('configs/temp/config-' + str(CurThread) + '.json', 'w') as s:
s.write(json.dumps(jsonData))
s.close()

except IOError:
Lprint ('config file error')
time.sleep(30)
except KeyboardInterrupt:
stop()


class ThreadClass(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.paused = True # start out paused
self.state = threading.Condition()

def run(self):
time.sleep(.1)
self.resume() # unpause self
while True:
with self.state:
if self.paused:
self.state.wait() # block until notified
self.CurThread = int(self.getName().replace('Thread-', '')) -1

self.Account = AccountManager()
self.username, self.password = self.Account.split(':')
Lprint ('Thread-{0} using account {1}'.format(self.CurThread, self.username))
try:
MakeConf(self.CurThread, self.username, self.password)
if MultiBotConfig[u'UseProxy']:
self.proxy = getProxy()
if platform.system() == "Linux":
self.os.system('export HTTP_PROXY="http://' + proxy + '"; export HTTPS_PROXY="https://' + proxy + '"')
if platform.system() == "Windows":
self.os.system('')
os.system(
"python pokecli.py -af configs/temp/auth-{0}.json -cf configs/temp/config-{0}.json --walker_limit_output {1}".format(
self.CurThread, MultiBotConfig[u'walker_limit_output']))
except Exception as e:
import traceback
Lprint ((e))
time.sleep (60)
except KeyboardInterrupt:
stop()
finally:
AccountManager(self.Account)

def resume(self):
with self.state:
self.paused = False
self.state.notify() # unblock self if waiting

def pause(self):
with self.state:
self.paused = True # make self block and wait
def stop(self):
self.stopped = True


def start():
try:
for i in range(MultiBotConfig[u'Threads']):
t = ThreadClass()
time.sleep (0.1)
t.start()
time.sleep (10)
except KeyboardInterrupt:
Lprint("stopping all Threads")
for i in range(MultiBotConfig[u'Threads']):
t.stop()
stop()

if __name__ == "__main__":
start()
16 changes: 16 additions & 0 deletions configs/MultiBotConfig.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"Threads": 2,
"HashKeyFile": "MultiBotConfigHashkey.txt",
"UseProxy": false,
"ProxyFile": "MultiBotConfigProxy.txt",
"AccountsFile": "MultiBotConfigAccounts.txt",
"AuthJsonFile": "auth.json",
"ConfigJsonFile": "config.json",
"CompleteTutorialNickName": true,
"WebSocket": {
"start_embedded_server": false,
"IP": "127.0.0.1",
"Port": 4000
},
"walker_limit_output": true
}
2 changes: 2 additions & 0 deletions configs/MultiBotConfigAccounts.txt.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
username:password
username:password
2 changes: 2 additions & 0 deletions configs/MultiBotConfigHashkey.txt.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1I2F1L5B3D7F3K5G3Z2N
7V5J1K2H6S1F8I4V3V5Z
2 changes: 2 additions & 0 deletions configs/MultiBotConfigProxy.txt.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
127.0.0.1:1080
127.0.0.1:1080
12 changes: 7 additions & 5 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@
"missing",
"vip",
"priority"
],
],
"teleport_back_to_last_location": false,
"sources": [
{
"enabled": false,
Expand Down Expand Up @@ -418,12 +419,13 @@
"pinap_on_level_below": 0,
"pinap_operator": "or",
"pinap_ignore_threshold": false,
"smart_pinap_enabled": true,
"smart_pinap_threshold": 0.85,
"smart_pinap_to_keep": 3,
"smart_pinap_enabled": true,
"smart_pinap_threshold": 0.85,
"smart_pinap_to_keep": 3,
"vip_berry_threshold": 0.9,
"treat_unseen_as_vip": true,
"daily_catch_limit": 800,
"daily_catch_limit": 500,
"exit_on_limit_reached": false,
"vanish_settings": {
"consecutive_vanish_limit": 10,
"rest_duration_min": "02:00:00",
Expand Down
21 changes: 12 additions & 9 deletions configs/config.json.map.example
Original file line number Diff line number Diff line change
Expand Up @@ -442,16 +442,19 @@
{
"type": "Sniper",
"config": {
"enabled": false,
"mode": "social",
"bullets": 1,
"homing_shots": true,
"special_iv": 100,
"order": [
"missing",
"vip",
"priority"
"enabled": false,
"mode": "social",
"bullets": 1,
"homing_shots": true,
"cooldown_enabled": false,
"loiter_after_snipe": false,
"special_iv": 100,
"order": [
"missing",
"vip",
"priority"
],
"teleport_back_to_last_location": false,
"sources": [
{
"enabled": false,
Expand Down
3 changes: 3 additions & 0 deletions docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,8 @@ This task will fetch current pokemon spawns from /raw_data of an PokemonGo-Map i

This task is an upgrade version of the MoveToMapPokemon task. It will fetch pokemon informations from any number of urls (sources), including PokemonGo-Map, or from the social feature. You can also use the old PokemonGo-Map project. For information on how to properly setup PokemonGo-Map have a look at the Github page of the project [here](https://github.com/PokemonGoMap/PokemonGo-Map). You can also use [this](https://github.com/YvesHenri/PogoLocationFeeder), which is an adapted version of the application that NecroBot used to snipe. There is an example config in `config/config.json.map.example`.

Please note that this feature only works with a radius of 15KM. By default, it will continue at new location once snipe is done unless you specify it not to with `teleport_back_to_last_location` set to true.

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

Expand All @@ -887,6 +889,7 @@ This task is an upgrade version of the MoveToMapPokemon task. It will fetch poke
- `missing` - Order by the target's pokedex missing status.
- `priority` - Order by the priority you have specified in the `catch` list.
- `expiration_timestamp_ms` - Order by the expiration time.
* `teleport_back_to_last_location` - Specify if you want to teleport back to last location. Default is false.
* `sources` - This should map a JSON param values from a given url. For example: different urls will provide different JSON response formats. **PLEASE ADVISED THAT, IF A PARAM DOES NOT EXIST (OR CONTAINS WRONG DATA LIKE PokeSnipers's ID PARAM), DO NOT SPECIFY IT!** Pokesnipers is a special case where it does provide IDs, however theyre wrong. Map bellow their corresponding values:
* `sources.key` - The JSON key that contains the results, eg.: For a JSON response such as `{ "SomeWeirdoName": [{"id": 123, ...}, {"id": 143, ...}]}`, `SomeWeirdoName` would be the key name.
* `sources.url` - The URL that will provide the JSON.
Expand Down
19 changes: 11 additions & 8 deletions docs/manual_installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,25 @@ source bin/activate
```
cd C:\Python27\
pip install --upgrade pip
pip install --upgrade virtualenv
cd ..
cd to PokemonGo-Bot directory
git clone --recursive -b dev https://github.com/PokemonGoF/PokemonGo-Bot
pip install --upgrade -r C:/Python27/PokemonGo-Bot/requirements.txt
cd C:/Python27/PokemonGo-Bot/
virtualenv .
call C:\Python27\PokemonGo-Bot\Scripts\activate.bat
pip install --upgrade -r C:/Python27/PokemonGo-Bot/requirements.txt
pip install --upgrade -r requirements.txt
git pull
cd web
git checkout master
git pull
cd ..
```

##### Update

*Run the following commands in the Command Prompt with Administrator Privileges*

```
cd C:/Python27/PokemonGo-Bot/
cd to PokemonGo-Bot directory
git pull
pip uninstall pgoapi
git submodule update --init --recursive
```

3 changes: 1 addition & 2 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1644,7 +1644,7 @@ def get_forts(self, order_by_distance=False):
# Need to filter out disabled forts!
forts = filter(lambda x: x["enabled"] is True, forts)
forts = filter(lambda x: 'closed' not in fort, forts)

if order_by_distance:
forts.sort(key=lambda x: distance(
self.position[0],
Expand Down Expand Up @@ -1672,7 +1672,6 @@ def get_gyms(self, order_by_distance=False):
# Need to filter out disabled gyms!
forts = filter(lambda x: x["enabled"] is True, forts)
forts = filter(lambda x: 'closed' not in fort, forts)
# forts = filter(lambda x: 'type' not in fort, forts)

if order_by_distance:
forts.sort(key=lambda x: distance(
Expand Down
Loading

0 comments on commit e974e27

Please sign in to comment.