2013-06-18 18:30:36 +00:00
|
|
|
|
"""
|
|
|
|
|
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``
|
|
|
|
|
|
|
|
|
|
"""
|
2016-06-27 23:10:52 +00:00
|
|
|
|
from poezio.plugin import BasePlugin
|
|
|
|
|
from poezio import tabs
|
2013-06-18 18:30:36 +00:00
|
|
|
|
import string
|
2016-06-27 23:10:52 +00:00
|
|
|
|
from poezio import xhtml
|
2014-04-10 17:34:26 +00:00
|
|
|
|
import random
|
2013-06-18 18:30:36 +00:00
|
|
|
|
|
|
|
|
|
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,
|
2014-04-10 17:34:26 +00:00
|
|
|
|
help="Repeats the last word of the last "
|
|
|
|
|
"message in the conversation, and "
|
|
|
|
|
"use it in an annoying “C’est toi "
|
|
|
|
|
"le” sentence.",
|
2013-06-18 18:30:36 +00:00
|
|
|
|
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"
|
2014-04-10 17:34:26 +00:00
|
|
|
|
intro = "C'est toi " if random.getrandbits(1) else "Stoi "
|
|
|
|
|
if last_word[0] in 'aeiouAEIOUÀàÉéÈè':
|
|
|
|
|
msg = intro + ('l’%s' % last_word)
|
|
|
|
|
else:
|
|
|
|
|
msg = intro + ('le %s' % last_word)
|
|
|
|
|
self.api.send_message(msg)
|
|
|
|
|
|