22from discord .ext import commands
33from cogs .logging .logger import CogLogger
44from utils .db import async_db as db
5+ import discord
56import json
67import datetime
78import random
@@ -749,7 +750,7 @@ async def clearcommands(self, ctx):
749750 await ctx .send (f"❌ Error: { type (e ).__name__ } : { e } " )
750751 raise e
751752
752- @commands .command ()
753+ @commands .command (aliases = [ "resetecon" ], hidden = True )
753754 @commands .is_owner ()
754755 async def reset_economy (self , ctx , * , confirmation : Optional [str ] = None ):
755756 """Reset everyone's balance, inventory, and economic data (Bot Owner Only)
@@ -1265,169 +1266,7 @@ async def repair_user_data(self, ctx, user: discord.Member = None):
12651266 color = discord .Color .red ()
12661267 )
12671268 await ctx .reply (embed = embed )
1268-
1269- @commands .command (name = "repair_all" )
1270- @commands .is_owner ()
1271- async def repair_all_users (self , ctx , limit : int = 50 ):
1272- """Repair all users with broken data (Bot Owner Only)
1273- Usage: .repair_all [limit]
1274- Default limit: 50 users"""
1275-
1276- if limit <= 0 or limit > 500 :
1277- return await ctx .reply ("❌ Limit must be between 1 and 500!" )
1278-
1279- try :
1280- # Get all users
1281- users_cursor = self .db .db .users .find ({}).limit (limit )
1282- users = await users_cursor .to_list (length = limit )
1283-
1284- if not users :
1285- return await ctx .reply ("No users found in database!" )
1286-
1287- embed = discord .Embed (
1288- title = "🔧 Bulk User Data Repair" ,
1289- description = f"Checking { len (users )} users for data issues..." ,
1290- color = discord .Color .blue ()
1291- )
1292- message = await ctx .reply (embed = embed )
1293-
1294- repaired_count = 0
1295- total_repairs = []
1296- failed_users = []
1297-
1298- for user_doc in users :
1299- user_id = user_doc ["_id" ]
1300-
1301- try :
1302- repairs_made = []
1303- updates = {}
1304-
1305- # Same repair logic as single user repair
1306- # Fix wallet/bank
1307- if "wallet" not in user_doc or not isinstance (user_doc .get ("wallet" ), (int , float )):
1308- updates ["wallet" ] = 0
1309- repairs_made .append ("wallet" )
1310-
1311- if "bank" not in user_doc or not isinstance (user_doc .get ("bank" ), (int , float )):
1312- updates ["bank" ] = 0
1313- repairs_made .append ("bank" )
1314-
1315- # Fix inventory structure
1316- inventory = user_doc .get ("inventory" , [])
1317-
1318- if isinstance (inventory , list ):
1319- new_inventory = {"rod" : {}, "bait" : {}, "potions" : {}, "upgrades" : {}}
1320-
1321- for item in inventory :
1322- if isinstance (item , dict ) and "type" in item :
1323- item_type = item ["type" ]
1324- item_id = item .get ("id" , item .get ("_id" , "unknown" ))
1325- quantity = item .get ("quantity" , item .get ("amount" , 1 ))
1326-
1327- if item_type == "potion" :
1328- new_inventory ["potions" ][item_id ] = quantity
1329- elif item_type == "upgrade" :
1330- new_inventory ["upgrades" ][item_id ] = quantity
1331- elif item_type == "rod" :
1332- new_inventory ["rod" ][item_id ] = quantity
1333- elif item_type == "bait" :
1334- new_inventory ["bait" ][item_id ] = quantity
1335-
1336- updates ["inventory" ] = new_inventory
1337- repairs_made .append ("inventory_structure" )
1338-
1339- elif isinstance (inventory , dict ):
1340- required_sections = ["rod" , "bait" , "potions" , "upgrades" ]
1341- missing_sections = []
1342-
1343- for section in required_sections :
1344- if section not in inventory :
1345- if "inventory" not in updates :
1346- updates ["inventory" ] = inventory .copy ()
1347- updates ["inventory" ][section ] = {}
1348- missing_sections .append (section )
1349-
1350- if missing_sections :
1351- repairs_made .append ("inventory_sections" )
1352-
1353- # Fix fishing data
1354- if "fishing" not in user_doc or not isinstance (user_doc .get ("fishing" ), dict ):
1355- updates ["fishing" ] = {
1356- "selected_rod" : None ,
1357- "selected_bait" : None ,
1358- "fish_caught" : {}
1359- }
1360- repairs_made .append ("fishing_data" )
1361-
1362- # Fix active effects
1363- if "active_effects" not in user_doc or not isinstance (user_doc .get ("active_effects" ), dict ):
1364- updates ["active_effects" ] = {}
1365- repairs_made .append ("active_effects" )
1366-
1367- # Apply updates if needed
1368- if updates :
1369- await self .db .db .users .update_one (
1370- {"_id" : user_id },
1371- {"$set" : updates }
1372- )
1373- repaired_count += 1
1374- total_repairs .extend (repairs_made )
1375-
1376- except Exception as e :
1377- failed_users .append (f"{ user_id } : { str (e )[:50 ]} " )
1378-
1379- # Update embed with results
1380- embed = discord .Embed (
1381- title = "✅ Bulk Repair Complete" ,
1382- description = f"Processed { len (users )} users" ,
1383- color = discord .Color .green ()
1384- )
1385-
1386- embed .add_field (
1387- name = "📊 Results" ,
1388- value = (
1389- f"✅ Users Repaired: { repaired_count } \n "
1390- f"⚠️ Failed Repairs: { len (failed_users )} \n "
1391- f"🔧 Total Fixes: { len (total_repairs )} "
1392- ),
1393- inline = False
1394- )
1395-
1396- if total_repairs :
1397- repair_counts = {}
1398- for repair in total_repairs :
1399- repair_counts [repair ] = repair_counts .get (repair , 0 ) + 1
1400-
1401- repair_summary = "\n " .join ([f"• { repair } : { count } " for repair , count in repair_counts .items ()])
1402- embed .add_field (
1403- name = "🔧 Repairs Made" ,
1404- value = repair_summary ,
1405- inline = False
1406- )
1407-
1408- if failed_users :
1409- embed .add_field (
1410- name = "❌ Failed Users" ,
1411- value = "\n " .join (failed_users [:5 ]) + ("..." if len (failed_users ) > 5 else "" ),
1412- inline = False
1413- )
1414-
1415- await message .edit (embed = embed )
1416-
1417- except Exception as e :
1418- self .logger .error (f"Failed to repair all users: { e } " )
1419- embed = discord .Embed (
1420- title = "❌ Bulk Repair Failed" ,
1421- description = f"An error occurred during bulk repair:\n ```{ str (e )} ```" ,
1422- color = discord .Color .red ()
1423- )
1424- await ctx .reply (embed = embed )
1425-
1426- @commands .command ()
1427- @commands .is_owner ()
1428- async def test (self , ctx ):
1429- """Test command for debugging"""
1430- await ctx .reply ("Admin cog is working!" )
1431-
1269+
14321270async def setup (bot ):
1433- await bot .add_cog (Admin (bot ))
1271+ """Load the Admin cog"""
1272+ await bot .add_cog (Admin (bot ))
0 commit comments