summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2015-05-11 23:35:47 +0200
committermathieui <mathieui@mathieui.net>2015-05-11 23:35:47 +0200
commit1914cfe00365e67e8d82554cd10d2e35f68ad60d (patch)
tree303d48315889b7e4012bd8b038c1ca6b821984ef
parentaf0fe9d2e45d6216f1cb0417b03dff7425f57c28 (diff)
downloadpoezio-1914cfe00365e67e8d82554cd10d2e35f68ad60d.tar.gz
poezio-1914cfe00365e67e8d82554cd10d2e35f68ad60d.tar.bz2
poezio-1914cfe00365e67e8d82554cd10d2e35f68ad60d.tar.xz
poezio-1914cfe00365e67e8d82554cd10d2e35f68ad60d.zip
Add a cyberplugin
-rw-r--r--doc/source/plugins/cyber.rst6
-rw-r--r--doc/source/plugins/index.rst6
-rw-r--r--plugins/cyber.py40
3 files changed, 52 insertions, 0 deletions
diff --git a/doc/source/plugins/cyber.rst b/doc/source/plugins/cyber.rst
new file mode 100644
index 00000000..40bc5eb8
--- /dev/null
+++ b/doc/source/plugins/cyber.rst
@@ -0,0 +1,6 @@
+.. _cyber-plugin:
+
+Cyber
+=====
+
+.. automodule:: cyber
diff --git a/doc/source/plugins/index.rst b/doc/source/plugins/index.rst
index 9df47c3b..b5969fd9 100644
--- a/doc/source/plugins/index.rst
+++ b/doc/source/plugins/index.rst
@@ -87,6 +87,11 @@ Plugin index
Close all tabs except MUCs and the roster.
+ Cyber
+ :ref:`Documentation <cyber-plugin>`
+
+ Add a cybertouch to your messages.
+
Day Change
:ref:`Documentation <daychange-plugin>`
@@ -297,3 +302,4 @@ Plugin index
pipe_cmd
close_all
reorder
+ cyber
diff --git a/plugins/cyber.py b/plugins/cyber.py
new file mode 100644
index 00000000..67d6cdc7
--- /dev/null
+++ b/plugins/cyber.py
@@ -0,0 +1,40 @@
+"""
+This plugin adds a "cyber" prefix to a random word in your chatroom messages.
+
+Usage
+-----
+
+Say something in a MUC tab.
+
+Configuration options
+---------------------
+
+.. glossary::
+
+ frequency
+ **Default:** ``10``
+
+ The percentage of the time the plugin will activate (randomly). 100 for every message, <= 0 for never.
+"""
+
+from plugin import BasePlugin
+from random import choice, randint
+import re
+
+
+DEFAULT_CONFIG = {'cyber': {'frequency': 10}}
+
+class Plugin(BasePlugin):
+
+ default_config = DEFAULT_CONFIG
+
+ def init(self):
+ self.api.add_event_handler('muc_say', self.cyberize)
+
+ def cyberize(self, msg, tab):
+ if randint(1, 100) > self.config.get('frequency'):
+ return
+ words = [word for word in re.split('\W+', msg['body']) if len(word) > 3]
+ if words:
+ word = choice(words)
+ msg['body'] = msg['body'].replace(word, 'cyber' + word)