Kuby/commandes/modules_security/logs_manager.py

62 lines
2.2 KiB
Python
Raw Normal View History

2026-05-06 17:07:09 +02:00
import disnake
from disnake.ext import commands
2026-01-01 18:48:25 +01:00
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:
2026-05-06 17:07:09 +02:00
embed = disnake.Embed(
2026-01-01 18:48:25 +01:00
title="🗑️ Message Supprimé",
description=f"**Auteur :** {message.author.mention}\n**Salon :** {message.channel.mention}",
color=0xFFA500,
2026-05-06 17:07:09 +02:00
timestamp=disnake.utils.utcnow()
2026-01-01 18:48:25 +01:00
)
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:
2026-05-06 17:07:09 +02:00
embed = disnake.Embed(
2026-01-01 18:48:25 +01:00
title="📤 Départ d'un membre",
description=f"{member.mention} ({member.id}) a quitté le serveur.",
color=0xFF0000,
2026-05-06 17:07:09 +02:00
timestamp=disnake.utils.utcnow()
2026-01-01 18:48:25 +01:00
)
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:
2026-05-06 17:07:09 +02:00
embed = disnake.Embed(
2026-01-01 18:48:25 +01:00
title="🔨 Bannissement",
description=f"**Utilisateur :** {user.mention} ({user.id}) a été banni.",
color=0x000000,
2026-05-06 17:07:09 +02:00
timestamp=disnake.utils.utcnow()
2026-01-01 18:48:25 +01:00
)
await log_chan.send(embed=embed)
async def setup(bot):
await bot.add_cog(LogsManager(bot))