fix: Add detailed error logging with traceback for user data and configuration loading/saving
This commit is contained in:
parent
76f2d2cd23
commit
c7097425a7
@ -6,6 +6,7 @@ import os
|
||||
import asyncio
|
||||
import random
|
||||
import math
|
||||
import traceback # Import traceback for detailed error logging
|
||||
from typing import Dict, List, Optional, Union, Set
|
||||
|
||||
# File paths for JSON data
|
||||
@ -63,6 +64,7 @@ class LevelingCog(commands.Cog):
|
||||
print(f"Loaded level data for {len(self.user_data)} users")
|
||||
except Exception as e:
|
||||
print(f"Error loading level data: {e}")
|
||||
traceback.print_exc()
|
||||
|
||||
def save_user_data(self):
|
||||
"""Save user XP and level data to JSON file"""
|
||||
@ -73,6 +75,7 @@ class LevelingCog(commands.Cog):
|
||||
json.dump(serializable_data, f, indent=4, ensure_ascii=False)
|
||||
except Exception as e:
|
||||
print(f"Error saving level data: {e}")
|
||||
traceback.print_exc()
|
||||
|
||||
def load_level_roles(self):
|
||||
"""Load level role configuration from JSON file"""
|
||||
@ -104,6 +107,7 @@ class LevelingCog(commands.Cog):
|
||||
print(f"Loaded level roles for {len(self.level_roles)} guilds")
|
||||
except Exception as e:
|
||||
print(f"Error loading level roles: {e}")
|
||||
traceback.print_exc()
|
||||
|
||||
def save_level_roles(self):
|
||||
"""Save level role configuration to JSON file"""
|
||||
@ -128,6 +132,7 @@ class LevelingCog(commands.Cog):
|
||||
json.dump(serializable_data, f, indent=4, ensure_ascii=False)
|
||||
except Exception as e:
|
||||
print(f"Error saving level roles: {e}")
|
||||
traceback.print_exc()
|
||||
|
||||
def load_restricted_channels(self):
|
||||
"""Load restricted channels from JSON file"""
|
||||
@ -140,6 +145,7 @@ class LevelingCog(commands.Cog):
|
||||
print(f"Loaded {len(self.restricted_channels)} restricted channels")
|
||||
except Exception as e:
|
||||
print(f"Error loading restricted channels: {e}")
|
||||
traceback.print_exc()
|
||||
|
||||
def save_restricted_channels(self):
|
||||
"""Save restricted channels to JSON file"""
|
||||
@ -150,6 +156,7 @@ class LevelingCog(commands.Cog):
|
||||
json.dump(serializable_data, f, indent=4, ensure_ascii=False)
|
||||
except Exception as e:
|
||||
print(f"Error saving restricted channels: {e}")
|
||||
traceback.print_exc()
|
||||
|
||||
def load_config(self):
|
||||
"""Load leveling configuration from JSON file"""
|
||||
@ -164,6 +171,7 @@ class LevelingCog(commands.Cog):
|
||||
print(f"Loaded leveling configuration")
|
||||
except Exception as e:
|
||||
print(f"Error loading leveling configuration: {e}")
|
||||
traceback.print_exc()
|
||||
|
||||
def save_config(self):
|
||||
"""Save leveling configuration to JSON file"""
|
||||
@ -172,6 +180,7 @@ class LevelingCog(commands.Cog):
|
||||
json.dump(self.config, f, indent=4, ensure_ascii=False)
|
||||
except Exception as e:
|
||||
print(f"Error saving leveling configuration: {e}")
|
||||
traceback.print_exc()
|
||||
|
||||
def calculate_level(self, xp: int) -> int:
|
||||
"""Calculate level based on XP"""
|
||||
@ -300,6 +309,7 @@ class LevelingCog(commands.Cog):
|
||||
print(f"Missing permissions to assign roles in guild {guild_id}")
|
||||
except Exception as e:
|
||||
print(f"Error assigning level role: {e}")
|
||||
traceback.print_exc()
|
||||
|
||||
return False
|
||||
|
||||
@ -631,6 +641,7 @@ class LevelingCog(commands.Cog):
|
||||
await ctx.send(f"Missing permissions to read message history in {channel.mention}")
|
||||
except Exception as e:
|
||||
await ctx.send(f"Error processing messages in {channel.mention}: {e}")
|
||||
traceback.print_exc()
|
||||
|
||||
# Final update
|
||||
await status_message.edit(content=f"✅ Finished processing {total_processed} messages across {total_channels} channels.")
|
||||
@ -896,6 +907,7 @@ class LevelingCog(commands.Cog):
|
||||
await ctx.send(f"Missing permissions to edit role: {role_name}")
|
||||
except Exception as e:
|
||||
await ctx.send(f"Error updating role {role_name}: {e}")
|
||||
traceback.print_exc()
|
||||
else:
|
||||
# Create new role
|
||||
try:
|
||||
@ -909,6 +921,7 @@ class LevelingCog(commands.Cog):
|
||||
await ctx.send(f"Missing permissions to create role: {role_name}")
|
||||
except Exception as e:
|
||||
await ctx.send(f"Error creating role {role_name}: {e}")
|
||||
traceback.print_exc()
|
||||
continue
|
||||
|
||||
# Register the role for this level
|
||||
@ -929,6 +942,7 @@ class LevelingCog(commands.Cog):
|
||||
await ctx.send(f"Missing permissions to edit role: {male_role_name}")
|
||||
except Exception as e:
|
||||
await ctx.send(f"Error updating role {male_role_name}: {e}")
|
||||
traceback.print_exc()
|
||||
else:
|
||||
try:
|
||||
male_role = await ctx.guild.create_role(
|
||||
@ -941,6 +955,7 @@ class LevelingCog(commands.Cog):
|
||||
await ctx.send(f"Missing permissions to create role: {male_role_name}")
|
||||
except Exception as e:
|
||||
await ctx.send(f"Error creating role {male_role_name}: {e}")
|
||||
traceback.print_exc()
|
||||
male_role = None
|
||||
|
||||
# Create female role
|
||||
@ -955,6 +970,7 @@ class LevelingCog(commands.Cog):
|
||||
await ctx.send(f"Missing permissions to edit role: {female_role_name}")
|
||||
except Exception as e:
|
||||
await ctx.send(f"Error updating role {female_role_name}: {e}")
|
||||
traceback.print_exc()
|
||||
else:
|
||||
try:
|
||||
female_role = await ctx.guild.create_role(
|
||||
@ -967,6 +983,7 @@ class LevelingCog(commands.Cog):
|
||||
await ctx.send(f"Missing permissions to create role: {female_role_name}")
|
||||
except Exception as e:
|
||||
await ctx.send(f"Error creating role {female_role_name}: {e}")
|
||||
traceback.print_exc()
|
||||
female_role = None
|
||||
|
||||
# Create a special entry for gendered roles
|
||||
|
Loading…
x
Reference in New Issue
Block a user