-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy path__main__.py
67 lines (58 loc) · 2.08 KB
/
__main__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import asyncio
import aiohttp
import discord
from async_rediscache import RedisSession
from pydis_core import StartupError
from pydis_core.utils.logging import get_logger
from redis import RedisError
import bot
from bot import constants
from bot.bot import SirRobin
from bot.log import setup_sentry
log = get_logger(__name__)
setup_sentry()
async def _create_redis_session() -> RedisSession:
"""Create and connect to a redis session."""
redis_session = RedisSession(
host=constants.RedisConfig.host,
port=constants.RedisConfig.port,
password=constants.RedisConfig.password,
max_connections=20,
use_fakeredis=constants.RedisConfig.use_fakeredis,
global_namespace="sir-robin",
decode_responses=True,
)
try:
return await redis_session.connect()
except RedisError as e:
raise StartupError(e)
if not constants.Bot.in_ci:
async def main() -> None:
"""Entry Async method for starting the bot."""
# Default is all intents except for privileged ones (Members, Presences, ...)
_intents = discord.Intents.default()
_intents.bans = False
_intents.integrations = False
_intents.invites = False
_intents.typing = False
_intents.webhooks = False
_intents.message_content = True
_intents.members = True
allowed_roles = (
constants.Roles.events_lead,
constants.Roles.code_jam_event_team,
constants.Roles.code_jam_participants
)
async with aiohttp.ClientSession() as session:
bot.instance = SirRobin(
redis_session=await _create_redis_session(),
http_session=session,
guild_id=constants.Bot.guild,
allowed_roles=allowed_roles,
command_prefix=constants.Bot.prefix,
activity=discord.Game("The Not-Quite-So-Bot-as-Sir-Lancebot"),
intents=_intents,
)
async with bot.instance:
await bot.instance.start(constants.Bot.token)
asyncio.run(main())