Fix LogView header section

This commit is contained in:
Codex 2025-06-06 06:59:57 +00:00 committed by Slipstream
parent 57a535358d
commit 7c7c53bf01
Signed by: slipstream
GPG Key ID: 13E498CE010AC6FD

View File

@ -116,15 +116,23 @@ class LoggingCog(commands.Cog):
self.container = ui.Container(accent_colour=color)
self.add_item(self.container)
self.header_section = ui.Section()
title_display = ui.TextDisplay(f"**{title}**")
desc_display = ui.TextDisplay(description) if description else None
self.header_items: list[ui.TextDisplay] = [title_display]
if desc_display:
self.header_items.append(desc_display)
self.header_section: Optional[ui.Section] = None
if author is not None:
self.header_section.accessory = ui.Thumbnail(
media=author.display_avatar.url
self.header_section = ui.Section(
accessory=ui.Thumbnail(media=author.display_avatar.url)
)
self.header_section.add_item(ui.TextDisplay(f"**{title}**"))
if description:
self.header_section.add_item(ui.TextDisplay(description))
self.container.add_item(self.header_section)
for item in self.header_items:
self.header_section.add_item(item)
self.container.add_item(self.header_section)
else:
for item in self.header_items:
self.container.add_item(item)
self.container.add_item(
ui.Separator(spacing=discord.SeparatorSpacing.small)
)
@ -147,8 +155,24 @@ class LoggingCog(commands.Cog):
self.content_container.add_item(ui.TextDisplay(f"**{name}:** {value}"))
def set_author(self, user: discord.abc.User) -> None:
"""Update the header with a user thumbnail and footer with the ID."""
self.header_section.accessory = ui.Thumbnail(media=user.display_avatar.url)
"""Add or update the thumbnail and append the user ID to the footer."""
if self.header_section is None:
self.header_section = ui.Section(
accessory=ui.Thumbnail(media=user.display_avatar.url)
)
for item in self.header_items:
self.container.remove_item(item)
self.header_section.add_item(item)
# Insert at the beginning to keep layout consistent
if hasattr(self.container, "children"):
self.container.children.insert(0, self.header_section)
else:
self.container.add_item(self.header_section)
else:
self.header_section.accessory = ui.Thumbnail(
media=user.display_avatar.url
)
if "User ID:" not in self.footer_display.content:
self.footer_display.content += f" | User ID: {user.id}"
@ -617,11 +641,9 @@ class LoggingCog(commands.Cog):
title="🧵 Thread Created",
description=f"Thread {thread.mention} (`{thread.name}`) created in {thread.parent.mention}.",
color=discord.Color.dark_blue(),
# Creator might be available via thread.owner_id or audit log
author=thread.owner if thread.owner else None,
footer=f"Thread ID: {thread.id} | Parent ID: {thread.parent_id}",
)
if thread.owner: # Sometimes owner isn't cached immediately
embed.set_author(thread.owner)
await self._send_log_embed(guild, embed)
@commands.Cog.listener()