Example #1
0
def _create_redis_session(loop: asyncio.AbstractEventLoop) -> RedisSession:
    """
    Create and connect to a redis session.

    Ensure the connection is established before returning to prevent race conditions.
    `loop` is the event loop on which to connect. The Bot should use this same event loop.
    """
    redis_session = RedisSession(
        address=(constants.Redis.host, constants.Redis.port),
        password=constants.Redis.password,
        minsize=1,
        maxsize=20,
        use_fakeredis=constants.Redis.use_fakeredis,
        global_namespace="bot",
    )
    loop.run_until_complete(redis_session.connect())
    return redis_session
Example #2
0

_allowed_roles = [discord.Object(id_) for id_ in constants.MODERATION_ROLES]

_intents = discord.Intents.default(
)  # Default is all intents except for privileged ones (Members, Presences, ...)
_intents.bans = False
_intents.integrations = False
_intents.invites = False
_intents.typing = False
_intents.webhooks = False

redis_session = RedisSession(address=(constants.RedisConfig.host,
                                      constants.RedisConfig.port),
                             password=constants.RedisConfig.password,
                             minsize=1,
                             maxsize=20,
                             use_fakeredis=constants.RedisConfig.use_fakeredis,
                             global_namespace="sir-lancebot")
loop = asyncio.get_event_loop()
loop.run_until_complete(redis_session.connect())

bot = Bot(
    redis_session=redis_session,
    command_prefix=constants.Client.prefix,
    activity=discord.Game(name=f"Commands: {constants.Client.prefix}help"),
    allowed_mentions=discord.AllowedMentions(everyone=False,
                                             roles=_allowed_roles),
    intents=_intents,
)
Example #3
0
def setUpModule():  # noqa: N802
    """Create and connect to the fakeredis session."""
    global redis_session
    redis_session = RedisSession(use_fakeredis=True)
    redis_loop.run_until_complete(redis_session.connect())
Example #4
0
 async def asyncSetUp(self):  # noqa: N802
     self.session = RedisSession(use_fakeredis=True)
     await self.session.connect()
     await self.flush()