Refactor ProfileFormatting class to enhance profile display. Simplify color assignment logic, improve layout with a modern design, and streamline the addition of stats and progress information. Update embed creation for better readability and user experience.
Some checks are pending
Run pre-commit / Run pre-commit (push) Waiting to run

This commit is contained in:
Valerie 2025-05-26 04:02:43 -04:00
parent 4b17dfedc3
commit 24aa1e27c9

View file

@ -165,45 +165,57 @@ class ProfileFormatting(MixinMeta):
pdata = conf.prestigedata[profile.prestige]
if conf.use_embeds or self.db.force_embeds:
if profile.statcolor:
color = discord.Color.from_rgb(*utils.string_to_rgb(profile.statcolor))
elif profile.barcolor:
color = discord.Color.from_rgb(*utils.string_to_rgb(profile.barcolor))
elif profile.namecolor:
color = discord.Color.from_rgb(*utils.string_to_rgb(profile.namecolor))
else:
# Default to ruby color if no custom color is set
# Use member's color if available, otherwise use ruby red
color = member.color
if color == discord.Color.default():
color = discord.Color.from_rgb(155, 17, 30) # Ruby red
# Create a clean, modern layout
description = []
# Add server score/rank info
if stat is not None:
description.append(f"Server Score: **{humanize_number(current_xp)}** (Rank #{stat})")
# Add level progress bar
progress_perc = (progress / current_diff) * 100
filled_blocks = int(progress_perc / 10)
progress_bar = "" * filled_blocks + "" * (10 - filled_blocks)
description.append(f"\n{progress_bar} {progress_perc:.1f}%")
description.append(f"**{humanize_number(progress)}**/**{humanize_number(current_diff)}** XP until level {profile.level + 1}")
# Add stats in a clean format
stats = []
if profile.prestige and profile.prestige in conf.prestigedata:
pdata = conf.prestigedata[profile.prestige]
stats.append(f"{trophy} Prestige {humanize_number(profile.prestige)} {pdata.emoji_string}")
stats.append(f"{level} Level {humanize_number(profile.level)}")
stats.append(f"{star} {humanize_number(profile.stars)} stars")
stats.append(f"{chat} {humanize_number(profile.messages)} messages")
stats.append(f"{mic} {utils.humanize_delta(profile.voice)} voice time")
# Create a cleaner layout with emojis and values aligned
txt = ""
txt += f"{level} **Level {humanize_number(profile.level)}**\n"
if pdata:
txt += f"{trophy} **Prestige {humanize_number(profile.prestige)}** {pdata.emoji_string}\n"
txt += f"{star} **{humanize_number(profile.stars)}** stars\n"
txt += f"{chat} **{humanize_number(profile.messages)}** messages sent\n"
txt += f"{mic} **{utils.humanize_delta(profile.voice)}** in voice\n"
progress_txt = f"{bulb} **{humanize_number(progress)}/{humanize_number(current_diff)}**"
txt += f"{progress_txt} XP (**{humanize_number(current_xp)}** total)\n"
if conf.showbal:
balance = await bank.get_balance(member)
creditname = await bank.get_currency_name(guild)
txt += f"{money} **{humanize_number(balance)}** {creditname}\n"
stats.append(f"{money} {humanize_number(balance)} {creditname}")
embed = discord.Embed(description=txt, color=color)
description.append("\n" + "\n".join(stats))
embed = discord.Embed(
description="\n".join(description),
color=color
)
# Set author with member info
display_name = member.display_name if profile.show_displayname else member.name
embed.set_author(
name=_("{}'s Profile").format(member.display_name if profile.show_displayname else member.name),
icon_url=member.display_avatar,
name=f"{display_name}'s Profile",
icon_url=member.display_avatar.url
)
embed.set_footer(
text=_("Rank {}, with {}% of the total server Exp").format(
humanize_number(stat["position"]), round(stat["percent"], 1)
),
icon_url=guild.icon,
)
# Make the progress bar more visually appealing
bar = box(bar.replace("", "").replace("", ""), lang="")
embed.add_field(name=_("Level Progress"), value=bar, inline=False)
# Add member ID as footer
embed.set_footer(text=f"ID: {member.id}")
return embed
kwargs = {