Skip to content

Commit 1663c46

Browse files
committed
Print project titles in /proyectos with bold style
1 parent 21de986 commit 1663c46

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

src/pycamp_bot/commands/projects.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -452,29 +452,41 @@ async def delete_project(update, context):
452452
async def show_projects(update, context):
453453
"""Show available projects"""
454454
projects = Project.select()
455-
text = []
455+
if not projects:
456+
msg_text = "Todavía no hay ningún proyecto cargado"
457+
await update.message.reply_text(msg_text, link_preview_options=LinkPreviewOptions(is_disabled=True))
458+
459+
msg_text = ""
460+
PROJECT_FIELDS = [
461+
'*{}*',
462+
'Owner: @{}',
463+
'Temática: {}',
464+
'Nivel: {}',
465+
'Repositorio: {}',
466+
'Grupo de Telegram: {}',
467+
]
456468
for project in projects:
457-
project_text = "{}\n Owner: @{}\n Temática: {}\n Nivel: {}\n Repositorio: {}\n Grupo de Telegram: {}".format(
458-
project.name,
459-
project.owner.username,
460-
project.topic,
469+
project_text = '\n'.join(PROJECT_FIELDS).format(
470+
escape_markdown(project.name),
471+
escape_markdown(project.owner.username),
472+
escape_markdown(project.topic),
461473
DIFFICULTY_LEVEL_NAMES[project.difficult_level],
462-
project.repository_url or '(ninguno)',
463-
project.group_url or '(ninguno)',
474+
escape_markdown(project.repository_url or '(ninguno)'),
475+
escape_markdown(project.group_url or '(ninguno)'),
464476
)
465477
participants_count = Vote.select().where(
466478
(Vote.project == project) & (Vote.interest)).count()
467479
if participants_count > 0:
468-
project_text += "\n Interesades: {}".format(participants_count)
469-
text.append(project_text)
480+
project_text += "\nInteresades: {}".format(participants_count)
470481

471-
if text:
472-
text = "\n\n".join(text)
473-
else:
474-
text = "Todavía no hay ningún proyecto cargado"
482+
if len(msg_text) + len(project_text) > 4096:
483+
await update.message.reply_text(msg_text, link_preview_options=LinkPreviewOptions(is_disabled=True), parse_mode='MarkdownV2')
484+
msg_text = ""
475485

476-
await update.message.reply_text(text, link_preview_options=LinkPreviewOptions(is_disabled=True))
486+
msg_text += "\n\n" + project_text
477487

488+
if msg_text:
489+
await update.message.reply_text(msg_text, link_preview_options=LinkPreviewOptions(is_disabled=True), parse_mode='MarkdownV2')
478490

479491

480492
async def show_participants(update, context):

0 commit comments

Comments
 (0)