Skip to content

Commit 4de8ee7

Browse files
committed
fix: use asyncio.sleep instead of time.sleep and restrict manual update to admins
1 parent 430f730 commit 4de8ee7

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

handlers/groups.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import logging
2-
from time import sleep
2+
import asyncio
33
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
44
from telegram.ext import ContextTypes
55
from models import Grupo, GrupoOptativa, ECI, GrupoOtros, Obligatoria, Listable
@@ -148,7 +148,7 @@ async def _update_groups(context: ContextTypes.DEFAULT_TYPE):
148148
logger.info(f"Found {len(chats)} groups to update")
149149

150150
for chat_db_id, chat_chat_id, chat_name in chats:
151-
sleep(1)
151+
await asyncio.sleep(1)
152152
chat_id, url, validated = await update_group_url(context, chat_chat_id)
153153
if not validated:
154154
logger.warning(f"Failed to update URL for group '{chat_name}'. De-validating.")
@@ -165,8 +165,15 @@ async def _update_groups(context: ContextTypes.DEFAULT_TYPE):
165165
c.url = url
166166
logger.info("Finished update_groups job")
167167

168+
from handlers.admin import admin_ids
169+
168170
async def actualizar_grupos(update: Update, context: ContextTypes.DEFAULT_TYPE):
169-
logger.info(f"Manual update of groups triggered by {update.effective_user.id}")
170-
await update.message.reply_text("Actualizando grupos...")
171+
user_id = update.effective_user.id
172+
if user_id not in admin_ids and str(user_id) not in admin_ids:
173+
logger.warning(f"Unauthorized user {user_id} tried to access /actualizar_grupos")
174+
return
175+
176+
logger.info(f"Manual update of groups triggered by {user_id}")
177+
await update.message.reply_text("Actualizando grupos (esto puede demorar varios minutos)...")
171178
await _update_groups(context)
172179
await update.message.reply_text("¡Grupos actualizados!")

0 commit comments

Comments
 (0)