diff --git a/bot/client.py b/bot/client.py index c4b6bd3..26a18f4 100644 --- a/bot/client.py +++ b/bot/client.py @@ -11,7 +11,7 @@ import discord from discord.ext.tasks import loop logger = logging.getLogger(__file__) -logger.setLevel(logging.DEBUG) +logger.setLevel(constants.LOGGING_LEVEL) class UnbelievaClient(discord.Client): diff --git a/bot/constants.py b/bot/constants.py index cc522e7..676c4c3 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -1,3 +1,16 @@ +import logging +import os + from collections import namedtuple +# Path Constants +BASE_DIR = os.path.dirname(os.path.abspath(os.path.join(__file__, '..'))) +STATIC_DIR = os.path.join(BASE_DIR, 'bot', 'static') +TOKEN = os.path.join(BASE_DIR, 'token.dat') +DATABASE = os.path.join(BASE_DIR, 'database.db') + +# Other constants +LOGGING_LEVEL = logging.DEBUG + +# NamedTuple Classes PlayOptions = namedtuple('PlayOptions', ['hit', 'stand', 'double', 'split']) diff --git a/bot/helpers.py b/bot/helpers.py index 4127307..6f22302 100644 --- a/bot/helpers.py +++ b/bot/helpers.py @@ -3,7 +3,7 @@ from pprint import pprint import discord -def print(embed: discord.Embed) -> None: +def print_embed(embed: discord.Embed) -> None: pprint(( embed.title, embed.description, diff --git a/bot/parsers.py b/bot/parsers.py index 2097c53..44a0fcb 100644 --- a/bot/parsers.py +++ b/bot/parsers.py @@ -4,8 +4,10 @@ from abc import ABC import discord +from bot import constants + logger = logging.getLogger(__file__) -logger.setLevel(logging.DEBUG) +logger.setLevel(constants.LOGGING_LEVEL) class BaseMessage(object): diff --git a/bot/timings.py b/bot/timings.py index 3fde2a5..34895ff 100644 --- a/bot/timings.py +++ b/bot/timings.py @@ -1,7 +1,11 @@ +import logging import time from typing import Union, Optional -from bot import exceptions +from bot import exceptions, constants + +logger = logging.getLogger(__file__) +logger.setLevel(constants.LOGGING_LEVEL) class Cooldown(object): diff --git a/main.py b/main.py index 80672de..728e286 100644 --- a/main.py +++ b/main.py @@ -1,11 +1,9 @@ import argparse import logging +from bot import constants from bot.client import UnbelievaClient -logging.basicConfig(format='[%(asctime)s] [%(levelname)s] [%(funcName)s] %(message)s') -logger = logging.getLogger(__file__) -logger.setLevel(logging.DEBUG) if __name__ == "__main__": parser = argparse.ArgumentParser(description='Start the discord bot.') @@ -14,6 +12,16 @@ if __name__ == "__main__": parser.add_argument('bot', metavar='BOT', type=int, help='The ID of the UnbelievaBoat bot to target.') parsed = parser.parse_args() + + logger = logging.getLogger(__file__) + # noinspection PyArgumentList + logging.basicConfig(format='[%(asctime)s] [%(levelname)s] [%(funcName)s] %(message)s', + handlers=[ + logging.FileHandler(f"bot-{parsed.channel}.log"), + logging.StreamHandler() + ]) + logger.setLevel(constants.LOGGING_LEVEL) + client = UnbelievaClient(parsed.bot, parsed.channel) logger.info('Starting bot.')