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

Updated Sniper docs, config.map.example and config.example files. #5554

Merged
merged 6 commits into from
Sep 22, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
73 changes: 66 additions & 7 deletions configs/config.json.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"websocket_server": false,
"heartbeat_threshold": 10,
"enable_social": true,
"enable_social": false,
"live_config_update": {
"enabled": false,
"tasks_only": false
Expand Down Expand Up @@ -196,6 +196,71 @@
"recycle_force_max": "00:05:00"
}
},
{
"type": "Sniper",
"config": {
"enabled": false,
"mode": "social",
"bullets": 1,
"homing_shots": true,
"special_iv": 100,
"order": ["missing", "vip", "priority"],
"sources": [
{
"url": "http://localhost:5000/raw_data",
"key": "pokemons",
"mappings": {
"id": { "param": "pokemon_id" },
"name": { "param": "pokemon_name" },
"latitude": { "param": "latitude" },
"longitude": { "param": "longitude" },
"expiration": { "param": "disappear_time", "format": "milliseconds" }
}
},
{
"url": "https://pokewatchers.com/grab/",
"mappings": {
"iv": { "param": "iv" },
"id": { "param": "pid" },
"name": { "param": "pokemon" },
"latitude": { "param": "cords" },
"longitude": { "param": "cords" },
"expiration": { "param": "timeend", "format": "milliseconds" }
}
},
{
"url": "http://pokesnipers.com/api/v1/pokemon.json",
"key": "results",
"mappings": {
"iv": { "param": "iv" },
"name": { "param": "name" },
"latitude": { "param": "coords" },
"longitude": { "param": "coords" },
"expiration": { "param": "until", "format": "utc" }
}
}
],
"catch": {
"Snorlax": 1000,
"Dragonite": 1000,
"Growlithe": 600,
"Clefairy": 500,
"Kabuto": 500,
"Dratini": 500,
"Dragonair": 500,
"Mr. Mime": 500,
"Magmar": 500,
"Electabuzz": 500,
"Tangela": 500,
"Tauros": 500,
"Primeape": 500,
"Chansey": 500,
"Pidgey": 100,
"Caterpie": 100,
"Weedle": 100
}
}
},
{
"type": "CatchPokemon",
"config": {
Expand Down Expand Up @@ -367,16 +432,10 @@
"Any pokemon put here directly force to use Berry & Best Ball to capture, to secure the capture rate": {},
"any": {"catch_above_cp": 1200, "catch_above_iv": 0.9, "logic": "or" },
"Lapras": {},
"Moltres": {},
"Zapdos": {},
"Articuno": {},

"// S-Tier pokemons (if pokemon can be evolved into tier, list the representative)": {},
"Mewtwo": {},
"Dragonite": {},
"Snorlax": {},
"// Mew evolves to Mewtwo": {},
"Mew": {},
"Arcanine": {},
"Vaporeon": {},
"Gyarados": {},
Expand Down
27 changes: 24 additions & 3 deletions configs/config.json.map.example
Original file line number Diff line number Diff line change
Expand Up @@ -455,22 +455,43 @@
"config": {
"enabled": true,
"mode": "social",
"bullets": 3,
"bullets": 1,
"homing_shots": true,
"special_iv": 100,
"order": ["missing", "iv", "priority", "vip", "expiration_timestamp_ms"],
"order": ["missing", "vip", "priority"],
"sources": [
{
"url": "http://localhost:5000/raw_data",
"key": "pokemons",
Copy link
Contributor

@DBa2016 DBa2016 Sep 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add "enabled": false

I suggest disabling all sources by default, allowing user to enable exactly what he wants to

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

"mappings": {
"iv": { "param": "iv" },
"id": { "param": "pokemon_id" },
"name": { "param": "pokemon_name" },
"latitude": { "param": "latitude" },
"longitude": { "param": "longitude" },
"expiration": { "param": "disappear_time", "format": "milliseconds" }
}
},
{
"url": "https://pokewatchers.com/grab/",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add "enabled": false, here, same reason

"mappings": {
"iv": { "param": "iv" },
"id": { "param": "pid" },
"name": { "param": "pokemon" },
"latitude": { "param": "cords" },
"longitude": { "param": "cords" },
"expiration": { "param": "timeend", "format": "milliseconds" }
}
},
{
"url": "http://pokesnipers.com/api/v1/pokemon.json",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add "enabled": false, here, same reason

"key": "results",
"mappings": {
"iv": { "param": "iv" },
"name": { "param": "name" },
"latitude": { "param": "coords" },
"longitude": { "param": "coords" },
"expiration": { "param": "until", "format": "utc" }
}
}
],
"catch": {
Expand Down
26 changes: 18 additions & 8 deletions docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -738,18 +738,18 @@ This task is an upgrade version of the MoveToMapPokemon task. It will fetch poke
* `mode` - The mode on which the sniper will fetch the informations. (default: social)
- `social` - Information will come from the social network.
- `url` - Information will come from one or multiple urls.
* `bullets` - Each bullet corresponds to an attempt of catching a pokemon. (default: 1)
* `homing_shots` - This will ensure that each bullet will catch a target. (default: true)
* `special_iv` - This will skip the catch list if the value is greater than the target's IV. This currently does not work with `social` mode and only works if the given `url` has this information. (default: 100)
* `bullets` - Each bullet corresponds to an **ATTEMPT** of catching a pokemon. (default: 1)
* `homing_shots` - This will ensure that each bullet **will catch** a target. If disabled, a target might not exist and thus it wont be caught. When enabled, this will jump to the next target (if any) and try again to catch it. This will be repeated untill you've spent all the bullets. (default: true)
* `special_iv` - This will skip the catch list if the value is greater than or equal to the target's IV. This currently does not work with `social` mode and only works if the given `url` has this information. (default: 100)
* `time_mask` - The time mask used (if `expiration.format` is a full date). The default mask is '%Y-%m-%d %H:%M:%S'.
* `order` - The order on which you want to snipe. This can be one or multiple of the following values (default: [`missing`, `vip`, `threshold`]):
* `order` - The order on which you want to snipe. This can be one or multiple of the following values (default: [`missing`, `vip`, `priority`]):
- `iv` - Order by IV, if any. See `min_iv_to_ignore_catch_list`.
- `vip` - Order by VIP.
- `missing` - Order by the target's pokedex missing status.
- `threshold` - Order by the threshold you have specified in the `catch` list.
- `priority` - Order by the priority you have specified in the `catch` list.
- `expiration_timestamp_ms` - Order by the expiration time.
* `sources` - This should map a JSON param values from a given url. For example: different urls will provide different JSON response formats. If a param does not exist, you DO NOT have to specify it! Map bellow their corresponding values:
- `iv` - The JSON param that corresponds to the pokemon IV. Only certain sources provide this info. NOTE: social does not provide this info!
* `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:
- `iv` - The JSON param that corresponds to the pokemon IV. Only certain sources provide this info. **NOTE:** `social` mode does not provide this info!
- `id` - The JSON param that corresponds to the pokemon ID. (required)
- `name` - The JSON param that corresponds to the pokemon name. (required)
- `latitude` - The JSON param that corresponds to the latitude. It will work if a single param is used for both `latitude` and `longitude`, eg.: "coords": "1.2345, 6.7890" (required)
Expand Down Expand Up @@ -789,13 +789,23 @@ This task is an upgrade version of the MoveToMapPokemon task. It will fetch poke
"url": "http://localhost:5000/raw_data",
"key": "pokemons",
"mappings": {
"iv": { "param": "iv" },
"id": { "param": "pokemon_id" },
"name": { "param": "pokemon_name" },
"latitude": { "param": "latitude" },
"longitude": { "param": "longitude" },
"expiration": { "param": "disappear_time", "format": "milliseconds" }
}
},
{
"url": "https://pokewatchers.com/grab/",
"mappings": {
"iv": { "param": "iv" },
"id": { "param": "pid" },
"name": { "param": "pokemon" },
"latitude": { "param": "cords" },
"longitude": { "param": "cords" },
"expiration": { "param": "timeend", "format": "milliseconds" }
}
}
],
"catch": {
Expand Down
64 changes: 33 additions & 31 deletions pokemongo_bot/cell_workers/sniper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import calendar

from random import uniform
from datetime import datetime, timedelta
from datetime import datetime
from pokemongo_bot import inventory
from pokemongo_bot.item_list import Item
from pokemongo_bot.base_task import BaseTask
Expand Down Expand Up @@ -62,8 +62,8 @@ def fetch(self, timeout):
expiration = expiration * 1000
elif self.mappings.expiration.format == SniperSourceMappingTimeFormat.UTC:
utc_date = datetime.strptime(expiration.replace("T", " ")[:19], self.time_mask)
timestamp = calendar.timegm(utc_date.timetuple())
local_date = datetime.fromtimestamp(timestamp)
unix_timestamp = calendar.timegm(utc_date.timetuple())
local_date = datetime.fromtimestamp(unix_timestamp)
local_date = local_date.replace(microsecond=utc_date.microsecond)
expiration = time.mktime(local_date.timetuple()) * 1000

Expand Down Expand Up @@ -206,33 +206,35 @@ def initialize(self):
self.altitude = uniform(self.bot.config.alt_min, self.bot.config.alt_max)
self.sources = [SniperSource(data) for data in self.config.get('sources', [])]

# Validate ordering
for ordering in self.order:
if ordering not in vars(SniperOrderMode).values():
raise ValueError("Unrecognized ordering: '{}'".format(ordering))
# Dont bother validating config if its not enabled
if self.enabled:
# Validate ordering
for ordering in self.order:
if ordering not in vars(SniperOrderMode).values():
raise ValueError("Unrecognized ordering: '{}'".format(ordering))

# Validate mode and sources
if self.mode not in vars(SniperMode).values():
raise ValueError("Unrecognized mode: '{}'".format(self.mode))
else:
# Selected mode is valid. Validate sources if mode is URL
if self.mode == SniperMode.URL:
self._log("Validating sources: {}...".format(", ".join([source.url for source in self.sources])))

# Create a copy of the list so we can iterate and remove elements at the same time
for source in list(self.sources):
try:
source.validate()
self._log("Source '{}' is good!".format(source.url))
# TODO: On ValueError, remember source and validate later (pending validation)
except (LookupError, ValueError) as exception:
self._error("Source '{}' contains errors. Details: {}. Removing from sources list...".format(source.url, exception))
self.sources.remove(source)

# Notify user if all sources are invalid and cant proceed
if not self.sources:
self._error("There is no source available. Disabling Sniper...")
self.disabled = True
# Validate mode and sources
if self.mode not in vars(SniperMode).values():
raise ValueError("Unrecognized mode: '{}'".format(self.mode))
else:
# Selected mode is valid. Validate sources if mode is URL
if self.mode == SniperMode.URL:
self._log("Validating sources: {}...".format(", ".join([source.url for source in self.sources])))

# Create a copy of the list so we can iterate and remove elements at the same time
for source in list(self.sources):
try:
source.validate()
self._log("Source '{}' is good!".format(source.url))
# TODO: On ValueError, remember source and validate later (pending validation)
except (LookupError, ValueError) as exception:
self._error("Source '{}' contains errors. Details: {}. Removing from sources list...".format(source.url, exception))
self.sources.remove(source)

# Notify user if all sources are invalid and cant proceed
if not self.sources:
self._error("There is no source available. Disabling Sniper...")
self.disabled = True

def is_snipeable(self, pokemon):
pokeballs_count = self.inventory.get(Item.ITEM_POKE_BALL.value).count
Expand All @@ -258,7 +260,7 @@ def is_snipeable(self, pokemon):
# Skip if not in catch list, not a VIP and/or IV sucks (if any)
if pokemon.get('pokemon_name', '') not in self.catch_list:
# This is not in the catch list. Lets see if its a VIP one
if not pokemon.get('vip'):
if not pokemon.get('vip', False):
# It is not a VIP either. Lets see if its IV is good (if any)
if pokemon.get('iv', 0) < self.special_iv:
self._trace('{} is not listed to catch, nor a VIP and its IV sucks. Skipping...'.format(pokemon.get('pokemon_name')))
Expand All @@ -278,7 +280,7 @@ def snipe(self, pokemon):

# Apply snipping business rules and snipe if its good
if not self.is_snipeable(pokemon):
self._error('{} is not snipeable! Skipping...'.format(pokemon['pokemon_name']))
self._trace('{} is not snipeable! Skipping...'.format(pokemon['pokemon_name']))
else:
# Backup position before anything
last_position = self.bot.position[0:2]
Expand Down