Merge da1d762c51 into c53c3cd195
This commit is contained in:
commit
6a451729ce
|
|
@ -44,4 +44,8 @@ class ServerConfig:
|
||||||
### Telegram bot
|
### Telegram bot
|
||||||
telegram_bot_token = os.getenv("telegram_bot_token") or "123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
telegram_bot_token = os.getenv("telegram_bot_token") or "123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
telegram_bot_enabled = bool(os.getenv("telegram_bot_enabled")) or True
|
telegram_bot_enabled = bool(os.getenv("telegram_bot_enabled")) or True
|
||||||
telegram_whitelist_ids = [x.strip() for x in os.getenv("telegram_whitelist_ids", "").split(",") if x.strip()]
|
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"
|
REGISTRATION_SUCCESS = "registration_success"
|
||||||
ACCOUNT_ALREADY_EXISTS = "account_already_exists"
|
ACCOUNT_ALREADY_EXISTS = "account_already_exists"
|
||||||
ID_NOT_WHITELISTED = "id_not_whitelisted"
|
ID_NOT_WHITELISTED = "id_not_whitelisted"
|
||||||
|
ID_BLACKLISTED = "id_blacklisted"
|
||||||
INTERNAL_ERROR = "internal_error"
|
INTERNAL_ERROR = "internal_error"
|
||||||
INCOMING_CODE = "incoming_code"
|
INCOMING_CODE = "incoming_code"
|
||||||
|
|
||||||
|
|
@ -104,6 +105,9 @@ class Static:
|
||||||
"id_not_whitelisted": """
|
"id_not_whitelisted": """
|
||||||
❌ Ваш ID не находится в белом списке.
|
❌ Ваш ID не находится в белом списке.
|
||||||
""",
|
""",
|
||||||
|
"id_blacklisted": """
|
||||||
|
❌ Ваш ID заблокирован.
|
||||||
|
""",
|
||||||
"internal_error": """
|
"internal_error": """
|
||||||
❌ Ошибка при регистрации аккаунта.
|
❌ Ошибка при регистрации аккаунта.
|
||||||
""",
|
""",
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ class TelegramBot:
|
||||||
self.enabled = enabled
|
self.enabled = enabled
|
||||||
self.db_pool = db_pool
|
self.db_pool = db_pool
|
||||||
self.whitelist_ids = whitelist_ids if whitelist_ids is not None else []
|
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.logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
self.msg_types = Static().BotMessageTypes()
|
self.msg_types = Static().BotMessageTypes()
|
||||||
|
|
@ -46,11 +47,16 @@ class TelegramBot:
|
||||||
async def handle_register(message):
|
async def handle_register(message):
|
||||||
tg_id = str(message.from_user.id)
|
tg_id = str(message.from_user.id)
|
||||||
|
|
||||||
# Проверка ID на наличие в белом списке
|
# Проверка ID на наличие в белом списке и в чёрном списке
|
||||||
if tg_id not in self.whitelist_ids:
|
if whitelist_enabled:
|
||||||
await self.bot.send_message(message.chat.id, self.get_bot_message(self.msg_types.ID_NOT_WHITELISTED))
|
if tg_id not in self.whitelist_ids:
|
||||||
return
|
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 self.db_pool.acquire() as conn:
|
||||||
async with conn.cursor() as cursor:
|
async with conn.cursor() as cursor:
|
||||||
# Проверка на существование
|
# Проверка на существование
|
||||||
|
|
@ -127,4 +133,4 @@ class TelegramBot:
|
||||||
chat_id, self.get_bot_message(self.msg_types.INCOMING_CODE).format(phone=phone, code=code)
|
chat_id, self.get_bot_message(self.msg_types.INCOMING_CODE).format(phone=phone, code=code)
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(f"Ошибка отправки кода в Telegram: {e}")
|
self.logger.error(f"Ошибка отправки кода в Telegram: {e}")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue