2023-02-05 04:32:26 -06:00
|
|
|
import logging
|
|
|
|
import sys
|
|
|
|
import autowl.bot as bot
|
2023-01-27 13:07:54 -06:00
|
|
|
from os import environ
|
2023-02-05 04:32:26 -06:00
|
|
|
from autowl.config import DiscordClientConfig
|
2023-01-27 13:49:55 -06:00
|
|
|
|
2023-02-05 04:32:26 -06:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2024-10-01 18:27:04 -05:00
|
|
|
|
2023-02-05 04:32:26 -06:00
|
|
|
class CustomFormat(logging.Formatter):
|
|
|
|
grey = "\x1b[38;20m"
|
|
|
|
yellow = "\x1b[33;20m"
|
|
|
|
red = "\x1b[31;20m"
|
|
|
|
bold_red = "\x1b[31;1m"
|
|
|
|
reset = "\x1b[0m"
|
|
|
|
format = (
|
|
|
|
"[%(asctime)s][%(levelname)s][%(name)s.%(funcName)s:%(lineno)d] %(message)s"
|
|
|
|
)
|
|
|
|
|
|
|
|
FORMATS = {
|
|
|
|
logging.DEBUG: grey + format + reset,
|
|
|
|
logging.INFO: grey + format + reset,
|
|
|
|
logging.WARNING: yellow + format + reset,
|
|
|
|
logging.ERROR: red + format + reset,
|
|
|
|
logging.CRITICAL: bold_red + format + reset,
|
|
|
|
}
|
|
|
|
|
|
|
|
def format(self, record):
|
|
|
|
log_fmt = self.FORMATS.get(record.levelno)
|
|
|
|
formatter = logging.Formatter(log_fmt)
|
|
|
|
return formatter.format(record)
|
2023-01-27 13:49:55 -06:00
|
|
|
|
2023-01-27 11:58:14 -06:00
|
|
|
|
2023-02-05 04:32:26 -06:00
|
|
|
def setup_logging():
|
|
|
|
log_level = environ.get("LOG_LEVEL") or "INFO"
|
2023-01-27 15:54:21 -06:00
|
|
|
|
2023-02-05 04:32:26 -06:00
|
|
|
ch = logging.StreamHandler(stream=sys.stdout)
|
|
|
|
ch.setFormatter(CustomFormat())
|
2023-01-27 15:54:21 -06:00
|
|
|
|
2023-02-05 04:32:26 -06:00
|
|
|
log.setLevel(log_level)
|
|
|
|
discord_log = logging.getLogger("discord")
|
|
|
|
discord_log.setLevel(log_level)
|
|
|
|
discord_http_log = logging.getLogger("discord.http")
|
|
|
|
discord_http_log.setLevel(log_level)
|
|
|
|
|
|
|
|
logging.basicConfig(level=log_level, handlers=[ch])
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
setup_logging()
|
|
|
|
|
|
|
|
if disToken := environ.get("DISCORD_TOKEN"):
|
|
|
|
bot_config = DiscordClientConfig(disToken)
|
2023-04-17 20:46:53 -05:00
|
|
|
if not (dbpass := environ.get("DBPASS")):
|
|
|
|
log.error("Unable to access DBPASS in environment!")
|
|
|
|
exit(1)
|
2023-02-05 04:32:26 -06:00
|
|
|
try:
|
2023-04-17 20:46:53 -05:00
|
|
|
bot.Bot(bot_config, dbpass).start_bot()
|
2023-02-05 04:32:26 -06:00
|
|
|
except Exception as e:
|
|
|
|
log.critical(f"Bot exited critically, error: {e}")
|
|
|
|
raise e
|
|
|
|
else:
|
|
|
|
log.error("Unable to access DISCORD_TOKEN in environment!")
|
|
|
|
exit(1)
|
2023-01-27 13:49:55 -06:00
|
|
|
|
2023-01-27 15:54:21 -06:00
|
|
|
exit(0)
|
2023-01-27 13:49:55 -06:00
|
|
|
|
2023-01-27 11:58:14 -06:00
|
|
|
|
|
|
|
main()
|