Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev merge to master, PR #4085

Merged
merged 6 commits into from
Aug 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"gmapkey": "GOOGLE_MAPS_API_KEY",
"encrypt_location": "",
"websocket_server": false,
"heartbeat_threshold": 10,
"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 @@ -5,6 +5,7 @@
"location": "SOME_LOCATION",
"gmapkey": "GOOGLE_MAPS_API_KEY",
"encrypt_location": "",
"heartbeat_threshold": 10,
"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 @@ -5,6 +5,7 @@
"location": "SOME_LOCATION",
"gmapkey": "GOOGLE_MAPS_API_KEY",
"encrypt_location": "",
"heartbeat_threshold": 10,
"tasks": [
{
"type": "HandleSoftBan"
Expand Down
9 changes: 8 additions & 1 deletion pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,14 @@ def _json_loader(filename):
type=float,
default=1
)

add_config(
parser,
load,
long_flag="--heartbeat_threshold",
help="A threshold between each heartbeat sending to server",
type=int,
default=10
)
# Start to parse other attrs
config = parser.parse_args()
if not config.username and 'username' not in load:
Expand Down
23 changes: 18 additions & 5 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def __init__(self, config):
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()

self.heartbeat_threshold = self.config.heartbeat_threshold
self.heartbeat_counter = 0
def start(self):
self._setup_event_system()
self._setup_logging()
Expand Down Expand Up @@ -474,6 +475,15 @@ def _register_events(self):
def tick(self):
self.health_record.heartbeat()
self.cell = self.get_meta_cell()

now = time.time() * 1000

for fort in self.cell["forts"]:
timeout = fort.get("cooldown_complete_timestamp_ms", 0)

if timeout >= now:
self.fort_timeouts[fort["id"]] = timeout

self.tick_count += 1

# Check if session token has expired
Expand Down Expand Up @@ -1008,10 +1018,13 @@ def heartbeat(self):
self.fort_timeouts = {id: timeout for id, timeout
in self.fort_timeouts.iteritems()
if timeout >= time.time() * 1000}
request = self.api.create_request()
request.get_player()
request.check_awarded_badges()
request.call()
self.heartbeat_counter = self.heartbeat_counter + 1
if self.heartbeat_counter >= self.heartbeat_threshold:
self.heartbeat_counter = 0
request = self.api.create_request()
request.get_player()
request.check_awarded_badges()
request.call()
try:
self.web_update_queue.put_nowait(True) # do this outside of thread every tick
except Queue.Full:
Expand Down
2 changes: 1 addition & 1 deletion pokemongo_bot/cell_workers/follow_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def work(self):
lng
)

if dist <= 1 or (self.bot.config.walk > 0 and is_at_destination):
if dist <= 1 or (self.bot.config.walk_min > 0 and is_at_destination):
if (self.ptr + 1) == len(self.points):
self.ptr = 0
if self.path_mode == 'linear':
Expand Down
2 changes: 1 addition & 1 deletion pokemongo_bot/cell_workers/follow_spiral.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def work(self):
}
)

if dist <= 1 or (self.bot.config.walk > 0 and step_walker == None):
if dist <= 1 or (self.bot.config.walk_min > 0 and step_walker == None):
if self.ptr + self.direction >= len(self.points) or self.ptr + self.direction <= -1:
self.direction *= -1
if len(self.points) != 1:
Expand Down
20 changes: 3 additions & 17 deletions pokemongo_bot/cell_workers/spin_fort.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,14 @@ def work(self):
player_latitude=f2i(self.bot.position[0]),
player_longitude=f2i(self.bot.position[1])
)
if 'responses' in response_dict and 'FORT_SEARCH' in response_dict['responses']:

if ('responses' in response_dict) and ('FORT_SEARCH' in response_dict['responses']):
spin_details = response_dict['responses']['FORT_SEARCH']
spin_result = spin_details.get('result', -1)
if spin_result == SPIN_REQUEST_RESULT_SUCCESS:

if (spin_result == SPIN_REQUEST_RESULT_SUCCESS) or (spin_result == SPIN_REQUEST_RESULT_INVENTORY_FULL):
self.bot.softban = False
experience_awarded = spin_details.get('experience_awarded', 0)


items_awarded = self.get_items_awarded_from_fort_spinned(response_dict)

if experience_awarded or items_awarded:
Expand Down Expand Up @@ -108,12 +107,6 @@ def work(self):
formatted="Pokestop {pokestop} on cooldown. Time left: {minutes_left}.",
data={'pokestop': fort_name, 'minutes_left': minutes_left}
)
elif spin_result == SPIN_REQUEST_RESULT_INVENTORY_FULL:
if not self.ignore_item_count:
self.emit_event(
'inventory_full',
formatted="Inventory is full!"
)
else:
self.emit_event(
'unknown_spin_result',
Expand Down Expand Up @@ -148,12 +141,6 @@ def work(self):

def get_forts_in_range(self):
forts = self.bot.get_forts(order_by_distance=True)

for fort in reversed(forts):
if 'cooldown_complete_timestamp_ms' in fort:
self.bot.fort_timeouts[fort["id"]] = fort['cooldown_complete_timestamp_ms']
forts.remove(fort)

forts = filter(lambda fort: fort["id"] not in self.bot.fort_timeouts, forts)
forts = filter(lambda fort: distance(
self.bot.position[0],
Expand Down Expand Up @@ -186,4 +173,3 @@ def get_items_awarded_from_fort_spinned(self, response_dict):
# TODO : Refactor this class, hide the inventory update right after the api call
def _update_inventory(self, item_awarded):
inventory.items().get(item_awarded['item_id']).add(item_awarded['item_count'])

2 changes: 1 addition & 1 deletion pokemongo_bot/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def all(self):

def add(self, pokemon):
if pokemon.id <= 0:
raise ValueError("Can't add a pokemin whitout id")
raise ValueError("Can't add a pokemon without id")
if pokemon.id in self._data:
raise ValueError("Pokemon already present in the inventory")
self._data[pokemon.id] = pokemon
Expand Down
9 changes: 9 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ filename="./configs/config.json"
fi
cd $pokebotpath
source bin/activate
git fetch -a
if [ "1" == $(git branch -vv |grep -c "* dev") ] && [ $(git log --pretty=format:"%h" -1) != $(git log --pretty=format:"%h" -1 origin/dev) ]
then
echo "Branch dev hav an update. Run ./setup.sh -u to update."
elif [ "1" == $(git branch -vv |grep -c "* master") ] && [ $(git log --pretty=format:"%h" -1) != $(git log --pretty=format:"%h" -1 origin/master) ]
then
echo "Branch master hav an update. Run ./setup.sh -u to update."
fi
sleep 2
if [ ! -f "$filename" ]; then
echo "There's no "$filename" file. Please use ./setup.sh -c to creat one."
fi
Expand Down
25 changes: 22 additions & 3 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ then
echo "You are on Mac os"
sudo brew update
sudo brew install --devel protobuf
elif [ $(uname -s) == CYGWIN* ]
then
echo "You are on Cygwin"
if [ !-x "$(command -v apt-cyg)" ]
then
wget http://apt-cyg.googlecode.com/svn/trunk/apt-cyg
chmod +x apt-cyg
mv apt-cyg /usr/local/bin/
fi
apt-cyg install gcc-core make
easy_install pip
elif [ -x "$(command -v apt-get)" ]
then
echo "You are on Debian/Ubuntu"
Expand Down Expand Up @@ -91,7 +102,7 @@ echo "Please check if you have python pip gcc make installed on your device."
echo "Wait 5 seconds to continue or Use ctrl+c to interrupt this shell."
sleep 5
fi
sudo pip install virtualenv
easy_install virtualenv
Pokebotreset
Pokebotupdate
Pokebotencrypt
Expand All @@ -101,8 +112,16 @@ Pokebotconfig

function Pokebotreset () {
cd $pokebotpath
git fetch --all
git fetch -a
if [ "1" == $(git branch -vv |grep -c "* dev") ]
then
echo "Branch dev resetting."
git reset --hard origin/dev
elif [ "1" == $(git branch -vv |grep -c "* master") ]
then
echo "Branch master resetting."
git reset --hard origin/master
fi
if [ -x "$(command -v python2)" ]
then
virtualenv -p python2 .
Expand All @@ -118,7 +137,7 @@ echo " -i,--install. Install PokemonGo-Bot."
echo " -b,--backup. Backup config files."
echo " -c,--config. Easy config generator."
echo " -e,--encrypt. Make encrypt.so."
echo " -r,--reset. Force sync dev branch."
echo " -r,--reset. Force sync source branch."
echo " -u,--update. Command git pull to update."
}

Expand Down