-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
69 lines (50 loc) · 1.85 KB
/
bot.py
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
61
62
63
64
65
66
67
68
69
from telegram.ext import Updater, CommandHandler
from config import TOKEN
import random as rd
TOTAL_QUESTIONS = 410
QUESTIONS = 'questions.txt'
def ask(bot, update):
update.message.reply_text( get_question() )
def get_question():
with open(QUESTIONS) as f:
content = f.readlines()
return content[ rd.randrange( 0 , TOTAL_QUESTIONS )]
return 'Te toca a ti preguntar'
def mimi(ms, indx=0):
""" str -> str"""
# caracteres especiales
# que -> qui (la u no te la puede transformar )
# c[aou] -> qui
# g[aeou] -> gui
# estos casos han sido generados con un for de antemano
esp = [["que", "qui"], ['ca', 'qui'], ['co', 'qui'],
['cu', 'qui'], ['ga', 'gui'], ['ge', 'gui'], ['go', 'gui'],
['gu', 'gui'], ['QUE', 'QUI'], ['CA', 'QUI'], ['CO', 'QUI'],
['CU', 'QUI'], ['GA', 'GUI'], ['GE', 'GUI'], ['GO', 'GUI'],
['GU', 'GUI']]
i = 0
while i < len(esp):
ind = ms.find(esp[i][0])
if ind != -1:
return mimi(ms[0:ind], indx+1) + esp[i][1] + mimi(ms[ind+len(esp[i][0]):], indx)
else:
i += 1
return mimi_normal(ms[0:])
def mimi_normal(ms):
""" str -> stryt"""
# Letras a reemplazar y su remplazamiento
cadena = [["aeou", "i"], ["aeou".upper(), "I"], ["áéóú", "í"],
["áéóú".upper(), "I"]]
for cad in cadena:
for vocal in cad[0]:
ms = ms.replace(vocal, cad[1])
return ms
def mimifica(bot, update):
mimificado = mimi(update.message.reply_to_message.text)
update.message.reply_to_message.reply_text(mimificado)
updater = Updater(TOKEN)
updater.dispatcher.add_handler(CommandHandler('ask', ask))
updater.dispatcher.add_handler(CommandHandler('mimifica', mimifica))
updater.dispatcher.add_handler(CommandHandler('mimi', mimifica))
updater.start_polling()
updater.idle()