Skip to content

Commit

Permalink
Added command to list the registered mages
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdelatorre committed Jun 21, 2024
1 parent 1cc72ab commit 864fb62
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,6 @@ Para agendar los magos:
* `/votar` envia opciones para votar (si está habilitada la votacion)
* `/ver_cronograma` te muestra el cronograma!
* `/ser_magx` te registra como mago.
* `/ver_magx` Lista los magos registrados.
* `/evocar_magx` llama al mago de turno para pedirle ayuda.
* `/ver_agenda_magx completa` te muestra la agenda de magos del PyCamp. El parámetro `completa` es opcional, si se omite solo muestra los turnos pendientes.
28 changes: 22 additions & 6 deletions src/pycamp_bot/commands/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def clean_wizards_free_slots(pycamp, slots):

def compute_wizards_slots(pycamp):
"""
* Magos trabajan de 9 a 19, sacando almuerzo (13 a 14).
* Magos trabajan desde el mediodía del primer día, hasta el mediodía del último día.
* Magxs trabajan de 9 a 19, sacando almuerzo (13 a 14).
* Magxs trabajan desde el mediodía del primer día, hasta el mediodía del último día.
Slots son [start; end)
"""
wizard_start = pycamp.init
Expand Down Expand Up @@ -84,9 +84,9 @@ def define_wizards_schedule(pycamp):
wizard = wizards_list[idx%n_wizards]
n_iter = 0 # railguard
while wizard.is_busy(slot):
logger.info('Mago {} con conflicto en el slot {}. Pruebo otro.'.format(wizard.username, slot))
logger.info('Magx {} con conflicto en el slot {}. Pruebo otro.'.format(wizard.username, slot))
if n_iter == n_wizards:
logger.warning('Queda el mago {} con conflicto en el slot {}'.format(wizard, slot))
logger.warning('Queda el magx {} con conflicto en el slot {}'.format(wizard, slot))
break
idx += 1
wizard = wizards_list[idx%n_wizards]
Expand Down Expand Up @@ -116,6 +116,20 @@ async def become_wizard(update, context):
)


async def list_wizards(update, context):
_, pycamp = get_active_pycamp()
msg = ""
for i, wizard in enumerate(pycamp.get_wizards()):
msg += "{}) @{}\n".format(i+1, wizard.username)
try:
await context.bot.send_message(
chat_id=update.message.chat_id,
text=msg
)
except BadRequest as e:
logger.exception("Coulnd't deliver the Wizards list to {}".format(update.message.from_user.username))


async def summon_wizard(update, context):
_, pycamp = get_active_pycamp()
wizard = pycamp.get_current_wizard()
Expand Down Expand Up @@ -152,7 +166,7 @@ async def notify_scheduled_slots_to_wizard(update, context, pycamp, wizard, agen
k = entry.init.strftime("%a %d de %b")
per_day[k].append(entry)

msg = "Esta es tu agenda de mago para el PyCamp {}".format(pycamp.headquarters)
msg = "Esta es tu agenda de magx para el PyCamp {}".format(pycamp.headquarters)
for day, items in per_day.items():
msg += "\nEl día _{}_:\n".format(day)
for i in items:
Expand Down Expand Up @@ -229,7 +243,7 @@ def format_wizards_schedule(agenda):
k = entry.init.strftime("%a %d de %b")
per_day[k].append(entry)

msg = "Agenda de magos:"
msg = "Agenda de magxs:"
for day, items in per_day.items():
msg += "\nEl día _{}_:\n".format(day)
for i in items:
Expand Down Expand Up @@ -288,6 +302,8 @@ def set_handlers(application):
CommandHandler('evocar_magx', summon_wizard))
application.add_handler(
CommandHandler('ser_magx', become_wizard))
application.add_handler(
CommandHandler('ver_magx', list_wizards))
application.add_handler(
CommandHandler('agendar_magx', schedule_wizards))
application.add_handler(
Expand Down

0 comments on commit 864fb62

Please sign in to comment.