Spaces:
Runtime error
Runtime error
| # utils/guards.py | |
| import functools | |
| import logging | |
| from telegram import Update | |
| from telegram.ext import ContextTypes | |
| import config | |
| logger = logging.getLogger(__name__) | |
| def is_admin(uid: int) -> bool: | |
| return uid in config.ADMIN_IDS | |
| def admin_only(func): | |
| async def wrapper(update: Update, ctx: ContextTypes.DEFAULT_TYPE): | |
| uid = update.effective_user.id if update.effective_user else 0 | |
| if not is_admin(uid): | |
| logger.warning(f"[GUARD] ุฑููุถ uid={uid} โ {func.__name__}") | |
| if update.message: | |
| await update.message.reply_text("โ ูุฐุง ุงูุฃู ุฑ ููู ุดุฑููู ููุท.") | |
| elif update.callback_query: | |
| await update.callback_query.answer("โ ูุฐุง ุงูุฃู ุฑ ููู ุดุฑููู ููุท.", show_alert=True) | |
| return | |
| return await func(update, ctx) | |
| return wrapper | |