blob: 78c4ed70b1c97ab01f7e97a8407a79ec7d914fb7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
"""
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 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 “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"
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)
|