log = logging.getLogger('bot') bot = Bot(command_prefix=when_mentioned_or(BotConfig.prefix), activity=Game(name="Commands: !help"), case_insensitive=True, max_messages=10_000) # Global aiohttp session for all cogs # - Uses asyncio for DNS resolution instead of threads, so we don't spam threads # - Uses AF_INET as its socket family to prevent https related problems both locally and in prod. bot.http_session = ClientSession(connector=TCPConnector( resolver=AsyncResolver(), family=socket.AF_INET, )) bot.api_client = APIClient(loop=asyncio.get_event_loop()) log.addHandler(APILoggingHandler(bot.api_client)) # Internal/debug bot.load_extension("bot.cogs.error_handler") bot.load_extension("bot.cogs.filtering") bot.load_extension("bot.cogs.logging") bot.load_extension("bot.cogs.modlog") bot.load_extension("bot.cogs.security") # Commands, etc bot.load_extension("bot.cogs.antispam") bot.load_extension("bot.cogs.bot") bot.load_extension("bot.cogs.clean") bot.load_extension("bot.cogs.cogs") bot.load_extension("bot.cogs.help")
default_kwargs = { 'name': 'user', 'id': next(self.discord_id), 'bot': False } super().__init__(spec_set=user_instance, **collections.ChainMap(kwargs, default_kwargs)) if 'mention' not in kwargs: self.mention = f"@{self.name}" # Create a Bot instance to get a realistic MagicMock of `discord.ext.commands.Bot` bot_instance = Bot(command_prefix=unittest.mock.MagicMock()) bot_instance.http_session = None bot_instance.api_client = None class MockBot(CustomMockMixin, unittest.mock.MagicMock): """ A MagicMock subclass to mock Bot objects. Instances of this class will follow the specifications of `discord.ext.commands.Bot` instances. For more information, see the `MockGuild` docstring. """ def __init__(self, **kwargs) -> None: super().__init__(spec_set=bot_instance, **kwargs) # self.wait_for is *not* a coroutine function, but returns a coroutine nonetheless and # and should therefore be awaited. (The documentation calls it a coroutine as well, which # is technically incorrect, since it's a regular def.)