53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
"""Main JARVIS package."""
|
|
import logging
|
|
from importlib.metadata import version as _v
|
|
|
|
from dis_snek import Intents
|
|
from jarvis_core.db import connect
|
|
from jarvis_core.log import get_logger
|
|
|
|
from jarvis import utils
|
|
from jarvis.client import Jarvis
|
|
from jarvis.config import JarvisConfig
|
|
|
|
try:
|
|
__version__ = _v("jarvis")
|
|
except Exception:
|
|
__version__ = "0.0.0"
|
|
|
|
jconfig = JarvisConfig.from_yaml()
|
|
logger = get_logger("jarvis")
|
|
logger.setLevel(jconfig.log_level)
|
|
file_handler = logging.FileHandler(filename="jarvis.log", encoding="UTF-8", mode="w")
|
|
file_handler.setFormatter(
|
|
logging.Formatter("[%(asctime)s] [%(name)s] [%(levelname)8s] %(message)s")
|
|
)
|
|
logger.addHandler(file_handler)
|
|
|
|
intents = Intents.DEFAULT | Intents.MESSAGES | Intents.GUILD_MEMBERS | Intents.GUILD_MESSAGES
|
|
restart_ctx = None
|
|
|
|
jarvis = Jarvis(
|
|
intents=intents,
|
|
sync_interactions=jconfig.sync,
|
|
delete_unused_application_cmds=True,
|
|
send_command_tracebacks=False,
|
|
)
|
|
|
|
|
|
async def run() -> None:
|
|
"""Run JARVIS"""
|
|
logger.info("Starting JARVIS")
|
|
logger.debug("Connecting to database")
|
|
connect(**jconfig.mongo["connect"], testing=jconfig.mongo["database"] != "jarvis")
|
|
logger.debug("Loading configuration from database")
|
|
# jconfig.get_db_config()
|
|
|
|
logger.debug("Loading extensions")
|
|
for extension in utils.get_extensions():
|
|
jarvis.load_extension(extension)
|
|
logger.debug(f"Loaded {extension}")
|
|
|
|
jarvis.max_messages = jconfig.max_messages
|
|
logger.debug("Running JARVIS")
|
|
await jarvis.astart(jconfig.token)
|