Kuby/commandes/modules_security/logs_manager.py
2026-01-01 18:48:25 +01:00

62 lines
No EOL
2.2 KiB
Python

import discord
from discord.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 = discord.Embed(
title="🗑️ Message Supprimé",
description=f"**Auteur :** {message.author.mention}\n**Salon :** {message.channel.mention}",
color=0xFFA500,
timestamp=datetime.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 = discord.Embed(
title="📤 Départ d'un membre",
description=f"{member.mention} ({member.id}) a quitté le serveur.",
color=0xFF0000,
timestamp=datetime.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 = discord.Embed(
title="🔨 Bannissement",
description=f"**Utilisateur :** {user.mention} ({user.id}) a été banni.",
color=0x000000,
timestamp=datetime.utcnow()
)
await log_chan.send(embed=embed)
async def setup(bot):
await bot.add_cog(LogsManager(bot))