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

[Feature] Recycle Threshold #2465

Merged
merged 10 commits into from
Aug 9, 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 CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@
* mjmadsen
* nikofil
* bigkraig
* nikhil-pandey
1 change: 1 addition & 0 deletions configs/config.json.cluster.example
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
{
"type": "RecycleItems",
"config": {
"min_empty_space": 15,
"item_filter": {
"Pokeball": { "keep" : 100 },
"Potion": { "keep" : 10 },
Expand Down
1 change: 1 addition & 0 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
{
"type": "RecycleItems",
"config": {
"min_empty_space": 15,
"item_filter": {
"Pokeball": { "keep" : 100 },
"Potion": { "keep" : 10 },
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 @@ -33,6 +33,7 @@
{
"type": "RecycleItems",
"config": {
"min_empty_space": 15,
"item_filter": {
"Pokeball": { "keep" : 100 },
"Potion": { "keep" : 10 },
Expand Down
1 change: 1 addition & 0 deletions configs/config.json.path.example
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
{
"type": "RecycleItems",
"config": {
"min_empty_space": 15,
"item_filter": {
"Pokeball": { "keep" : 100 },
"Potion": { "keep" : 10 },
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 @@ -36,6 +36,7 @@
{
"type": "RecycleItems",
"config": {
"min_empty_space": 15,
"item_filter": {
"Pokeball": { "keep" : 100 },
"Potion": { "keep" : 10 },
Expand Down
4 changes: 4 additions & 0 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@ def _register_events(self):
'amount', 'item', 'maximum'
)
)
self.event_manager.register_event(
'item_discard_skipped',
parameters=('space',)
)
self.event_manager.register_event(
'item_discard_fail',
parameters=('item',)
Expand Down
23 changes: 21 additions & 2 deletions pokemongo_bot/cell_workers/recycle_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
from pokemongo_bot.base_task import BaseTask
from pokemongo_bot.tree_config_builder import ConfigException


class RecycleItems(BaseTask):
SUPPORTED_TASK_API_VERSION = 1

def initialize(self):
self.min_empty_space = self.config.get('min_empty_space', None)
self.item_filter = self.config.get('item_filter', {})
self._validate_item_filter()

Expand All @@ -15,9 +17,26 @@ def _validate_item_filter(self):
for config_item_name, bag_count in self.item_filter.iteritems():
if config_item_name not in item_list.viewvalues():
if config_item_name not in item_list:
raise ConfigException("item {} does not exist, spelling mistake? (check for valid item names in data/items.json)".format(config_item_name))
raise ConfigException(
"item {} does not exist, spelling mistake? (check for valid item names in data/items.json)".format(
config_item_name))

def work(self):
items_in_bag = self.bot.get_inventory_count('item')
total_bag_space = self.bot.player_data['max_item_storage']
free_bag_space = total_bag_space - items_in_bag

if self.min_empty_space is not None:
if free_bag_space >= self.min_empty_space:
self.emit_event(
'item_discard_skipped',
formatted="Skipping Recycling of Items. {space} space left in bag.",
data={
'space': free_bag_space
}
)
return

self.bot.latest_inventory = None
item_count_dict = self.bot.item_inventory_count('all')

Expand Down Expand Up @@ -58,7 +77,7 @@ def work(self):

def send_recycle_item_request(self, item_id, count):
# Example of good request response
#{'responses': {'RECYCLE_INVENTORY_ITEM': {'result': 1, 'new_count': 46}}, 'status_code': 1, 'auth_ticket': {'expire_timestamp_ms': 1469306228058L, 'start': '/HycFyfrT4t2yB2Ij+yoi+on778aymMgxY6RQgvrGAfQlNzRuIjpcnDd5dAxmfoTqDQrbz1m2dGqAIhJ+eFapg==', 'end': 'f5NOZ95a843tgzprJo4W7Q=='}, 'request_id': 8145806132888207460L}
# {'responses': {'RECYCLE_INVENTORY_ITEM': {'result': 1, 'new_count': 46}}, 'status_code': 1, 'auth_ticket': {'expire_timestamp_ms': 1469306228058L, 'start': '/HycFyfrT4t2yB2Ij+yoi+on778aymMgxY6RQgvrGAfQlNzRuIjpcnDd5dAxmfoTqDQrbz1m2dGqAIhJ+eFapg==', 'end': 'f5NOZ95a843tgzprJo4W7Q=='}, 'request_id': 8145806132888207460L}
return self.bot.api.recycle_inventory_item(
item_id=item_id,
count=count
Expand Down