Last active
August 29, 2015 14:11
-
-
Save sleduc/1df7f86daec44a0469b9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/pipobot/lib/loader.py b/pipobot/lib/loader.py | |
index 40d00b2..0ac110d 100644 | |
--- a/pipobot/lib/loader.py | |
+++ b/pipobot/lib/loader.py | |
@@ -97,6 +97,14 @@ class BotModuleLoader(object): | |
except (AttributeError, ImportError): | |
logger.error("Error trying to import post_hook %s for module %s", func_path, module_name) | |
+ def set_flood_level(self, module_obj, module_name): | |
+ if module_name in self._module_settings and \ | |
+ "flood_level" in self._module_settings[module_name]: | |
+ flood_level = self._module_settings[module_name]["flood_level"] | |
+ setattr(module_obj, | |
+ "flood_level", | |
+ flood_level) | |
+ | |
def get_modules(self, module_names): | |
modules_tpl = namedtuple('modules_tpl', ['modules', 'test_mods']) | |
modules = [] | |
@@ -132,6 +140,7 @@ class BotModuleLoader(object): | |
# We search for _config parameter (ie required configuration parameter) in each module | |
for module in bot_modules: | |
self.set_post_hook(module, name) | |
+ self.set_flood_level(module, name) | |
if hasattr(module, "_config"): | |
# For each config parameter specified in the module | |
for (param_name, param_type, default_value) in module._config: | |
diff --git a/pipobot/lib/modules.py b/pipobot/lib/modules.py | |
index 10ca1bc..2328028 100644 | |
--- a/pipobot/lib/modules.py | |
+++ b/pipobot/lib/modules.py | |
@@ -89,8 +89,13 @@ class BotModule(object): | |
# A not specified module type ! | |
return | |
try: | |
if send is not None: | |
+ if hasattr(self, "flood_level"): | |
+ flood_level = self.flood_level | |
+ if len(send.split("\n")) > flood_level: | |
+ send = {"users": {sender: send}} | |
return getattr(self, "post_hook")(send) | |
except AttributeError: | |
return send |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
modules_config: | |
flood: | |
flood_level: 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment