mirror of
https://github.com/Xevion/unbelievaselfbot.git
synced 2025-12-08 06:08:51 -06:00
proper path constants, logging level constant, file & stream logging
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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'])
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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):
|
||||
|
||||
14
main.py
14
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.')
|
||||
|
||||
Reference in New Issue
Block a user