fix log view sections

This commit is contained in:
Codex 2025-06-05 20:49:50 +00:00 committed by Slipstream
parent d38cc6a2a2
commit e2806adfa2
Signed by: slipstream
GPG Key ID: 13E498CE010AC6FD

View File

@ -77,33 +77,35 @@ class LoggingCog(commands.Cog):
self.header.add_item(ui.TextDisplay(description))
self.container.add_item(self.header)
# Section to hold log fields with no accessory. The API requires at
# least one child component, so include an empty text display that
# will be removed when actual fields are added. A disabled button is
# used as the accessory to satisfy Discord's component validation.
self.fields_section = ui.Section(
accessory=ui.Button(label="\u200b", disabled=True)
)
self._fields_placeholder = ui.TextDisplay("\u200b")
self.fields_section.add_item(self._fields_placeholder)
self.container.add_item(self.fields_section)
# Placeholder for future field sections. They are inserted before
# the separator when the first field is added.
self._field_sections: list[ui.Section] = []
self.container.add_item(ui.Separator(spacing=discord.SeparatorSpacing.small))
self.separator = ui.Separator(spacing=discord.SeparatorSpacing.small)
footer_text = footer or f"Bot ID: {bot.user.id}" + (
f" | User ID: {author.id}" if author else "")
self.footer_display = ui.TextDisplay(footer_text)
self.container.add_item(self.separator)
self.container.add_item(self.footer_display)
# --- Compatibility helpers ---
def add_field(self, name: str, value: str, inline: bool = False):
"""Mimic Embed.add_field by appending a bolded name/value line."""
if (
hasattr(self, "_fields_placeholder")
and self._fields_placeholder in self.fields_section.children
):
self.fields_section.remove_item(self._fields_placeholder)
self.fields_section.add_item(ui.TextDisplay(f"**{name}:** {value}"))
if not self._field_sections or len(self._field_sections[-1].children) >= 3:
section = ui.Section(accessory=ui.Button(label="\u200b", disabled=True))
self._insert_field_section(section)
self._field_sections.append(section)
self._field_sections[-1].add_item(ui.TextDisplay(f"**{name}:** {value}"))
def _insert_field_section(self, section: ui.Section) -> None:
"""Insert a field section before the footer separator."""
self.container.remove_item(self.separator)
self.container.remove_item(self.footer_display)
self.container.add_item(section)
self.container.add_item(self.separator)
self.container.add_item(self.footer_display)
def set_footer(self, text: str):
"""Mimic Embed.set_footer by replacing the footer text display."""