|
1 | 1 | import logging |
2 | | -import os |
3 | | - |
4 | 2 | from telegram.ext import CommandHandler |
5 | 3 | from pycamp_bot.models import Project, Pycampista, Vote |
6 | 4 | from pycamp_bot.commands.auth import get_admins_username |
7 | 5 |
|
8 | 6 |
|
9 | 7 | logger = logging.getLogger(__name__) |
| 8 | + |
| 9 | + |
10 | 10 | def announce(bot, update): |
11 | 11 | username = update.message.from_user.username |
12 | 12 | admins = get_admins_username() |
13 | 13 | project_name = update.message.text.split()[1:] |
14 | | - |
15 | | - project_name = " ".join(project_name) |
16 | | - project = Project.select().where(Project.name ==project_name) |
17 | 14 |
|
| 15 | + project_name = " ".join(project_name) |
| 16 | + project = Project.select().where(Project.name == project_name) |
18 | 17 |
|
19 | 18 | if len(project) <= 0: |
20 | 19 | bot.send_message( |
21 | | - chat_id=update.message.chat_id, |
22 | | - text=f"El proyecto '{project_name}' no existe o esta mal escroto.\n" |
| 20 | + chat_id=update.message.chat_id, |
| 21 | + text=f"El proyecto '{project_name}' no existe o esta mal escroto.\n" |
23 | 22 | "El formato de este comando es:\n" |
24 | 23 | "/anunciar NOMBRE_DEL_PROYECTO" |
25 | 24 | ) |
26 | 25 | return |
27 | 26 |
|
28 | 27 | if not (project.get().owner.username == username or username in admins): |
29 | 28 | bot.send_message( |
30 | | - chat_id=update.message.chat_id, |
31 | | - text=f"No sos ni admin ni el owner de este proyecto, Careta." |
32 | | - ) |
| 29 | + chat_id=update.message.chat_id, |
| 30 | + text="No sos ni admin ni el owner de este proyecto, Careta." |
| 31 | + ) |
33 | 32 | return |
34 | 33 |
|
35 | | - |
36 | 34 | pycampistas = Vote.select().join(Pycampista).where((Vote.project == project) & (Vote.interest)) |
37 | 35 |
|
38 | 36 | chat_id_list = [user.pycampista.chat_id for user in pycampistas] |
39 | | - |
| 37 | + |
40 | 38 | for chat_id in chat_id_list: |
41 | 39 | bot.send_message( |
42 | 40 | chat_id=chat_id, |
43 | 41 | text=f"Esta por empezar {project_name} a cargo de @{project.get().owner.username}." |
44 | 42 | ) |
45 | 43 | bot.send_message( |
46 | 44 | chat_id=update.message.chat_id, |
47 | | - text=f"Anunciado!" |
| 45 | + text="Anunciado!" |
48 | 46 | ) |
49 | 47 |
|
| 48 | + |
50 | 49 | def set_handlers(updater): |
51 | 50 | updater.dispatcher.add_handler(CommandHandler('anunciar', announce)) |
52 | | - |
0 commit comments