-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.py
94 lines (69 loc) · 2.2 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
83
84
85
86
87
88
89
90
91
92
93
94
import asyncio
import json
import logging
import os
from os import getenv
from colorlog import ColoredFormatter
from disnake import Intents, Activity, BaseActivity
from disnake.ext.commands import CommandSyncFlags
from dotenv import load_dotenv
from lava.bot import Bot
def main():
if getenv("LOAD_ENV", "false").lower() == "true":
load_dotenv("stack.env")
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,
activity=get_activity(),
command_sync_flags=CommandSyncFlags.default(),
)
bot.i18n.load("locale/")
load_extensions(bot)
bot.run(os.environ["TOKEN"])
def get_activity() -> BaseActivity:
with open("configs/activity.json", "r") as f:
activity = json.load(f)
return Activity(**activity)
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
"""
with open("extensions.json", "r") as f:
extensions = json.load(f)
for extension in extensions:
bot.load_extension(extension)
return bot
if __name__ == "__main__":
main()