major-domo-legacy/majordomo.py
Cal Corum e54cf885ad Migrated to rotating log handler
Added random_gif()
Moved back from exception-handler cog to local error handling
Updated !keepers to be season agnostic
Added new !sync param to update and clear local guild
Added error checking to !player command
2024-12-11 14:52:28 -06:00

77 lines
1.8 KiB
Python

import asyncio
import datetime
import logging
from logging.handlers import RotatingFileHandler
import os
import discord
from discord.ext import commands
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
logger = logging.getLogger('discord_app')
logger.setLevel(log_level)
handler = RotatingFileHandler(
filename='logs/discord.log',
# encoding='utf-8',
maxBytes=32 * 1024 * 1024, # 32 MiB
backupCount=5, # Rotate through 5 files
)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
COGS = [
'cogs.owner',
'cogs.transactions',
'cogs.admins',
'cogs.dice',
'cogs.fun',
'cogs.players',
'cogs.exception-handler'
# 'cogs.gameday',
# 'cogs.gameplay'
]
intents = discord.Intents.default()
intents.message_content = True
intents.members = True
bot = commands.Bot(
command_prefix='!',
intents=intents,
description='The Strat-o-matic Bot\nIf you have questions, feel free to contact Cal.',
case_insensitive=True,
owner_id=258104532423147520
)
@bot.event
async def on_ready():
logger.info('Logged in as:')
logger.info(bot.user.name)
logger.info(bot.user.id)
async def main():
for c in COGS:
try:
await bot.load_extension(c)
logger.info(f'Loaded cog: {c}')
except Exception as e:
logger.error(f'Failed to load cog: {c}')
logger.error(f'{e}')
async with bot:
await bot.start(os.environ.get('BOT_TOKEN'))
asyncio.run(main())