Skip to content

Commit

Permalink
Merge pull request #70 from andresdelfino/add_show_my_projects
Browse files Browse the repository at this point in the history
Add mis_proyectos command
  • Loading branch information
WinnaZ authored Jun 21, 2024
2 parents 797e32d + 6d15095 commit cddbe57
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/pycamp_bot/commands/help_msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/pycamps: lista todos los pycamps.
/cargar_proyecto: empieza la conversacion de carga de proyecto.
/proyectos: te muestra la informacion de todos los proyectos y sus responsables.
/mis_proyectos: te muestra día y horario de los proyectos que votaste.
/ser_magx: te agrega la lista de Magx.
/evocar_magx: pingea a la/el Magx de turno, informando que necesitas su\
ayuda. Con un gran poder, viene una gran responsabilidad.
Expand Down
53 changes: 52 additions & 1 deletion src/pycamp_bot/commands/projects.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import logging
import peewee
from telegram.ext import ConversationHandler, CommandHandler, MessageHandler, filters
from pycamp_bot.models import Pycampista, Project, Vote
from pycamp_bot.models import Pycampista, Project, Slot, Vote
from pycamp_bot.commands.base import msg_to_active_pycamp_chat
from pycamp_bot.commands.manage_pycamp import active_needed, get_active_pycamp
from pycamp_bot.commands.auth import admin_needed, get_admins_username
from pycamp_bot.commands.schedule import DIAS


current_projects = {}
Expand Down Expand Up @@ -254,6 +255,53 @@ async def show_projects(update, context):
await update.message.reply_text(text)


async def show_my_projects(update, context):
"""Let people see what projects they have voted for"""

user = Pycampista.get(
Pycampista.username == update.message.from_user.username,
)
votes = (
Vote
.select(Project, Slot)
.join(Project)
.join(Slot)
.where(
(Vote.pycampista == user) &
Vote.interest
)
.order_by(Slot.code)
)

if votes:
text_chunks = []

prev_slot_day_code = None

for vote in votes:
slot_day_code = vote.project.slot.code[0]
slot_day_name = DIAS[slot_day_code]

if slot_day_code != prev_slot_day_code:
text_chunks.append(f'*{slot_day_name}*')

project_lines = [
f'{vote.project.slot.start}:00',
vote.project.name,
f'Owner: @{vote.project.owner.username}',
]

text_chunks.append('\n'.join(project_lines))

prev_slot_day_code = slot_day_code

text = '\n\n'.join(text_chunks)
else:
text = "No votaste por ningún proyecto"

await update.message.reply_text(text, parse_mode='Markdown')


def set_handlers(application):
application.add_handler(load_project_handler)
application.add_handler(
Expand All @@ -264,3 +312,6 @@ def set_handlers(application):
CommandHandler('borrar_proyecto', delete_project))
application.add_handler(
CommandHandler('proyectos', show_projects))
application.add_handler(
CommandHandler('mis_proyectos', show_my_projects))

0 comments on commit cddbe57

Please sign in to comment.