Initialisation du repository de Beta

This commit is contained in:
Mathis 2026-02-06 22:23:20 +01:00
commit 14985f6dbb
9469 changed files with 1903273 additions and 0 deletions

89
superviseur/context.py Normal file
View file

@ -0,0 +1,89 @@
"""Context building utilities for Superviseur bot."""
import discord
from typing import Tuple
def build_server_context(guild: discord.Guild) -> str:
"""Build a comprehensive context string for the server."""
if not guild:
return "\nContexte : Aucun serveur (Message Direct)."
context = f"\nInformations sur le serveur '{guild.name}' (ID: {guild.id}):\n"
context += f"- Membres: {guild.member_count}\n"
context += f"- Propriétaire: {guild.owner.display_name if guild.owner else 'Inconnu'}\n"
context += f"- Créé le: {guild.created_at.strftime('%Y-%m-%d %H:%M:%S')} UTC\n"
# Channels
text_channels = [ch.name for ch in guild.channels if isinstance(ch, discord.TextChannel)]
voice_channels = [ch.name for ch in guild.channels if isinstance(ch, discord.VoiceChannel)]
categories = [cat.name for cat in guild.channels if isinstance(cat, discord.CategoryChannel)]
if text_channels:
context += f"- Salons textes: {len(text_channels)} ({', '.join(text_channels[:5])}...)\n"
else:
context += "- Salons textes: 0\n"
context += f"- Salons vocaux: {len(voice_channels)}\n"
if categories:
context += f"- Catégories: {len(categories)} ({', '.join(categories[:3])}...)\n"
else:
context += "- Catégories: 0\n"
# Roles (except @everyone)
roles = [role.name for role in guild.roles[1:]] # Skip @everyone
if roles:
context += f"- Rôles: {len(roles)}\n"
for role_name in roles:
context += f" - {role_name}\n"
else:
context += "- Rôles: 0\n"
# Recent activity (approximate)
recent_members = sorted(guild.members, key=lambda m: m.joined_at or m.created_at, reverse=True)[:3]
context += f"- Membres récents: {', '.join([m.display_name for m in recent_members])}\n"
return context
def build_channels_list(guild: discord.Guild) -> str:
"""Build a formatted list of all channels."""
if not guild:
return ""
lines = ["\nListe des salons:"]
for ch in guild.channels:
if isinstance(ch, discord.TextChannel):
ch_type = 'textuel'
elif isinstance(ch, discord.VoiceChannel):
ch_type = 'vocal'
else:
ch_type = str(ch.type)
lines.append(f"- {ch.name} ({ch_type})")
return "\n".join(lines)
def build_context_for_message(
guild: discord.Guild,
channels_list_cache: dict,
server_context_cache: dict
) -> Tuple[str, str]:
"""Build channels list and server context with caching."""
if not guild:
return "", build_server_context(None)
guild_id = guild.id
# Build channels list with caching
if guild_id not in channels_list_cache:
channels_list_cache[guild_id] = build_channels_list(guild)
channels_list = channels_list_cache[guild_id]
# Build server context with caching
if guild_id not in server_context_cache:
server_context_cache[guild_id] = build_server_context(guild)
server_context = server_context_cache[guild_id]
return channels_list, server_context