mirror of
https://github.com/djimboy/djimbo_template_aio3.git
synced 2026-07-25 09:44:29 +00:00
Update main.py
This commit is contained in:
@@ -5,6 +5,7 @@ import sys
|
|||||||
|
|
||||||
import colorama
|
import colorama
|
||||||
from aiogram import Bot, Dispatcher
|
from aiogram import Bot, Dispatcher
|
||||||
|
from aiogram.client.default import DefaultBotProperties
|
||||||
|
|
||||||
from tgbot.data.config import BOT_TOKEN, BOT_SCHEDULER, get_admins
|
from tgbot.data.config import BOT_TOKEN, BOT_SCHEDULER, get_admins
|
||||||
from tgbot.database.db_helper import create_dbx
|
from tgbot.database.db_helper import create_dbx
|
||||||
@@ -28,15 +29,20 @@ async def main():
|
|||||||
BOT_SCHEDULER.start() # Запуск Шедулера
|
BOT_SCHEDULER.start() # Запуск Шедулера
|
||||||
dp = Dispatcher() # Образ Диспетчера
|
dp = Dispatcher() # Образ Диспетчера
|
||||||
arSession = AsyncRequestSession() # Пул асинхронной сессии запросов
|
arSession = AsyncRequestSession() # Пул асинхронной сессии запросов
|
||||||
bot = Bot(token=BOT_TOKEN, parse_mode="HTML") # Образ Бота
|
bot = Bot( # Образ Бота
|
||||||
|
token=BOT_TOKEN,
|
||||||
|
default=DefaultBotProperties(
|
||||||
|
parse_mode="HTML",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
register_all_middlwares(dp) # Регистрация всех мидлварей
|
register_all_middlwares(dp) # Регистрация всех мидлварей
|
||||||
register_all_routers(dp) # Регистрация всех роутеров
|
register_all_routers(dp) # Регистрация всех роутеров
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await set_commands(bot)
|
await set_commands(bot) # Установка команд
|
||||||
await startup_notify(bot)
|
await startup_notify(bot) # Уведомления админам при запуске бота
|
||||||
await scheduler_start(bot)
|
await scheduler_start(bot) # Подключение шедулеров
|
||||||
|
|
||||||
bot_logger.warning("BOT WAS STARTED")
|
bot_logger.warning("BOT WAS STARTED")
|
||||||
print(colorama.Fore.LIGHTYELLOW_EX + f"~~~~~ Bot was started - @{(await bot.get_me()).username} ~~~~~")
|
print(colorama.Fore.LIGHTYELLOW_EX + f"~~~~~ Bot was started - @{(await bot.get_me()).username} ~~~~~")
|
||||||
@@ -45,8 +51,8 @@ async def main():
|
|||||||
|
|
||||||
if len(get_admins()) == 0: print("***** ENTER ADMIN ID IN settings.ini *****")
|
if len(get_admins()) == 0: print("***** ENTER ADMIN ID IN settings.ini *****")
|
||||||
|
|
||||||
await bot.delete_webhook()
|
await bot.delete_webhook() # Удаление вебхуков, если они имеются
|
||||||
await bot.get_updates(offset=-1)
|
await bot.get_updates(offset=-1) # Сброс пендинг апдейтов
|
||||||
|
|
||||||
await dp.start_polling(
|
await dp.start_polling(
|
||||||
bot,
|
bot,
|
||||||
@@ -62,10 +68,6 @@ if __name__ == "__main__":
|
|||||||
create_dbx()
|
create_dbx()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Исправление "RuntimeError: Event loop is closed" для Windows
|
|
||||||
# if sys.version_info[0] == 3 and sys.version_info[1] >= 8 and sys.platform.startswith("win"):
|
|
||||||
# asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
|
||||||
|
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
except (KeyboardInterrupt, SystemExit):
|
except (KeyboardInterrupt, SystemExit):
|
||||||
bot_logger.warning("Bot was stopped")
|
bot_logger.warning("Bot was stopped")
|
||||||
|
|||||||
Reference in New Issue
Block a user