2121
2222# Local imports
2323from models import (Session , Command , Grupo , GrupoOptativa , ECI , GrupoOtros ,
24- Obligatoria , Optativa , Otro , File )
24+ Obligatoria , Optativa , Otro , File , Listable , Noticia )
2525from deletablecommandhandler import DeletableCommandHandler
2626import labos
2727import river
@@ -45,14 +45,10 @@ async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
4545
4646
4747async def help (update : Update , context : ContextTypes .DEFAULT_TYPE ):
48- message_text = ""
49- session = Session ()
50- try :
51- commands = session .query (Command ).filter (Command .description != None , Command .enabled == True ).order_by (Command .name ).all ()
52- for command in commands :
53- message_text += "/" + command .name + " - " + command .description + "\n "
54- finally :
55- session .close ()
48+ message_text = "Comandos disponibles:\n "
49+ for name , command_info in sorted (COMMANDS .items ()):
50+ if 'description' in command_info and command_info ['description' ]:
51+ message_text += f"/{ name } - { command_info ['description' ]} \n "
5652 await update .message .reply_text (message_text )
5753
5854
@@ -158,6 +154,16 @@ async def sugerireci(update: Update, context: ContextTypes.DEFAULT_TYPE):
158154async def sugerirotro (update : Update , context : ContextTypes .DEFAULT_TYPE ):
159155 await suggest_listable (update , context , Otro )
160156
157+ async def agregargrupo (update : Update , context : ContextTypes .DEFAULT_TYPE ):
158+ await update .message .reply_text (
159+ "Para sugerir un grupo, usá uno de los siguientes comandos, dependiendo de la categoría del grupo:\n "
160+ "/sugerirgrupo - Materia obligatoria\n "
161+ "/sugeriroptativa - Materia optativa\n "
162+ "/sugerireci - ECI\n "
163+ "/sugerirotro - Otra categoría\n \n "
164+ "El formato es: /comando <nombre>|<link>"
165+ )
166+
161167async def campusvivo (update : Update , context : ContextTypes .DEFAULT_TYPE ):
162168 msg = await update .message .reply_text ("Bancá que me fijo..." )
163169
@@ -281,27 +287,132 @@ async def responder_documento(update: Update, context: ContextTypes.DEFAULT_TYPE
281287 await mandar_pdf (update .message .chat_id , context , file_path )
282288
283289
290+ async def button (update : Update , context : ContextTypes .DEFAULT_TYPE ):
291+ query = update .callback_query
292+ await query .answer ()
293+ message = query .message
294+ buttonType , id , action = query .data .split ("|" )
295+
296+ session = Session ()
297+ try :
298+ if buttonType == "Listable" :
299+ group = session .query (Listable ).filter_by (id = int (id )).first ()
300+ if group :
301+ if action == "1" :
302+ group .validated = True
303+ session .commit ()
304+ action_text = "\n ¡Aceptado!"
305+ else :
306+ session .delete (group )
307+ session .commit ()
308+ action_text = "\n ¡Rechazado!"
309+ await query .edit_message_text (text = message .text + action_text )
310+
311+ elif buttonType == "Noticia" :
312+ noticia = session .query (Noticia ).filter_by (id = int (id )).first ()
313+ if noticia :
314+ if action == "1" :
315+ noticia .validated = True
316+ session .commit ()
317+ action_text = "\n ¡Aceptado!"
318+ await context .bot .send_message (chat_id = NOTICIAS_CHATID ,
319+ text = noticia .text , parse_mode = ParseMode .MARKDOWN )
320+ else :
321+ session .delete (noticia )
322+ session .commit ()
323+ action_text = "\n ¡Rechazado!"
324+ await query .edit_message_text (text = message .text + action_text )
325+ finally :
326+ session .close ()
327+
328+
284329COMMANDS = {
285- 'start' : start ,
286- 'help' : help ,
287- 'estasvivo' : estasvivo ,
288- 'listar' : listar ,
289- 'listaroptativa' : listaroptativa ,
290- 'listareci' : listareci ,
291- 'listarotro' : listarotro ,
292- 'cubawiki' : cubawiki ,
293- 'sugerirgrupo' : sugerirgrupo ,
294- 'sugeriroptativa' : sugeriroptativa ,
295- 'sugerireci' : sugerireci ,
296- 'sugerirotro' : sugerirotro ,
297- 'campusvivo' : campusvivo ,
298- 'noitip' : noitip ,
299- 'asm' : asm ,
300- 'flan' : flan ,
301- 'flanviejo' : flanviejo ,
302- # 'aulas': aulas, lo comente por q se me rompio mandar pdf y no se por q
303- 'checodepers' : checodepers ,
304- 'checodeppers' : checodeppers ,
305- 'cuandovence' : cuandovence ,
306- 'colaborar' : colaborar ,
330+ 'start' : {
331+ 'handler' : start ,
332+ 'description' : 'Inicia el bot.'
333+ },
334+ 'help' : {
335+ 'handler' : help ,
336+ 'description' : 'Muestra este mensaje de ayuda.'
337+ },
338+ 'estasvivo' : {
339+ 'handler' : estasvivo ,
340+ 'description' : 'Responde si el bot está funcionando.'
341+ },
342+ 'listar' : {
343+ 'handler' : listar ,
344+ 'description' : 'Muestra los grupos de Telegram de materias obligatorias.'
345+ },
346+ 'listaroptativa' : {
347+ 'handler' : listaroptativa ,
348+ 'description' : 'Muestra los grupos de Telegram de materias optativas.'
349+ },
350+ 'listareci' : {
351+ 'handler' : listareci ,
352+ 'description' : 'Muestra los grupos de Telegram de las ECI.'
353+ },
354+ 'listarotro' : {
355+ 'handler' : listarotro ,
356+ 'description' : 'Muestra otros grupos de Telegram.'
357+ },
358+ 'cubawiki' : {
359+ 'handler' : cubawiki ,
360+ 'description' : 'Devuelve el link a la Cubawiki de la materia (si estás en el grupo de la materia).'
361+ },
362+ 'sugerirgrupo' : {
363+ 'handler' : sugerirgrupo ,
364+ 'description' : 'Sugiere un grupo de una materia obligatoria.'
365+ },
366+ 'sugeriroptativa' : {
367+ 'handler' : sugeriroptativa ,
368+ 'description' : 'Sugiere un grupo de una materia optativa.'
369+ },
370+ 'sugerireci' : {
371+ 'handler' : sugerireci ,
372+ 'description' : 'Sugiere un grupo de una ECI.'
373+ },
374+ 'sugerirotro' : {
375+ 'handler' : sugerirotro ,
376+ 'description' : 'Sugiere un grupo de otra categoría.'
377+ },
378+ 'campusvivo' : {
379+ 'handler' : campusvivo ,
380+ 'description' : 'Verifica si el Campus Virtual está funcionando.'
381+ },
382+ 'noitip' : {
383+ 'handler' : noitip ,
384+ 'description' : "Explica el meme 'No, it IP'."
385+ },
386+ 'asm' : {
387+ 'handler' : asm ,
388+ 'description' : 'Explica el meme de Assembly.'
389+ },
390+ 'flan' : {
391+ 'handler' : flan ,
392+ 'description' : 'Muestra el plan de estudios de la carrera.'
393+ },
394+ 'flanviejo' : {
395+ 'handler' : flanviejo ,
396+ 'description' : 'Muestra el plan de estudios viejo de la carrera.'
397+ },
398+ # 'aulas': {
399+ # 'handler': aulas,
400+ # 'description': 'Muestra el mapa de las aulas.'
401+ # },
402+ 'checodepers' : {
403+ 'handler' : checodepers ,
404+ 'description' : 'Envía un mensaje a les codepers.'
405+ },
406+ 'checodeppers' : {
407+ 'handler' : checodeppers ,
408+ 'description' : 'Alias para /checodepers.'
409+ },
410+ 'cuandovence' : {
411+ 'handler' : cuandovence ,
412+ 'description' : 'Calcula cuándo vence la validez de los TPs de una materia.'
413+ },
414+ 'colaborar' : {
415+ 'handler' : colaborar ,
416+ 'description' : 'Muestra el link al repositorio de Github del bot.'
417+ },
307418}
0 commit comments