-
Notifications
You must be signed in to change notification settings - Fork 6
/
start.py
48 lines (40 loc) · 1.21 KB
/
start.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
"""
start.py
Entrypoint for the bot.
"""
from __future__ import annotations
import asyncio
import logging
import sys
from src.bot import Bot
logger = logging.getLogger(__name__)
if __name__ == "__main__":
bot = Bot()
async def main() -> None:
"""
The main runner for the bot.
"""
async with bot:
await bot.load_extension("cogs.scheduler")
await bot.load_extension("cogs.general")
logger.info("[green]Starting bot.[/green]", extra={"markup": True})
await bot.start()
try:
try:
import uvloop
except ModuleNotFoundError:
logger.info("uvloop not installed.")
asyncio.run(main())
else:
# Start event loop
if sys.version_info >= (3, 11):
# noinspection PyUnresolvedReferences
with asyncio.Runner(loop_factory=uvloop.new_event_loop) as runner:
runner.run(main())
else:
uvloop.install()
asyncio.run(main())
del uvloop # remove local variable
except KeyboardInterrupt:
pass
logger.info("[red]Bot has stopped.[/red]", extra={"markup": True})