from configparser import ConfigParser import sys from core.logger import ColorizedArgsFormatter, BraceFormatStyleFormatter from core.logger import logging __version__ = "0.1.0" # Set up logging root_logger = logging.getLogger() root_logger.setLevel(logging.DEBUG) console_level = "DEBUG" console_handler = logging.StreamHandler(stream=sys.stdout) console_handler.setLevel(console_level) console_format = "%(asctime)s - %(levelname)-8s - %(name)-25s - %(message)s" # NOQA colored_formatter = ColorizedArgsFormatter(console_format) console_handler.setFormatter(colored_formatter) root_logger.addHandler(console_handler) file_handler = logging.FileHandler("app.log") file_level = "DEBUG" file_handler.setLevel(file_level) file_format = "%(asctime)s - %(name)s (%(lineno)s) - %(levelname)-8s - %(threadName)-12s - %(message)s" # NOQA file_handler.setFormatter(BraceFormatStyleFormatter(file_format)) root_logger.addHandler(file_handler) # Load bot config config = ConfigParser() try: config.read("config.ini") logging.debug("Configuration loaded") except FileNotFoundError: config["DEFAULT"] = {"BotName": "ameliabot", "BotOwner": "Some Name"} config["owncast"] = { "ServerURL": "https://yourowncloud.server", "AccessToken": "Someaccesstoken23-209523dfsd"} with open("config.ini", "w") as f: config.write(f) logging.error("Configuration file not found so minimal one generated.") logging.error("Please edit config.ini and try again.") logging.error("See config.example.ini for full options") raise SystemExit cmd_file = ConfigParser() try: cmd_file.read("commands.ini") commands = cmd_file["commands"] logging.debug("Commands loaded") aliases = cmd_file["aliases"] logging.debug("Aliases loaded") except FileNotFoundError: cmd_file["commands"] = { "!version": "I am running ameliabot {bot_version}"} cmd_file["aliases"] = {"!bot": "!version"} with open("commands.ini", "w") as f: cmd_file.write(f) logging.error("Missing commands.ini! Generated basic file.") raise SystemExit