This commit is contained in:
Anatoliy Esherkin 2026-03-23 09:41:50 +03:00 committed by GitHub
commit d7a037ff7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 7 deletions

View File

@ -44,4 +44,8 @@ class ServerConfig:
### Telegram bot
telegram_bot_token = os.getenv("telegram_bot_token") or "123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ"
telegram_bot_enabled = bool(os.getenv("telegram_bot_enabled")) or True
telegram_whitelist_enabled = bool(os.getenv("telegram_whitelist_enabled")) or False
telegram_blacklist_enabled = bool(os.getenv("telegram_blacklist_enabled")) or False
telegram_whitelist_ids = [x.strip() for x in os.getenv("telegram_whitelist_ids", "").split(",") if x.strip()]
telegram_blacklist_ids = [x.strip() for x in os.getenv("telegram_blacklist_ids", "").split(",") if x.strip()]

View File

@ -23,6 +23,7 @@ class Static:
REGISTRATION_SUCCESS = "registration_success"
ACCOUNT_ALREADY_EXISTS = "account_already_exists"
ID_NOT_WHITELISTED = "id_not_whitelisted"
ID_BLACKLISTED = "id_blacklisted"
INTERNAL_ERROR = "internal_error"
INCOMING_CODE = "incoming_code"
@ -104,6 +105,9 @@ class Static:
"id_not_whitelisted": """
Ваш ID не находится в белом списке.
""",
"id_blacklisted": """
Ваш ID заблокирован.
""",
"internal_error": """
Ошибка при регистрации аккаунта.
""",

View File

@ -13,6 +13,7 @@ class TelegramBot:
self.enabled = enabled
self.db_pool = db_pool
self.whitelist_ids = whitelist_ids if whitelist_ids is not None else []
self.blacklist_ids = blacklist_ids if blacklist_ids is not None else []
self.logger = logging.getLogger(__name__)
self.msg_types = Static().BotMessageTypes()
@ -46,10 +47,15 @@ class TelegramBot:
async def handle_register(message):
tg_id = str(message.from_user.id)
# Проверка ID на наличие в белом списке
if tg_id not in self.whitelist_ids:
await self.bot.send_message(message.chat.id, self.get_bot_message(self.msg_types.ID_NOT_WHITELISTED))
return
# Проверка ID на наличие в белом списке и в чёрном списке
if whitelist_enabled:
if tg_id not in self.whitelist_ids:
await self.bot.send_message(message.chat.id, self.get_bot_message(self.msg_types.ID_NOT_WHITELISTED))
return
elif blacklist_enabled:
if tg_id in self.blacklist_ids:
await self.bot.send_message(message.chat.id, self.get_bot_message(self.msg_types.ID_BLACKLISTED))
return
async with self.db_pool.acquire() as conn:
async with conn.cursor() as cursor: