Skip to content

Instantly share code, notes, and snippets.

@sleduc
Last active August 29, 2015 14:11
Show Gist options
  • Select an option

  • Save sleduc/22055565c9f168b38ef4 to your computer and use it in GitHub Desktop.

Select an option

Save sleduc/22055565c9f168b38ef4 to your computer and use it in GitHub Desktop.
diff --git a/pipobot/lib/loader.py b/pipobot/lib/loader.py
index 40d00b2..7c629a2 100644
--- a/pipobot/lib/loader.py
+++ b/pipobot/lib/loader.py
@@ -88,12 +88,20 @@ class BotModuleLoader(object):
def set_post_hook(self, module_obj, module_name):
if module_name in self._module_settings and \
"post_hook" in self._module_settings[module_name]:
- func_path = self._module_settings[module_name]["post_hook"]
+ hook = self._module_settings[module_name]["post_hook"]
+ kwargs = {}
+ if type(hook) is dict:
+ func_path = hook["path"]
+ kwargs = hook.copy()
+ del kwargs["path"]
+ else:
+ func_path = self._module_settings[module_name]["post_hook"]
+
try:
fct = import_fct(func_path, self._paths)
setattr(module_obj,
"post_hook",
- fct)
+ (fct, kwargs))
except (AttributeError, ImportError):
logger.error("Error trying to import post_hook %s for module %s", func_path, module_name)
diff --git a/pipobot/lib/modules.py b/pipobot/lib/modules.py
index 10ca1bc..50f1e7c 100644
--- a/pipobot/lib/modules.py
+++ b/pipobot/lib/modules.py
@@ -91,7 +91,8 @@ class BotModule(object):
try:
if send is not None:
- return getattr(self, "post_hook")(send)
+ post_hook, kwargs = self.post_hook
+ return post_hook(self, send, sender, **kwargs)
except AttributeError:
return send
except Pasteque as pasteque:
diff --git a/pipobot/lib/utils.py b/pipobot/lib/utils.py
index 480b8ba..409a8cb 100644
--- a/pipobot/lib/utils.py
+++ b/pipobot/lib/utils.py
@@ -156,14 +156,14 @@ def color(txt, color_name):
return "\033[%sm%s\033[0m" % (color_codes[color_name], txt)
-def rdyell(mod, message):
+def rdyell(mod, message, sender):
ret = ""
for c in message:
ret += c.upper() if random.randint(0, 1) == 1 else c
return ret
-def rd_censored(mod, message):
+def rd_censored(mod, message, sender):
ret = ""
for c in message:
if c == " ":
@@ -172,9 +172,15 @@ def rd_censored(mod, message):
ret += "*" if random.randint(0, 5) > 4 else c
return ret
-def rot13(mod, message):
+def rot13(mod, message, sender):
return codecs.encode(message, "rot13")
+def private_flood(mod, message, sender, limit=5):
+ if len(message.split("\n")) > limit:
+ return {"users": {sender: message}}
+ else:
+ return message
+
class ListConfigParser(configparser.RawConfigParser):
def get(self, section, option):
modules_config:
flood:
post_hook:
path: pipobot.lib.utils.private_flood
limit: 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment