Skip to content

Commit 1849690

Browse files
authored
BETA 1.4
Ahora se pueden añadir mensajes directamente desde el bot.
2 parents 635fa24 + b3d55c8 commit 1849690

93 files changed

Lines changed: 429 additions & 236 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cosas/TOKEN.pyc

-198 Bytes
Binary file not shown.

cosas/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from .objetos import Partida,Usuario
2-
from .sesiones import Sesion
32
from .TOKEN import TOKEN
4-
from .funciones import nuevosMensajes,enviarMensaje,error
3+
from .funciones import nuevosMensajes, enviarMensaje, error, debbugPrint
4+
from .queryCallbacks import CB_newMessage_normal, CB_noDisponible, CB_newMessage_picante, CB_newMessage_hef, CB_newMessage_done

cosas/__init__.pyc

-414 Bytes
Binary file not shown.

cosas/funciones.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,7 @@ def enviarMensaje(bot,update,Partidas,Usuarios):
9898
def error(e,bot,update):
9999
print "ERROR\n", e
100100
bot.send_message(chat_id=update.message.chat_id, text="Oh oh. Parece que ha ocurrido un error. Por favor, informa a"
101-
" @vetu11.\nSi el error persiste usa /restart")
101+
" @vetu11.\nSi el error persiste usa /restart")
102+
103+
def debbugPrint(txt):
104+
print txt

cosas/funciones.pyc

-3.9 KB
Binary file not shown.

cosas/objetos.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ def actualizarUsuario(self,idUsuario,posicion):
4545
self.usuariosActivos[posUsuLista]["ultimoUso"] = time.time()
4646
self.usuariosActivos[posUsuLista]["posicion"] = posicion
4747
else:
48-
self.usuariosActivos.append({"id":idUsuario,"posicion":posicion,"ajustes":{"hastaElFondo":False,"picante":False,"rondas":30},"ultimoUso":time.time()})
48+
self.usuariosActivos.append({"id":idUsuario,"posicion":posicion,"ajustes":{"hastaElFondo":False,"picante":False,"rondas":30},"ultimoUso":time.time(),"editando":None})
4949

5050
def guardarUsuarios(self):
5151
with open("usuarios","w") as f:
52-
json.dump(self.usuariosActivos,f,indent=True)
52+
json.dump(self.usuariosActivos,f,indent=4)
5353

5454
def borrarUsuarios(self):
5555
pos = 0
@@ -66,4 +66,17 @@ def borrarUsuarios(self):
6666

6767
if e["posicion"] == 2:
6868
self.usuariosActivos[indice]["posicion"] = 0
69-
indice = indice + 1
69+
indice = indice + 1
70+
71+
72+
"""
73+
POSICIONES:
74+
POSICION = 0: fuera de partida, después de acabarla o de escribir /start
75+
POSICION = 1: esperando lista de jugadores por parte de este usuario
76+
POSICION = 2: en partida
77+
POSICION = 3: en ajustes/personalizar.
78+
POSICION = 4: esperando nuevo mensaje de tipo normal
79+
POSICION = 5: esperando nuevo mensaje de tipo RI (reaparición instantánea)
80+
POSICION = 6: esperando nuevo mensaje de tipo RNI (reaparicón no instantánea)
81+
POSOCION = 7: esperando segundo mensaje para RI o RNI.
82+
"""

cosas/objetos.pyc

-3.29 KB
Binary file not shown.

cosas/queryCallbacks.py

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#coding=utf-8
2+
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, ParseMode
3+
4+
def CB_newMessage_categorias_generarKEY(picante, hef):
5+
keyboard = [[],[InlineKeyboardButton("Hecho 👌", callback_data="newMessage_done")]]
6+
7+
if picante == True:
8+
keyboard[0].append(InlineKeyboardButton("Picante ✅", callback_data="newMessage_picante"))
9+
else:
10+
keyboard[0].append(InlineKeyboardButton("Picante ❎", callback_data="newMessage_picante"))
11+
12+
if hef == True:
13+
keyboard[0].append((InlineKeyboardButton("Hasta el fondo ✅", callback_data="newMessage_hef")))
14+
else:
15+
keyboard[0].append(InlineKeyboardButton("Hasta el fondo ❎", callback_data="newMessage_hef"))
16+
17+
return keyboard
18+
19+
20+
def CB_newMessage_normal(bot,update,Usuarios):
21+
query = update.callback_query
22+
23+
Usuarios.actualizarUsuario(update.callback_query.from_user.id,4)
24+
25+
msg="Estas escribiendo un mensaje de tipo normal (de un sólo texto). Usa /cancel para cancelar.\n*RECUERDA:* Si q" \
26+
"uieres poner nombres de jugadores usa `{1}` para el primer nombre aleatorio y `{2}` para el segundo nombre."
27+
28+
keyboard = [[InlineKeyboardButton("AYUDA 🆘", url="telegra.ph/Okay-03-12")]]
29+
30+
bot.edit_message_text(text=msg,
31+
chat_id=query.message.chat_id,
32+
message_id=query.message.message_id,
33+
reply_markup=InlineKeyboardMarkup(keyboard),
34+
parse_mode=ParseMode.MARKDOWN)
35+
36+
37+
def CB_newMessage_picante(bot, update, Usuarios, newMessages):
38+
query = update.callback_query
39+
40+
posUsu = Usuarios.finder(query.from_user.id)
41+
editando = Usuarios.usuariosActivos[posUsu]["editando"]
42+
43+
variantesActuales = newMessages[editando]["variantes"]
44+
45+
if "picante" not in variantesActuales:
46+
newMessages[editando]["variantes"].append("picante")
47+
picante = True
48+
else:
49+
newMessages[editando]["variantes"].remove("picante")
50+
picante = False
51+
52+
if "hastaElFondo" in variantesActuales:
53+
hef = True
54+
else:
55+
hef = False
56+
57+
keyboard = CB_newMessage_categorias_generarKEY(picante, hef)
58+
59+
bot.edit_message_reply_markup(chat_id=query.message.chat_id,
60+
message_id=query.message.message_id,
61+
reply_markup=InlineKeyboardMarkup(keyboard))
62+
63+
def CB_newMessage_hef(bot, update, Usuarios, newMessages):
64+
query = update.callback_query
65+
66+
posUsu = Usuarios.finder(query.from_user.id)
67+
editando = Usuarios.usuariosActivos[posUsu]["editando"]
68+
69+
variantesActuales = newMessages[editando]["variantes"]
70+
71+
if "hastaElFondo" not in variantesActuales:
72+
newMessages[editando]["variantes"].append("hastaElFondo")
73+
hef = True
74+
else:
75+
newMessages[editando]["variantes"].remove("hastaElFondo")
76+
hef = False
77+
78+
if "picante" in variantesActuales:
79+
picante = True
80+
else:
81+
picante = False
82+
83+
keyboard = CB_newMessage_categorias_generarKEY(picante, hef)
84+
85+
bot.edit_message_reply_markup(chat_id=query.message.chat_id,
86+
message_id=query.message.message_id,
87+
reply_markup=InlineKeyboardMarkup(keyboard))
88+
89+
def CB_newMessage_done(bot, update, Usuarios):
90+
query = update.callback_query
91+
92+
msg = "Gracias por tu aportación, el mensaje se incluirá próximamente."
93+
94+
keyboard = [[]]
95+
96+
bot.edit_message_text(text=msg,
97+
chat_id=query.message.chat_id,
98+
message_id=query.message.message_id,
99+
reply_markup=InlineKeyboardMarkup(keyboard))
100+
101+
posUsu = Usuarios.finder(query.from_user.id)
102+
Usuarios.usuariosActivos[posUsu]["posicion"] = 0
103+
Usuarios.usuariosActivos[posUsu]["editando"] = None
104+
105+
def CB_noDisponible(bot,update,Usuarios):
106+
query = update.callback_query
107+
108+
print "Se ha pedido una función no disponible."
109+
110+
update.callback_query.message.reply_text("Esa función no está disponible todavía, cancelando.")
111+
112+
posUsu = Usuarios.finder(update.callback_query.from_user.id)
113+
114+
Usuarios.usuariosActivos[posUsu]["posicion"] = 0
115+
116+
msg = "Work in progress. Vuelve a intentarlo en la próxima acutalización. Consulta la versión con /about"
117+
118+
keyboard = [[]]
119+
120+
bot.edit_message_text(text=msg,
121+
chat_id=query.message.chat_id,
122+
message_id=query.message.message_id,
123+
reply_markup=InlineKeyboardMarkup(keyboard))

cosas/sesiones.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

cosas/sesiones.pyc

-1.12 KB
Binary file not shown.

0 commit comments

Comments
 (0)