From 4063f9f336dd9937c5049bbbcd104790622c114f Mon Sep 17 00:00:00 2001 From: mihalin Date: Fri, 24 Jun 2022 23:33:01 +0300 Subject: [PATCH] don't accept bot own token (for self-hosted projects) --- olgram/commands/bots.py | 5 ++++- olgram/settings.py | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/olgram/commands/bots.py b/olgram/commands/bots.py index adfe9f0..a362834 100644 --- a/olgram/commands/bots.py +++ b/olgram/commands/bots.py @@ -9,7 +9,7 @@ import re from textwrap import dedent from olgram.models.models import Bot, User -from olgram.settings import OlgramSettings +from olgram.settings import OlgramSettings, BotSettings from olgram.commands.menu import send_bots_menu from server.server import register_token from locales.locale import _ @@ -104,6 +104,9 @@ async def bot_added(message: types.Message, state: FSMContext): except TelegramAPIError: return await on_unknown_error() + if token == BotSettings.token(): + return await on_duplication_bot() + user, created = await User.get_or_create(telegram_id=message.from_user.id) bot = Bot(token=Bot.encrypted_token(token), owner=user, name=test_bot_info.username, super_chat_id=message.from_user.id) diff --git a/olgram/settings.py b/olgram/settings.py index 074adf5..ec06ee4 100644 --- a/olgram/settings.py +++ b/olgram/settings.py @@ -110,6 +110,7 @@ logging.basicConfig(level=os.environ.get("LOGLEVEL", "WARNING")) class BotSettings(AbstractSettings): @classmethod + @lru_cache def token(cls) -> str: """ Токен olgram бота