This commit is contained in:
mihalin 2021-09-10 01:30:17 +03:00
parent 289b40b532
commit 1205eece56
2 changed files with 11 additions and 3 deletions

View File

@ -15,6 +15,11 @@ from server.server import register_token
from olgram.router import dp
import logging
logger = logging.getLogger(__name__)
token_pattern = r'[0-9]{8,10}:[a-zA-Z0-9_-]{35}'
@ -95,9 +100,6 @@ async def bot_added(message: types.Message, state: FSMContext):
except TelegramAPIError:
return await on_unknown_error()
if not register_token(token):
return await on_unknown_error()
user, _ = await User.get_or_create(telegram_id=message.from_user.id)
bot = Bot(token=token, owner=user, name=test_bot_info.username, super_chat_id=message.from_user.id)
try:
@ -105,5 +107,9 @@ async def bot_added(message: types.Message, state: FSMContext):
except IntegrityError:
return await on_duplication_bot()
if not register_token(bot):
await bot.delete()
return await on_unknown_error()
await message.answer("Бот добавлен! Список ваших ботов: /mybots")
await state.reset_state()

View File

@ -28,6 +28,7 @@ async def register_token(bot: Bot) -> bool:
logger.info(f"register token {bot.name}")
a_bot = AioBot(bot.token)
res = await a_bot.set_webhook(url_for_bot(bot))
await a_bot.session.close()
del a_bot
return res
@ -41,6 +42,7 @@ async def unregister_token(token: str):
logger.info(f"unregister token {token}")
bot = AioBot(token)
await bot.delete_webhook()
await bot.session.close()
del bot