import disnake from disnake.ext import commands import json import os from datetime import datetime SETTINGS_FILE = "data/security_settings.json" def get_log_channel(guild, settings): channel_id = settings.get("log_channel_id") if channel_id: return guild.get_channel(int(channel_id)) return None class LogsManager(commands.Cog): def __init__(self, bot): self.bot = bot @commands.Cog.listener() async def on_message_delete(self, message): if message.author.bot: return settings = dict(json.load(open(SETTINGS_FILE, "r"))).get(str(message.guild.id), {}) log_chan = get_log_channel(message.guild, settings) if log_chan: embed = disnake.Embed( title="🗑️ Message Supprimé", description=f"**Auteur :** {message.author.mention}\n**Salon :** {message.channel.mention}", color=0xFFA500, timestamp=disnake.utils.utcnow() ) embed.add_field(name="Contenu", value=message.content or "*(Image ou Embed)*") await log_chan.send(embed=embed) @commands.Cog.listener() async def on_member_remove(self, member): settings = dict(json.load(open(SETTINGS_FILE, "r"))).get(str(member.guild.id), {}) log_chan = get_log_channel(member.guild, settings) if log_chan: embed = disnake.Embed( title="📤 Départ d'un membre", description=f"{member.mention} ({member.id}) a quitté le serveur.", color=0xFF0000, timestamp=disnake.utils.utcnow() ) await log_chan.send(embed=embed) @commands.Cog.listener() async def on_member_ban(self, guild, user): settings = dict(json.load(open(SETTINGS_FILE, "r"))).get(str(guild.id), {}) log_chan = get_log_channel(guild, settings) if log_chan: embed = disnake.Embed( title="🔨 Bannissement", description=f"**Utilisateur :** {user.mention} ({user.id}) a été banni.", color=0x000000, timestamp=disnake.utils.utcnow() ) await log_chan.send(embed=embed) async def setup(bot): await bot.add_cog(LogsManager(bot))