#!/usr/bin/env python3 # -*- coding: utf-8 -*- # System packages import json import logging import sys from pathlib import Path from typing import Dict, Any # PyPi packages import discord # Project packages from bot.marxbot import MarxBot def setup_logger(path_log: Path) -> None: """Setup of the logger to keep logs in the given file. :param path_log: Path to file where the logs should be kept. :return: None """ logging.basicConfig(filename=path_log, filemode="a+", level=logging.INFO, format="[%(asctime)s][%(levelname)s] %(message)s", datefmt="%Y-%m-%d %H:%M:%S") handler = logging.StreamHandler(sys.stdout) handler.setLevel(logging.INFO) handler.setFormatter(logging.Formatter('[%(asctime)s][%(levelname)s] %(message)s')) logging.getLogger().addHandler(handler) if __name__ == '__main__': # Load the bot configuration. with open(Path("configuration.json"), "r") as file_config: botconfig: Dict[str, Any] = json.loads(file_config.read()) # Activate the logs setup_logger(Path(botconfig["path_root"]) / botconfig["path_log"]) # Launch MarxBot logging.info("MarxBot is launching.") intents = discord.Intents.all() client = MarxBot(botconfig=botconfig, intents=intents) try: client.run(botconfig["token"]) except Exception: logging.error("Something went bad !", exc_info=True) raise logging.info("MarxBot has shutdown.")