2
0
mirror of https://github.com/Nick80835/microbot synced 2025-08-22 18:19:16 +00:00

initialize aiohttp from coroutine

This commit is contained in:
Nick80835 2024-08-02 19:38:55 -04:00
parent d0187b585b
commit f1882912d1
2 changed files with 20 additions and 4 deletions

View File

@ -57,6 +57,7 @@ class MicroBot():
self.me = await self.client.get_me() self.me = await self.client.get_me()
self.loader = Loader(self) self.loader = Loader(self)
await self.loader._initialize_loader()
client = self.client client = self.client
ldr = self.loader ldr = self.loader
self.loader.load_all_modules() self.loader.load_all_modules()

View File

@ -2,23 +2,34 @@ import glob
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from functools import partial from functools import partial
from importlib import import_module, reload from importlib import import_module, reload
from logging import Logger
from os.path import basename, dirname, isfile from os.path import basename, dirname, isfile
from traceback import print_exc from traceback import print_exc
from typing import TYPE_CHECKING
from aiohttp import ClientSession from aiohttp import ClientSession
from ubot.settings import Settings
from .cache import Cache from .cache import Cache
from .command import (CallbackQueryCommand, Command, InlineArticleCommand, from .command import (CallbackQueryCommand, Command, InlineArticleCommand,
InlinePhotoCommand) InlinePhotoCommand)
from .command_handler import CommandHandler from .command_handler import CommandHandler
from .database import Database from .database import Database
if TYPE_CHECKING:
from ubot import MicroBot
class Loader(): class Loader():
aioclient = ClientSession() thread_pool: ThreadPoolExecutor = ThreadPoolExecutor()
thread_pool = ThreadPoolExecutor() db: Database = Database()
cache = Cache(aioclient) micro_bot: "MicroBot"
db = Database() settings: Settings
logger: Logger
command_handler: CommandHandler
aioclient: ClientSession
cache: Cache
loaded_modules = [] loaded_modules = []
all_modules = [] all_modules = []
@ -27,6 +38,10 @@ class Loader():
self.micro_bot = micro_bot self.micro_bot = micro_bot
self.settings = micro_bot.settings self.settings = micro_bot.settings
self.logger = micro_bot.logger self.logger = micro_bot.logger
async def _initialize_loader(self):
self.aioclient = ClientSession()
self.cache = Cache(self.aioclient)
self.command_handler = CommandHandler(self) self.command_handler = CommandHandler(self)
def load_all_modules(self): def load_all_modules(self):