Rework complet du système de ticket § focntinnnement partiel

This commit is contained in:
Mathis 2026-01-10 15:30:51 +01:00
parent 93e2f9bb44
commit dfec6b2418
75 changed files with 6424 additions and 1893 deletions

View file

@ -28,32 +28,44 @@ class WhitelistMonitor(commands.Cog):
discord.Permissions.view_audit_log
]
def load_whitelist(self) -> List[str]:
def load_whitelist(self) -> Dict[str, List[str]]:
"""Load whitelist from JSON file."""
if not os.path.exists(self.whitelist_file):
return []
return {}
try:
with open(self.whitelist_file, "r", encoding="utf-8") as f:
return json.load(f)
raw_data = json.load(f)
# Convert all user IDs to strings for consistent comparison
result = {}
for guild_id, user_ids in raw_data.items():
result[str(guild_id)] = [str(uid) for uid in user_ids]
return result
except (json.JSONDecodeError, FileNotFoundError):
return []
return {}
def save_whitelist(self, whitelist: List[str]):
def save_whitelist(self, whitelist: Dict[str, List[str]]):
"""Save whitelist to JSON file."""
with open(self.whitelist_file, "w", encoding="utf-8") as f:
json.dump(whitelist, f, ensure_ascii=False, indent=4)
def is_whitelisted(self, user_id: int) -> bool:
"""Check if user is whitelisted."""
def is_whitelisted(self, guild_id: int, user_id: int) -> bool:
"""Check if user is whitelisted for a specific guild."""
whitelist = self.load_whitelist()
return str(user_id) in whitelist
guild_key = str(guild_id)
user_key = str(user_id)
return guild_key in whitelist and user_key in whitelist[guild_key]
def remove_from_whitelist(self, user_id: int) -> bool:
"""Remove user from whitelist."""
def remove_from_whitelist(self, guild_id: int, user_id: int) -> bool:
"""Remove user from whitelist for a specific guild."""
whitelist = self.load_whitelist()
user_str = str(user_id)
if user_str in whitelist:
whitelist.remove(user_str)
guild_key = str(guild_id)
user_key = str(user_id)
if guild_key in whitelist and user_key in whitelist[guild_key]:
whitelist[guild_key].remove(user_key)
# Clean up empty guild entries
if not whitelist[guild_key]:
del whitelist[guild_key]
self.save_whitelist(whitelist)
return True
return False
@ -148,7 +160,7 @@ class WhitelistMonitor(commands.Cog):
if before.roles == after.roles:
return
if not self.is_whitelisted(after.id):
if not self.is_whitelisted(after.guild.id, after.id):
return
# Find removed roles
@ -163,8 +175,8 @@ class WhitelistMonitor(commands.Cog):
@commands.Cog.listener()
async def on_member_remove(self, member: discord.Member):
"""Auto-remove from whitelist when member leaves server."""
if self.is_whitelisted(member.id):
removed = self.remove_from_whitelist(member.id)
if self.is_whitelisted(member.guild.id, member.id):
removed = self.remove_from_whitelist(member.guild.id, member.id)
if removed:
# Log the removal
try:
@ -225,7 +237,7 @@ class WhitelistRemovalView(View):
return
# Remove from whitelist
removed = cog.remove_from_whitelist(self.user_id)
removed = cog.remove_from_whitelist(self.guild_id, self.user_id)
if removed:
# Get user info