Merge da1d762c51 into c53c3cd195
This commit is contained in:
commit
6a451729ce
|
|
@ -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()]
|
||||
|
|
|
|||
|
|
@ -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": """
|
||||
❌ Ошибка при регистрации аккаунта.
|
||||
""",
|
||||
|
|
|
|||
|
|
@ -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 на наличие в белом списке
|
||||
# Проверка 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:
|
||||
|
|
|
|||
Loading…
Reference in New Issue