poezio/plugins/stoi.py
Maxime “pep” Buquet b5849a868e
plugins: Make all changed plugins work in 1:1 tabs
These were still using tabs.ConversationTab that's been replaced by
Dynamic and StaticConversationTab. These class have been introduced
after resource locking was removed in 1:1, because they were needed for
some plugins like OTR.

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
2019-07-19 18:55:16 +02:00

60 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
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 poezio.plugin import BasePlugin
from poezio import tabs
import string
from poezio import xhtml
import random
char_we_dont_want = string.punctuation + ' ’„“”…«»'
class Plugin(BasePlugin):
def init(self):
for tab_type in (tabs.MucTab, tabs.PrivateTab, tabs.DynamicConversationTab, tabs.StaticConversationTab):
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"
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)