Discord-Raid-bot/cogs/mystats.py

99 lines
4.4 KiB
Python
Raw Normal View History

2025-08-26 17:35:54 +00:00
# -*- coding: utf-8 -*-
2025-08-22 13:25:34 +00:00
import discord
from discord.ext import commands
from config import AUTHORIZED_CHANNEL_ID, BOSS_CONFIG
from utils.helpers import format_damage_display, format_date_only
2025-08-28 12:24:06 +00:00
from utils.pb_handler import db_manager # Assurez-vous que db_manager est initialisé correctement
2025-08-22 13:25:34 +00:00
class MyStats(commands.Cog):
2025-08-26 17:35:54 +00:00
"""Cog pour afficher tous les PB d'un utilisateur"""
2025-08-22 13:25:34 +00:00
def __init__(self, bot):
self.bot = bot
@commands.command(name="mystats")
async def mystats(self, ctx, *, target_user: str = None):
2025-08-28 12:24:06 +00:00
"""Affiche tous les PB d'un utilisateur avec les nouvelles difficultés"""
2025-08-22 13:25:34 +00:00
if ctx.channel.id != AUTHORIZED_CHANNEL_ID:
return
2025-08-26 17:35:54 +00:00
2025-08-22 13:25:34 +00:00
try:
if target_user:
matches = db_manager.find_user_by_name(target_user)
if not matches:
await ctx.send(f"❌ No data found for **{target_user}**.")
return
if len(matches) > 1:
await ctx.send(f"⚠️ Multiple users found for **{target_user}**. Please be more specific.")
return
user_id, display_name = matches[0]
else:
user_id = ctx.author.id
display_name = ctx.author.display_name
user_data = db_manager.get_user_all_pbs(user_id)
2025-08-26 17:35:54 +00:00
2025-08-22 13:25:34 +00:00
if not user_data:
await ctx.send(f"❌ No data found for **{display_name}**.")
2025-08-22 13:25:34 +00:00
return
2025-08-26 17:35:54 +00:00
2025-08-22 13:25:34 +00:00
embed = discord.Embed(
title=f"📊 {display_name}'s Complete Stats",
2025-08-22 13:25:34 +00:00
color=0x00bfff
)
2025-08-26 17:35:54 +00:00
2025-08-28 12:24:06 +00:00
# Hydra - toutes les difficultés
2025-08-22 13:25:34 +00:00
hydra_stats = []
for difficulty in BOSS_CONFIG['hydra']['difficulties']:
pb_key = f'pb_hydra_{difficulty}'
date_key = f'pb_hydra_{difficulty}_date'
2025-08-26 17:35:54 +00:00
2025-08-22 13:25:34 +00:00
if pb_key in user_data and user_data[pb_key] > 0:
pb_value = user_data[pb_key]
pb_date = user_data.get(date_key)
2025-08-28 12:24:06 +00:00
date_text = f"{format_date_only(pb_date)}" if pb_date else ""
2025-08-22 13:25:34 +00:00
hydra_stats.append(f"**{difficulty.title()}:** {format_damage_display(pb_value)}{date_text}")
2025-08-26 17:35:54 +00:00
2025-08-22 13:25:34 +00:00
hydra_text = "\n".join(hydra_stats) if hydra_stats else "No records"
2025-08-28 12:24:06 +00:00
embed.add_field(name="⚔️ Hydra PBs", value=hydra_text, inline=False)
2025-08-26 17:35:54 +00:00
2025-08-28 12:24:06 +00:00
# Chimera - toutes les difficultés
2025-08-22 13:25:34 +00:00
chimera_stats = []
for difficulty in BOSS_CONFIG['chimera']['difficulties']:
pb_key = f'pb_chimera_{difficulty}'
date_key = f'pb_chimera_{difficulty}_date'
2025-08-26 17:35:54 +00:00
2025-08-22 13:25:34 +00:00
if pb_key in user_data and user_data[pb_key] > 0:
pb_value = user_data[pb_key]
pb_date = user_data.get(date_key)
2025-08-28 12:24:06 +00:00
date_text = f"{format_date_only(pb_date)}" if pb_date else ""
2025-08-22 13:25:34 +00:00
display_name = "Ultra Nightmare" if difficulty == "ultra" else difficulty.title()
chimera_stats.append(f"**{display_name}:** {format_damage_display(pb_value)}{date_text}")
2025-08-26 17:35:54 +00:00
2025-08-22 13:25:34 +00:00
chimera_text = "\n".join(chimera_stats) if chimera_stats else "No records"
2025-08-28 12:24:06 +00:00
embed.add_field(name="🛡️ Chimera PBs", value=chimera_text, inline=False)
2025-08-26 17:35:54 +00:00
2025-08-22 13:25:34 +00:00
# CvC
cvc_pb = user_data.get('pb_cvc', 0)
cvc_date = user_data.get('pb_cvc_date')
cvc_text = f"**{format_damage_display(cvc_pb)} damage**" if cvc_pb > 0 else "No record"
if cvc_pb > 0 and cvc_date:
formatted_date = format_date_only(cvc_date)
if formatted_date:
2025-08-28 12:24:06 +00:00
cvc_text += f"{formatted_date}"
embed.add_field(name="🗡️ CvC PB", value=cvc_text, inline=False)
2025-08-26 17:35:54 +00:00
2025-08-28 12:24:06 +00:00
# Total combiné
2025-08-26 17:35:54 +00:00
total_damage = sum(user_data.get(f'pb_hydra_{d}', 0) for d in BOSS_CONFIG['hydra']['difficulties'])
total_damage += sum(user_data.get(f'pb_chimera_{d}', 0) for d in BOSS_CONFIG['chimera']['difficulties'])
2025-08-22 13:25:34 +00:00
total_damage += user_data.get('pb_cvc', 0)
2025-08-28 12:24:06 +00:00
embed.add_field(name="💯 Total Combined Damage", value=f"**{format_damage_display(total_damage)}**", inline=False)
2025-08-26 17:35:54 +00:00
2025-08-22 13:25:34 +00:00
await ctx.send(embed=embed)
2025-08-26 17:35:54 +00:00
except Exception as e:
2025-08-28 12:24:06 +00:00
await ctx.send(f"❌ Error: {e}")
2025-08-22 13:25:34 +00:00
2025-08-25 16:09:37 +00:00
async def setup(bot):
await bot.add_cog(MyStats(bot))