|
|
|
@ -105,10 +105,27 @@ class Plugin:
|
|
|
|
|
return True
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def should_handle_command(self, message, no_content=False):
|
|
|
|
|
"""Store Command in object and return True if it should handle it."""
|
|
|
|
|
def should_handle_command(
|
|
|
|
|
self,
|
|
|
|
|
message,
|
|
|
|
|
no_content=False,
|
|
|
|
|
exclude_conditions=None,
|
|
|
|
|
):
|
|
|
|
|
"""Store Command in object and return True if it should handle it.
|
|
|
|
|
|
|
|
|
|
If no_content is True, the command does not parse command contents and
|
|
|
|
|
put all the command message (without suffix) to the command identifier.
|
|
|
|
|
This is useful for commands that have multiple words in their identifier
|
|
|
|
|
and do not have any content, or when the content parsing should be done
|
|
|
|
|
by the plugin itself.
|
|
|
|
|
|
|
|
|
|
If exclude_conditions is a collection of plugin namespaces, the
|
|
|
|
|
conditions of these plugins are not tested. A basic scenario is the
|
|
|
|
|
wakeup command from sleep plugin that requires excluding its own
|
|
|
|
|
condition (i.e. do not handle commands when sleeping).
|
|
|
|
|
"""
|
|
|
|
|
# Are the config conditions to handle a command valid?
|
|
|
|
|
if not self.__respects_handling_conditions():
|
|
|
|
|
if not self.__respects_handling_conditions(exclude_conditions):
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
# Is it a valid command?
|
|
|
|
@ -140,10 +157,12 @@ class Plugin:
|
|
|
|
|
content = " ".join(words[2:-1])
|
|
|
|
|
return Command(ident, content)
|
|
|
|
|
|
|
|
|
|
def __respects_handling_conditions(self):
|
|
|
|
|
def __respects_handling_conditions(self, exclude_conditions=None):
|
|
|
|
|
"""Check if question conditions are valid."""
|
|
|
|
|
conditions = self.config.get("handling_conditions", {})
|
|
|
|
|
for plugin_ns, plugin_conditions in conditions.items():
|
|
|
|
|
if exclude_conditions and plugin_ns in exclude_conditions:
|
|
|
|
|
continue
|
|
|
|
|
for condition_key, condition_value in plugin_conditions.items():
|
|
|
|
|
value = self.get_runtime_value(condition_key, ns=plugin_ns)
|
|
|
|
|
if condition_value != value:
|
|
|
|
|