diff options
Diffstat (limited to 'bot/bot.py')
-rw-r--r-- | bot/bot.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/bot/bot.py b/bot/bot.py new file mode 100644 index 00000000..24d099ad --- /dev/null +++ b/bot/bot.py @@ -0,0 +1,42 @@ +import logging +import socket +from traceback import format_exc +from typing import List + +from aiohttp import AsyncResolver, ClientSession, TCPConnector +from discord.ext.commands import Bot + +log = logging.getLogger(__name__) + +__all__ = ('SeasonalBot',) + + +class SeasonalBot(Bot): + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.http_session = ClientSession( + connector=TCPConnector( + resolver=AsyncResolver(), + family=socket.AF_INET, + ) + ) + + def load_extensions(self, exts: List[str]): + """ + Unload all current cogs, then load in the ones passed into `cogs` + """ + + # Unload all cogs + extensions = list(self.extensions.keys()) + for extension in extensions: + if extension != "bot.seasons": # We shouldn't unload the manager. + self.unload_extension(extension) + + # Load in the list of cogs that was passed in here + for extension in exts: + cog = extension.split(".")[-1] + try: + self.load_extension(extension) + log.info(f'Successfully loaded extension: {cog}') + except Exception as e: + log.error(f'Failed to load extension {cog}: {repr(e)} {format_exc()}') |