diff --git a/common.py b/common.py index e78825d..4a6ba8f 100644 --- a/common.py +++ b/common.py @@ -18,6 +18,7 @@ from types import SimpleNamespace from typing import Union import aiohttp +import httpx import discord import discord.ext.commands as commands @@ -125,12 +126,16 @@ class ImagesGroup(collections.abc.Mapping): class BotHTTPError(Exception): """Raised whan a requests fails (status != 200) in a command.""" - def __init__(self, response: aiohttp.ClientResponse): - msg = f"Request failed: {response.status} {response.reason}" + def __init__(self, response: aiohttp.ClientResponse | httpx.Response): + if isinstance(response, aiohttp.ClientResponse): + self.status = response.status + self.reason = response.reason + else: + self.status = response.status_code + self.reason = response.reason_phrase + msg = f"Request failed: {self.status} {self.reason}" super().__init__(msg) self.response = response - self.status = response.status - self.reason = response.reason # --- Converters --- diff --git a/main.py b/main.py index b2d6946..68214a5 100644 --- a/main.py +++ b/main.py @@ -16,6 +16,7 @@ from datetime import datetime, time from types import SimpleNamespace from pathlib import Path +import httpx import pytz import discord @@ -69,6 +70,8 @@ bot.qrm = SimpleNamespace() # Let's store stuff here. bot.qrm.connector = connector bot.qrm.debug_mode = debug_mode +# TODO: Add code to close the client +bot.qrm.httpx_client = httpx.AsyncClient() # --- Commands ---