Skip to content

Commit 115a643

Browse files
committed
Implement mis_proyectos command
1 parent 797e32d commit 115a643

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

src/pycamp_bot/commands/projects.py

Lines changed: 40 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,41 @@ 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_id = Pycampista.get(Pycampista.username == update.message.from_user.username)
262+
votes = Vote.select(Project, Slot).join(Project).join(Slot).where((Vote.pycampista == user_id) & Vote.interest).order_by(Slot.code)
263+
264+
if votes:
265+
text_chunks = []
266+
267+
prev_slot_day_code = None
268+
269+
for vote in votes:
270+
slot_day_code = vote.project.slot.code[0]
271+
slot_day_name = DIAS[slot_day_code]
272+
273+
if slot_day_code != prev_slot_day_code:
274+
text_chunks.append(f'*{slot_day_name}*')
275+
276+
slot_start_time = str(vote.project.slot.start) + ':00'
277+
project_text = "{}\n{}\nOwner: @{}".format(
278+
slot_start_time,
279+
vote.project.name,
280+
vote.project.owner.username,
281+
)
282+
text_chunks.append(project_text)
283+
284+
prev_slot_day_code = slot_day_code
285+
286+
text = '\n\n'.join(text_chunks)
287+
else:
288+
text = "No votaste por ningún proyecto"
289+
290+
await update.message.reply_text(text, parse_mode='Markdown')
291+
292+
257293
def set_handlers(application):
258294
application.add_handler(load_project_handler)
259295
application.add_handler(
@@ -264,3 +300,6 @@ def set_handlers(application):
264300
CommandHandler('borrar_proyecto', delete_project))
265301
application.add_handler(
266302
CommandHandler('proyectos', show_projects))
303+
application.add_handler(
304+
CommandHandler('mis_proyectos', show_my_projects))
305+

0 commit comments

Comments
 (0)