11import logging
2- from time import sleep
2+ import asyncio
33from telegram import Update , InlineKeyboardButton , InlineKeyboardMarkup
44from telegram .ext import ContextTypes
55from 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+
168170async 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