Files
Telegram-Downloader-Bot/telegram_downloader_bot/security.py
Roman Krček c68d3d8722
All checks were successful
Build Docker image / test (push) Successful in 2m29s
Build Docker image / build (push) Successful in 49s
Fix datetime in unittests
2024-10-13 19:13:12 +02:00

24 lines
776 B
Python

import os
from functools import wraps
from telegram_downloader_bot.logger import log
# Comma separated list of Telegram IDs that this bot will respond to
allowed_ids_raw = os.getenv("ALLOWED_IDS", "")
allowed_ids = allowed_ids_raw.split(",")
allowed_ids = [int(x) for x in allowed_ids]
def protected(func):
@wraps(func)
async def wrapper(client, message):
if int(message.from_user.id) not in allowed_ids:
log.warning(
f"User with ID {message.from_user.id} attempted"
"to text this bot!")
log.info(
f"Only users allowed are: {' '.join(allowed_ids)}")
return await message.reply_text("You are not on the list!")
return await func(client, message)
return wrapper