2
0
mirror of https://github.com/Nick80835/microbot synced 2025-08-22 10:09:40 +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.loader = Loader(self)
await self.loader._initialize_loader()
client = self.client
ldr = self.loader
self.loader.load_all_modules()

View File

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