summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2013-05-01 18:59:09 +0200
committerFlorent Le Coz <louiz@louiz.org>2013-05-01 18:59:09 +0200
commit5038367b9251012beffab4d6ebcfb26f44c42105 (patch)
tree38672db57cfaaf979e32c3c34024afe6764079b4
parent48aa8d0bda5d5e61a41e00301cc15c07e47a2237 (diff)
downloadpoezio-5038367b9251012beffab4d6ebcfb26f44c42105.tar.gz
poezio-5038367b9251012beffab4d6ebcfb26f44c42105.tar.bz2
poezio-5038367b9251012beffab4d6ebcfb26f44c42105.tar.xz
poezio-5038367b9251012beffab4d6ebcfb26f44c42105.zip
Add a new replace_word plugin.
-rw-r--r--plugins/replace_word.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/plugins/replace_word.py b/plugins/replace_word.py
new file mode 100644
index 00000000..6abb1702
--- /dev/null
+++ b/plugins/replace_word.py
@@ -0,0 +1,46 @@
+"""
+Replace some word with some other word in a message before sending it.
+
+
+Installation
+------------
+You only have to load the plugin.
+
+.. code-block:: none
+
+ /load replace_word
+
+Configuration example
+---------------------
+.. code-block:: ini
+
+[replace_word]
+# How to appear casual in your daily conversations.
+yes = yep
+no = nope
+
+Usage
+-----
+Just use the word in a message. It will be replaced automatically.
+
+"""
+
+from plugin import BasePlugin
+import tabs
+import re
+
+class Plugin(BasePlugin):
+ def init(self):
+ self.api.add_event_handler('conversation_say', self.replace_pattern)
+ self.api.add_event_handler('muc_say', self.replace_pattern)
+ self.api.add_event_handler('private_say', self.replace_pattern)
+
+ def replace_pattern(self, message, tab):
+ """
+ Look for a given word in the message and replace it by the corresponding word.
+ """
+ body = message['body']
+ for before in self.config.options("replace_word"):
+ after = self.config.get(before, before)
+ body = re.sub(r"\b%s\b" % before, after, body)
+ message['body'] = body