Add the stoi plugin

This commit is contained in:
Florent Le Coz 2013-06-18 20:30:36 +02:00
parent b5362ff754
commit 3015b3b9e5

50
plugins/stoi.py Normal file
View file

@ -0,0 +1,50 @@
"""
Repeats the last word of the last message in the conversation, and use it in
an annoying Cest 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 “Cest toi le” sentence.",
short='Cest toi le stoi.')
def stoi(self, args):
messages = self.api.get_conversation_messages()
if not messages:
# Do nothing if the conversation doesnt 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("Cest toi le %s." % last_word)