paper-dynasty-discord/paperdynasty.py
Cal Corum 97519fc8d5 Move db creation to entry
Nearing completion of new-game mlb-campaign
2024-10-13 00:25:29 -05:00

88 lines
2.4 KiB
Python

import discord
import datetime
import logging
# import logging.handlers
import asyncio
import os
from discord.ext import commands
from in_game.gameplay_models import create_db_and_tables
raw_log_level = os.getenv('LOG_LEVEL')
if raw_log_level == 'DEBUG':
log_level = logging.DEBUG
elif raw_log_level == 'INFO':
log_level = logging.INFO
elif raw_log_level == 'WARN':
log_level = logging.WARNING
else:
log_level = logging.ERROR
date = f'{datetime.datetime.now().year}-{datetime.datetime.now().month}-{datetime.datetime.now().day}'
logging.basicConfig(
filename=f'logs/{date}.log',
format='%(asctime)s - %(levelname)s - %(message)s',
level=log_level
)
# logging.getLogger('discord.http').setLevel(logging.INFO)
# logger = logging.getLogger('discord')
# logger.setLevel(log_level)
# handler = logging.handlers.RotatingFileHandler(
# filename='discord.log',
# encoding='utf-8',
# maxBytes=32 * 1024 * 1024, # 32 MiB
# backupCount=5, # Rotate through 5 files
# )
# dt_fmt = '%Y-%m-%d %H:%M:%S'
# formatter = logging.Formatter('[{asctime}] [{levelname:<8}] {name}: {message}', dt_fmt, style='{')
# handler.setFormatter(formatter)
# logger.addHandler(handler)
COGS = [
'cogs.owner',
'cogs.admins',
'cogs.economy',
'cogs.players',
'cogs.gameplay',
]
intents = discord.Intents.default()
intents.members = True
intents.message_content = True
bot = commands.Bot(command_prefix='.',
intents=intents,
# help_command=None,
description='The Paper Dynasty Bot\nIf you have questions, feel free to contact Cal.',
case_insensitive=True,
owner_id=258104532423147520)
@bot.event
async def on_ready():
logging.info('Logged in as:')
logging.info(bot.user.name)
logging.info(bot.user.id)
# @bot.tree.error
# async def on_error(interaction, error):
# await interaction.channel.send(f'{error}')
async def main():
create_db_and_tables()
for c in COGS:
try:
await bot.load_extension(c)
logging.info(f'Loaded cog: {c}')
except Exception as e:
logging.error(f'Failed to load cog: {c}')
logging.error(f'{e}')
async with bot:
await bot.start(os.environ.get('BOT_TOKEN'))
asyncio.run(main())