Skip to content

Commit

Permalink
Remove bot_on since it's actually unnecessary
Browse files Browse the repository at this point in the history
  • Loading branch information
wchill committed Jul 26, 2016
1 parent 70e0c36 commit e78cbf9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 50 deletions.
8 changes: 4 additions & 4 deletions plugins/logger/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
from pokemongo_bot import logger, event_manager
from pokemongo_bot.event_manager import manager

@manager.bot_on("before_catch_pokemon")
@manager.on("before_catch_pokemon")
def action_before_catch_pokemon(event, bot, name=None, cp=None, pokemon_potential=None, **kwargs):
logger.log("[#] A Wild {} appeared! [CP {}] [Potential {}]".format(name, cp, pokemon_potential, "yellow"))

@manager.bot_on("catch_pokemon")
@manager.on("catch_pokemon")
def action_catch_pokemon(hook_params):
pass

@manager.bot_on("after_catch_pokemon")
@manager.on("after_catch_pokemon")
def action_after_catch_pokemon(event, bot, name=None, cp=None, **kwargs):
logger.log("[x] Captured {} [CP {}]".format(name, cp, "green"))

@manager.bot_on("use_pokeball")
@manager.on("use_pokeball")
def action_use_pokeball(event, bot, pokeball_name=None, number_left=None, **kwargs):
logger.log("[x] Using {}... ({} left!)".format(pokeball_name, number_left))
9 changes: 0 additions & 9 deletions pokemongo_bot/event_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ def register_handler(function):
return function
return register_handler

# decorator that injects the bot context into the event handler
def bot_on(self, *trigger_list):
def register_handler(function):
for trigger in trigger_list:
# inject the bot context into the function as 2nd parameter and remove from kwargs
self.add_listener(trigger, lambda *args, **kwargs: function(args[0], kwargs.get('bot'), *(args[1:]), **{x:kwargs[x] for x in kwargs if x != 'bot'}))
return function
return register_handler

# fire an event and call all event handlers
def fire(self, event_name, *args, **kwargs):
if event_name in self.events:
Expand Down
37 changes: 0 additions & 37 deletions pokemongo_bot/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,40 +68,3 @@ def unload_plugin(self, plugin_name):
'''
del self.loaded_plugins[plugin_name]
self.logging.log('plugin "%s" unloaded' % plugin_name)

"""
def execute_action_hook(self, hook_name, hook_params=None):
'''
Executes action hook functions of the form action_hook_name contained in
the loaded plugin modules.
'''
if hook_params is None:
hook_params = {}
for plugin_info in self.loaded_plugins.values():
module = plugin_info['module']
hook_func_name = 'action_%s' % hook_name
if hasattr(module, hook_func_name):
hook_func = getattr(module, hook_func_name)
hook_func(hook_params)
def execute_filter_hook(self, hook_name, hook_params=None):
'''
Filters the hook_params through filter hook functions of the form
filter_hook_name contained in the loaded plugin modules.
'''
if hook_params is None:
hook_params = {}
hook_params_keys = hook_params.keys()
for plugin_info in self.loaded_plugins.values():
module = plugin_info['module']
hook_func_name = 'filter_%s' % hook_name
if hasattr(module, hook_func_name):
hook_func = getattr(module, hook_func_name)
hook_params = hook_func(hook_params)
for nkey in hook_params_keys:
if nkey not in hook_params.keys():
msg = 'function "%s" in plugin "%s" is missing "%s" in the dict it returns' % (hook_func_name, plugin_info['name'], nkey)
self.logging.log(msg)
raise Exception(msg)
return hook_params
"""

0 comments on commit e78cbf9

Please sign in to comment.