fix: mystats username lookup and multi-word name support
All checks were successful
Deploy Bot on NAS / deploy (push) Successful in 25s
All checks were successful
Deploy Bot on NAS / deploy (push) Successful in 25s
- Résolution du nom via find_user_by_name avant get_user_all_pbs (l'ancien code passait le nom en guise de discord_id → aucun résultat) - Affichage du nom de la cible dans le titre de l'embed - * pour capturer les noms avec espaces Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
314483e4f5
commit
e364f354b0
1 changed files with 17 additions and 5 deletions
|
|
@ -12,21 +12,33 @@ class MyStats(commands.Cog):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
@commands.command(name="mystats")
|
@commands.command(name="mystats")
|
||||||
async def mystats(self, ctx, target_user: str = None):
|
async def mystats(self, ctx, *, target_user: str = None):
|
||||||
"""Affiche tous les PB d'un utilisateur avec les nouvelles difficultés"""
|
"""Affiche tous les PB d'un utilisateur avec les nouvelles difficultés"""
|
||||||
if ctx.channel.id != AUTHORIZED_CHANNEL_ID:
|
if ctx.channel.id != AUTHORIZED_CHANNEL_ID:
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
username = target_user if target_user else ctx.author.id
|
if target_user:
|
||||||
user_data = db_manager.get_user_all_pbs(username)
|
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)
|
||||||
|
|
||||||
if not user_data:
|
if not user_data:
|
||||||
await ctx.send(f"❌ No data found for **{ctx.author.display_name}**.")
|
await ctx.send(f"❌ No data found for **{display_name}**.")
|
||||||
return
|
return
|
||||||
|
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title=f"📊 {ctx.author.display_name}'s Complete Stats",
|
title=f"📊 {display_name}'s Complete Stats",
|
||||||
color=0x00bfff
|
color=0x00bfff
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue