mirror of
https://github.com/civsocit/olgram.git
synced 2023-07-22 01:29:12 +03:00
test
This commit is contained in:
parent
289b40b532
commit
1205eece56
@ -15,6 +15,11 @@ from server.server import register_token
|
|||||||
|
|
||||||
from olgram.router import dp
|
from olgram.router import dp
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
token_pattern = r'[0-9]{8,10}:[a-zA-Z0-9_-]{35}'
|
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:
|
except TelegramAPIError:
|
||||||
return await on_unknown_error()
|
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)
|
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)
|
bot = Bot(token=token, owner=user, name=test_bot_info.username, super_chat_id=message.from_user.id)
|
||||||
try:
|
try:
|
||||||
@ -105,5 +107,9 @@ async def bot_added(message: types.Message, state: FSMContext):
|
|||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
return await on_duplication_bot()
|
return await on_duplication_bot()
|
||||||
|
|
||||||
|
if not register_token(bot):
|
||||||
|
await bot.delete()
|
||||||
|
return await on_unknown_error()
|
||||||
|
|
||||||
await message.answer("Бот добавлен! Список ваших ботов: /mybots")
|
await message.answer("Бот добавлен! Список ваших ботов: /mybots")
|
||||||
await state.reset_state()
|
await state.reset_state()
|
||||||
|
@ -28,6 +28,7 @@ async def register_token(bot: Bot) -> bool:
|
|||||||
logger.info(f"register token {bot.name}")
|
logger.info(f"register token {bot.name}")
|
||||||
a_bot = AioBot(bot.token)
|
a_bot = AioBot(bot.token)
|
||||||
res = await a_bot.set_webhook(url_for_bot(bot))
|
res = await a_bot.set_webhook(url_for_bot(bot))
|
||||||
|
await a_bot.session.close()
|
||||||
del a_bot
|
del a_bot
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@ -41,6 +42,7 @@ async def unregister_token(token: str):
|
|||||||
logger.info(f"unregister token {token}")
|
logger.info(f"unregister token {token}")
|
||||||
bot = AioBot(token)
|
bot = AioBot(token)
|
||||||
await bot.delete_webhook()
|
await bot.delete_webhook()
|
||||||
|
await bot.session.close()
|
||||||
del bot
|
del bot
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user