Fix multiple bug et optimisation
This commit is contained in:
parent
b0535af75c
commit
886bfa4b1e
2 changed files with 66 additions and 15 deletions
|
|
@ -121,12 +121,45 @@ class Goodbye(commands.Cog):
|
|||
kuby_logger.error(f"[Goodbye] Police introuvable: {font_path}")
|
||||
raise FileNotFoundError(f"Police introuvable: {font_path}")
|
||||
|
||||
font_large = ImageFont.truetype(font_large_path, 70)
|
||||
font_small = ImageFont.truetype(font_small_path, 50)
|
||||
|
||||
# Dessiner uniquement le nom du serveur (comme pour welcome)
|
||||
display_name = server_name if server_name else "OMEGA KUBE"
|
||||
draw.text((325, 135), display_name, font=font_large, fill=(255,255,255))
|
||||
# Adapter le texte pour éviter les débordements et afficher correctement le nom
|
||||
line1_text = "AU REVOIR"
|
||||
line2_text = username.upper()
|
||||
line3_text = (server_name or "OMEGA KUBE").upper()
|
||||
|
||||
text_area_left = 300
|
||||
text_area_right = background.width - 20
|
||||
text_area_width = text_area_right - text_area_left
|
||||
text_area_center_x = text_area_left + text_area_width // 2
|
||||
|
||||
def fit_font(font_path, text, max_size, max_width):
|
||||
size = max_size
|
||||
while size > 10:
|
||||
font = ImageFont.truetype(font_path, size)
|
||||
bbox = draw.textbbox((0, 0), text, font=font)
|
||||
w = bbox[2] - bbox[0]
|
||||
if w <= max_width:
|
||||
h = bbox[3] - bbox[1]
|
||||
return font, w, h
|
||||
size -= 2
|
||||
font = ImageFont.truetype(font_path, 10)
|
||||
bbox = draw.textbbox((0, 0), text, font=font)
|
||||
return font, bbox[2] - bbox[0], bbox[3] - bbox[1]
|
||||
|
||||
font1, w1, h1 = fit_font(font_large_path, line1_text, 65, text_area_width)
|
||||
font2, w2, h2 = fit_font(font_small_path, line2_text, 38, text_area_width)
|
||||
font3, w3, h3 = fit_font(font_large_path, line3_text, 65, text_area_width)
|
||||
|
||||
spacing_1_2 = 12
|
||||
spacing_2_3 = 12
|
||||
total_height = h1 + spacing_1_2 + h2 + spacing_2_3 + h3
|
||||
start_y = (background.height - total_height) // 2
|
||||
|
||||
y = start_y
|
||||
draw.text((text_area_center_x - w1 // 2, y), line1_text, font=font1, fill=(255, 255, 255))
|
||||
y += h1 + spacing_1_2
|
||||
draw.text((text_area_center_x - w2 // 2, y), line2_text, font=font2, fill=(255, 255, 255))
|
||||
y += h2 + spacing_2_3
|
||||
draw.text((text_area_center_x - w3 // 2, y), line3_text, font=font3, fill=(255, 255, 255))
|
||||
|
||||
# Ajouter l'avatar
|
||||
avatar = Image.open(io.BytesIO(avatar_bytes)).convert("RGBA").resize((224, 224), Image.LANCZOS)
|
||||
|
|
@ -188,9 +221,10 @@ class Goodbye(commands.Cog):
|
|||
|
||||
if img:
|
||||
embed = disnake.Embed(
|
||||
description=f"{member.mention} vient de nous quitter.\n\n{message_text}\n\n⌛ **Avait rejoint :** {joined_message}",
|
||||
color=0x7289DA
|
||||
description=f"{member.mention} vient de nous quitter.\n\n{message_text}",
|
||||
color=0x9B59B6
|
||||
)
|
||||
embed.set_footer(text=f"avait rejoint · {joined_message}")
|
||||
embed.set_image(url="attachment://goodbye.png")
|
||||
await channel.send(embed=embed, file=disnake.File(img, filename="goodbye.png"))
|
||||
kuby_logger.info(f"[Goodbye] Message de départ avec image envoyé pour {member.name}")
|
||||
|
|
@ -198,9 +232,10 @@ class Goodbye(commands.Cog):
|
|||
# Fallback : image non générée
|
||||
kuby_logger.warning(f"[Goodbye] Image non générée pour {member.name}, envoi d'un message texte")
|
||||
embed = disnake.Embed(
|
||||
description=f"{member.mention} vient de nous quitter.\n\n{message_text}\n\n⌛ **Avait rejoint :** {joined_message}",
|
||||
color=0x7289DA
|
||||
description=f"{member.mention} vient de nous quitter.\n\n{message_text}",
|
||||
color=0x9B59B6
|
||||
)
|
||||
embed.set_footer(text=f"avait rejoint · {joined_message}")
|
||||
await channel.send(embed=embed)
|
||||
|
||||
except Exception as e:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue