summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2013-06-18 20:30:36 +0200
committerFlorent Le Coz <louiz@louiz.org>2013-06-18 20:30:36 +0200
commit3015b3b9e58b33210b79633110608b5fb41dead0 (patch)
tree752908fcf74d445b297ccb350649c730d00d1d63 /plugins
parentb5362ff7543f14bffc85dd39c5191fe91b90381c (diff)
downloadpoezio-3015b3b9e58b33210b79633110608b5fb41dead0.tar.gz
poezio-3015b3b9e58b33210b79633110608b5fb41dead0.tar.bz2
poezio-3015b3b9e58b33210b79633110608b5fb41dead0.tar.xz
poezio-3015b3b9e58b33210b79633110608b5fb41dead0.zip
Add the stoi plugin
Diffstat (limited to 'plugins')
-rw-r--r--plugins/stoi.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/plugins/stoi.py b/plugins/stoi.py
new file mode 100644
index 00000000..56440db5
--- /dev/null
+++ b/plugins/stoi.py
@@ -0,0 +1,50 @@
+"""
+Repeats the last word of the last message in the conversation, and use it in
+an annoying “C’est toi le” sentence.
+
+Installation
+------------
+
+You only have to load the plugin:
+
+.. code-block:: none
+
+ /load stoi
+
+.. glossary::
+
+ /stoi
+ **Usage:** ``/stoi``
+
+"""
+from plugin import BasePlugin
+import tabs
+import string
+import xhtml
+
+char_we_dont_want = string.punctuation+' ’„“”…«»'
+
+class Plugin(BasePlugin):
+ def init(self):
+ for tab_type in (tabs.MucTab, tabs.PrivateTab, tabs.ConversationTab):
+ self.api.add_tab_command(tab_type, 'stoi',
+ handler=self.stoi,
+ help="Repeats the last word of the last message "
+ "in the conversation, and use it in an "
+ "annoying “C’est toi le” sentence.",
+ short='C’est toi le stoi.')
+
+ def stoi(self, args):
+ messages = self.api.get_conversation_messages()
+ if not messages:
+ # Do nothing if the conversation doesn’t contain any message
+ return
+ last_message = messages[-1]
+ txt = xhtml.clean_text(last_message.txt)
+ for char in char_we_dont_want:
+ txt = txt.replace(char, ' ')
+ if txt.strip():
+ last_word = txt.split()[-1]
+ else:
+ last_word = "vide"
+ self.api.send_message("C’est toi le %s." % last_word)