feat: Refactored all cogs implementation
Some checks failed
CI / Run tests (pull_request) Has been cancelled

This commit is contained in:
2026-09-12 23:16:43 +02:00
parent 505621e0cd
commit c86ea54e86
10 changed files with 451 additions and 123 deletions

55
main.py
View File

@@ -1,29 +1,54 @@
import os, discord, json, sys, random
import os
import sys
import discord
from argparse import ArgumentParser
from datetime import datetime
from asyncio import create_task
from discord import option
from discord.ext import tasks, commands
# Parse minimal CLI args early so we can configure logging before imports that
# initialize loggers. Keep only `--log-level`; other args were unused.
PARSER = ArgumentParser(description='BotMafieux for Discord.')
PARSER.add_argument('--log-level', type=str, help='Logging level (DEBUG, INFO, WARNING, ERROR)')
EXEC_ARGS = PARSER.parse_args()
if EXEC_ARGS.log_level:
os.environ['LOG_LEVEL'] = str(EXEC_ARGS.log_level)
from setup.bot import bot, reload_feature, register_cogs
from setup.logger import LOGGER
from setup.config import Config
PARSER = ArgumentParser(description='BotMafieux for Discord.')
PARSER.add_argument('--guild_id',type=int,help='The guild ID.')
PARSER.add_argument('--channel_id',type=int,help='The channel ID.')
PARSER.add_argument('-r','--reload',action='store_true',help='Reload the bot.')
PARSER.add_argument('--cogs',nargs='+',default=None,help='Select which cogs to load (for example: --cogs cs insult).')
EXEC_ARGS = PARSER.parse_args()
selected_cogs = EXEC_ARGS.cogs if EXEC_ARGS.cogs is not None else Config.get_cogs()
register_cogs(selected_cogs)
# Register cogs from configuration (no CLI activation)
register_cogs()
@bot.event
async def on_ready():
if bot.user:
LOGGER.info(f'{bot.user.name} has connected to Discord!')
LOGGER.debug(f"Guilds: {','.join([guild.name for guild in bot.guilds])}")
LOGGER.info(f"Guilds: {','.join([guild.name for guild in bot.guilds])}")
# Log configuration for each guild we are connected to
try:
for guild in bot.guilds:
cfg = Config.GUILD_CONFIGS.get(guild.id)
if cfg is not None:
LOGGER.info(f"Guild config for {guild.name} ({guild.id}): {cfg}")
else:
LOGGER.info(f"No guild config for {guild.name} ({guild.id})")
except Exception as e:
LOGGER.warning(f"Failed to log guild configs: {e}")
@bot.event
async def on_guild_join(guild: discord.Guild):
# Refresh configs and log the joined guild configuration
try:
Config.load_guilds_configs()
except Exception:
LOGGER.debug('Could not reload guild configs during on_guild_join.')
cfg = Config.GUILD_CONFIGS.get(guild.id)
if cfg is not None:
LOGGER.info(f"Joined guild {guild.name} ({guild.id}) with config: {cfg}")
else:
LOGGER.info(f"Joined guild {guild.name} ({guild.id}) with no configuration present.")
if __name__ == '__main__':
token = Config.TOKEN