From 6867b64a187203fef89997ecbdbdd4e54bed9614 Mon Sep 17 00:00:00 2001 From: profitroll Date: Sat, 10 Aug 2024 14:10:59 +0200 Subject: [PATCH] Should resolve #87 --- classes/pyroclient.py | 2 +- classes/updater.py | 12 +++++++++--- main.py | 4 +++- requirements.txt | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/classes/pyroclient.py b/classes/pyroclient.py index 118654a..8e49bf2 100644 --- a/classes/pyroclient.py +++ b/classes/pyroclient.py @@ -23,7 +23,7 @@ class PyroClient(LibPyroClient): super().__init__(**kwargs) - self.updater = Updater(ClientSession()) + self.updater = Updater() self.contexts = [] if self.scheduler is not None: diff --git a/classes/updater.py b/classes/updater.py index 0f06c59..d1a2930 100644 --- a/classes/updater.py +++ b/classes/updater.py @@ -1,5 +1,5 @@ import logging -from typing import Any, Dict, Tuple +from typing import Any, Dict, Tuple, Union from aiohttp import ClientSession @@ -7,12 +7,15 @@ logger = logging.getLogger(__name__) class Updater: - def __init__(self, client_session: ClientSession) -> None: - self.client_session: ClientSession = client_session + def __init__(self, client_session: Union[ClientSession, None] = None) -> None: + self.client_session: Union[ClientSession, None] = client_session async def check_updates( self, version_current: Tuple[int, int, int], api_url: str ) -> bool: + if not self.client_session: + self.client_session = ClientSession() + response = await self.client_session.get(api_url) if response.status != 200: @@ -30,6 +33,9 @@ class Updater: ) async def get_latest_release(self, api_url: str) -> Dict[str, Any]: + if not self.client_session: + self.client_session = ClientSession() + response = await self.client_session.get(api_url) if response.status != 200: diff --git a/main.py b/main.py index 2cb0e19..7818ff9 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,7 @@ from argparse import ArgumentParser from os import getpid from pathlib import Path +from aiohttp import ClientSession from convopyro import Conversation from libbot import sync @@ -41,7 +42,8 @@ def main(): exit() client = PyroClient( - scheduler=scheduler, commands_source=sync.json_read(Path("commands.json")) + scheduler=scheduler, + commands_source=sync.json_read(Path("commands.json")), ) Conversation(client) diff --git a/requirements.txt b/requirements.txt index 67d360f..828d0c6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -aiohttp~=3.9.5 +aiohttp~=3.10.2 apscheduler~=3.10.4 async_pymongo==0.1.6 convopyro==0.5