2022-04-24 04:47:08 +03:00
|
|
|
from configparser import ConfigParser
|
2022-04-24 02:48:43 +03:00
|
|
|
import sys
|
2022-04-27 11:24:45 +03:00
|
|
|
from core.logger import ColorizedArgsFormatter, BraceFormatStyleFormatter
|
|
|
|
from core.logger import logging
|
2022-04-24 02:48:43 +03:00
|
|
|
|
|
|
|
|
2022-04-24 04:47:08 +03:00
|
|
|
__version__ = "0.1.0"
|
2022-04-24 02:48:43 +03:00
|
|
|
|
|
|
|
# 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)
|
|
|
|
|
2022-04-24 04:47:08 +03:00
|
|
|
# Load bot config
|
|
|
|
config = ConfigParser()
|
2022-04-24 02:48:43 +03:00
|
|
|
try:
|
2022-04-24 04:47:08 +03:00
|
|
|
config.read("config.ini")
|
|
|
|
logging.info("Configuration loaded")
|
2022-04-24 02:48:43 +03:00
|
|
|
except FileNotFoundError:
|
2022-04-24 04:47:08 +03:00
|
|
|
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")
|
2022-04-24 02:48:43 +03:00
|
|
|
raise SystemExit
|
|
|
|
|
2022-04-24 04:47:08 +03:00
|
|
|
cmd_file = ConfigParser()
|
|
|
|
try:
|
|
|
|
cmd_file.read("commands.ini")
|
|
|
|
commands = cmd_file["commands"]
|
2022-04-24 02:48:43 +03:00
|
|
|
logging.info("Commands loaded")
|
|
|
|
|
2022-04-24 04:47:08 +03:00
|
|
|
aliases = cmd_file["aliases"]
|
2022-04-24 02:48:43 +03:00
|
|
|
logging.info("Aliases loaded")
|
2022-04-24 04:47:08 +03:00
|
|
|
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
|