Skip to content

Commit cddbe57

Browse files
authored
Merge pull request #70 from andresdelfino/add_show_my_projects
Add mis_proyectos command
2 parents 797e32d + 6d15095 commit cddbe57

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

src/pycamp_bot/commands/help_msg.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/pycamps: lista todos los pycamps.
88
/cargar_proyecto: empieza la conversacion de carga de proyecto.
99
/proyectos: te muestra la informacion de todos los proyectos y sus responsables.
10+
/mis_proyectos: te muestra día y horario de los proyectos que votaste.
1011
/ser_magx: te agrega la lista de Magx.
1112
/evocar_magx: pingea a la/el Magx de turno, informando que necesitas su\
1213
ayuda. Con un gran poder, viene una gran responsabilidad.

src/pycamp_bot/commands/projects.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import logging
22
import peewee
33
from telegram.ext import ConversationHandler, CommandHandler, MessageHandler, filters
4-
from pycamp_bot.models import Pycampista, Project, Vote
4+
from pycamp_bot.models import Pycampista, Project, Slot, Vote
55
from pycamp_bot.commands.base import msg_to_active_pycamp_chat
66
from pycamp_bot.commands.manage_pycamp import active_needed, get_active_pycamp
77
from pycamp_bot.commands.auth import admin_needed, get_admins_username
8+
from pycamp_bot.commands.schedule import DIAS
89

910

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

256257

258+
async def show_my_projects(update, context):
259+
"""Let people see what projects they have voted for"""
260+
261+
user = Pycampista.get(
262+
Pycampista.username == update.message.from_user.username,
263+
)
264+
votes = (
265+
Vote
266+
.select(Project, Slot)
267+
.join(Project)
268+
.join(Slot)
269+
.where(
270+
(Vote.pycampista == user) &
271+
Vote.interest
272+
)
273+
.order_by(Slot.code)
274+
)
275+
276+
if votes:
277+
text_chunks = []
278+
279+
prev_slot_day_code = None
280+
281+
for vote in votes:
282+
slot_day_code = vote.project.slot.code[0]
283+
slot_day_name = DIAS[slot_day_code]
284+
285+
if slot_day_code != prev_slot_day_code:
286+
text_chunks.append(f'*{slot_day_name}*')
287+
288+
project_lines = [
289+
f'{vote.project.slot.start}:00',
290+
vote.project.name,
291+
f'Owner: @{vote.project.owner.username}',
292+
]
293+
294+
text_chunks.append('\n'.join(project_lines))
295+
296+
prev_slot_day_code = slot_day_code
297+
298+
text = '\n\n'.join(text_chunks)
299+
else:
300+
text = "No votaste por ningún proyecto"
301+
302+
await update.message.reply_text(text, parse_mode='Markdown')
303+
304+
257305
def set_handlers(application):
258306
application.add_handler(load_project_handler)
259307
application.add_handler(
@@ -264,3 +312,6 @@ def set_handlers(application):
264312
CommandHandler('borrar_proyecto', delete_project))
265313
application.add_handler(
266314
CommandHandler('proyectos', show_projects))
315+
application.add_handler(
316+
CommandHandler('mis_proyectos', show_my_projects))
317+

0 commit comments

Comments
 (0)