-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
82 lines (60 loc) · 1.82 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import asyncio
import logging
import os
from os import getenv
from colorlog import ColoredFormatter
from disnake import Intents
from disnake.ext.commands import CommandSyncFlags
from dotenv import load_dotenv
from core.bot import Bot
# pylint: disable=C0116
# pylint: disable=C0115
def main():
load_dotenv()
setup_logging()
main_logger = logging.getLogger("lava.main")
loop = asyncio.new_event_loop()
bot = Bot(
logger=main_logger,
command_prefix=getenv("PREFIX", "l!"), intents=Intents.all(), loop=loop,
command_sync_flags=CommandSyncFlags.default()
)
load_extensions(bot)
bot.run(os.environ["TOKEN"])
def setup_logging():
"""
Set up the loggings for the bot
:return: None
"""
formatter = ColoredFormatter(
'%(asctime)s %(log_color)s [%(levelname)s] %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
log_colors={
'DEBUG': 'cyan',
'INFO': 'white',
'WARNING': 'yellow',
'ERROR': 'red',
'CRITICAL': 'bold_red',
}
)
stream_handler = logging.StreamHandler()
stream_handler.setLevel(logging.INFO)
stream_handler.setFormatter(formatter)
file_handler = logging.FileHandler(filename="lava.log", encoding="utf-8", mode="w")
file_handler.setLevel(logging.DEBUG)
file_handler.setFormatter(formatter)
logging.basicConfig(
handlers=[stream_handler, file_handler], level=logging.INFO
)
def load_extensions(bot: Bot) -> Bot:
"""
Load extensions in extensions.json file
:param bot: The bot to load the extensions to
:return: The bot
"""
for filename in os.listdir("./cogs"):
if filename.endswith('.py'):
bot.load_extension(f"cogs.{filename[:-3]}")
return bot
if __name__ == "__main__":
main()