Applying previous commit.
This commit is contained in:
parent
92746ac51f
commit
c2a99d6629
@ -116,17 +116,23 @@ class LoggingCog(commands.Cog):
|
||||
self.container = ui.Container(accent_colour=color)
|
||||
self.add_item(self.container)
|
||||
|
||||
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:
|
||||
header = ui.Section(
|
||||
self.header_section = ui.Section(
|
||||
accessory=ui.Thumbnail(media=author.display_avatar.url)
|
||||
)
|
||||
for item in self.header_items:
|
||||
self.header_section.add_item(item)
|
||||
self.container.add_item(self.header_section)
|
||||
else:
|
||||
header = ui.Section()
|
||||
|
||||
header.add_item(ui.TextDisplay(f"**{title}**"))
|
||||
if description:
|
||||
header.add_item(ui.TextDisplay(description))
|
||||
self.container.add_item(header)
|
||||
for item in self.header_items:
|
||||
self.container.add_item(item)
|
||||
self.container.add_item(
|
||||
ui.Separator(spacing=discord.SeparatorSpacing.small)
|
||||
)
|
||||
@ -148,6 +154,27 @@ class LoggingCog(commands.Cog):
|
||||
def add_field(self, name: str, value: str, inline: bool = False) -> None:
|
||||
self.content_container.add_item(ui.TextDisplay(f"**{name}:** {value}"))
|
||||
|
||||
def set_author(self, user: discord.abc.User) -> None:
|
||||
"""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}"
|
||||
|
||||
def _user_display(self, user: Union[discord.Member, discord.User]) -> str:
|
||||
"""Return display name, username and ID string for a user."""
|
||||
display = user.display_name if isinstance(user, discord.Member) else user.name
|
||||
@ -539,44 +566,38 @@ class LoggingCog(commands.Cog):
|
||||
guild_id = ctx.guild.id
|
||||
toggles = await settings_manager.get_all_log_event_toggles(guild_id)
|
||||
|
||||
embed = discord.Embed(
|
||||
title=f"Logging Status for {ctx.guild.name}", color=discord.Color.blue()
|
||||
)
|
||||
lines = []
|
||||
for key in ALL_EVENT_KEYS:
|
||||
# Get status, defaulting to True if not explicitly in the DB/cache map
|
||||
is_enabled = toggles.get(key, True)
|
||||
status_emoji = "✅" if is_enabled else "❌"
|
||||
lines.append(f"{status_emoji} `{key}`")
|
||||
|
||||
# Paginate if too long for one embed description
|
||||
description = ""
|
||||
for line in lines:
|
||||
if (
|
||||
len(description) + len(line) + 1 > 4000
|
||||
): # Embed description limit (approx)
|
||||
embed.description = description
|
||||
await ctx.send(embed=embed, allowed_mentions=AllowedMentions.none())
|
||||
description = line + "\n" # Start new description
|
||||
embed = discord.Embed(
|
||||
color=discord.Color.blue()
|
||||
) # New embed for continuation
|
||||
if len(description) + len(line) + 1 > 4000:
|
||||
view = self._create_log_embed(
|
||||
title=f"Logging Status for {ctx.guild.name}",
|
||||
description=description.strip(),
|
||||
color=discord.Color.blue(),
|
||||
)
|
||||
await ctx.send(view=view, allowed_mentions=AllowedMentions.none())
|
||||
description = line + "\n"
|
||||
else:
|
||||
description += line + "\n"
|
||||
|
||||
if description: # Send the last embed page
|
||||
embed.description = description.strip()
|
||||
await ctx.send(embed=embed, allowed_mentions=AllowedMentions.none())
|
||||
if description:
|
||||
view = self._create_log_embed(
|
||||
title=f"Logging Status for {ctx.guild.name}",
|
||||
description=description.strip(),
|
||||
color=discord.Color.blue(),
|
||||
)
|
||||
await ctx.send(view=view, allowed_mentions=AllowedMentions.none())
|
||||
|
||||
@log_group.command(name="list_keys")
|
||||
async def log_list_keys(self, ctx: commands.Context):
|
||||
"""Lists all valid event keys for use with the 'log toggle' command."""
|
||||
embed = discord.Embed(
|
||||
title="Available Logging Event Keys", color=discord.Color.purple()
|
||||
)
|
||||
keys_text = "\n".join(f"`{key}`" for key in ALL_EVENT_KEYS)
|
||||
|
||||
# Paginate if needed
|
||||
if len(keys_text) > 4000:
|
||||
parts = []
|
||||
current_part = ""
|
||||
@ -590,16 +611,22 @@ class LoggingCog(commands.Cog):
|
||||
if current_part:
|
||||
parts.append(current_part)
|
||||
|
||||
embed.description = parts[0]
|
||||
await ctx.send(embed=embed, allowed_mentions=AllowedMentions.none())
|
||||
for part in parts[1:]:
|
||||
await ctx.send(
|
||||
embed=discord.Embed(description=part, color=discord.Color.purple()),
|
||||
allowed_mentions=AllowedMentions.none(),
|
||||
first = True
|
||||
for part in parts:
|
||||
view = self._create_log_embed(
|
||||
title="Available Logging Event Keys" if first else "",
|
||||
description=part.strip(),
|
||||
color=discord.Color.purple(),
|
||||
)
|
||||
await ctx.send(view=view, allowed_mentions=AllowedMentions.none())
|
||||
first = False
|
||||
else:
|
||||
embed.description = keys_text
|
||||
await ctx.send(embed=embed, allowed_mentions=AllowedMentions.none())
|
||||
view = self._create_log_embed(
|
||||
title="Available Logging Event Keys",
|
||||
description=keys_text,
|
||||
color=discord.Color.purple(),
|
||||
)
|
||||
await ctx.send(view=view, allowed_mentions=AllowedMentions.none())
|
||||
|
||||
# --- Thread Events ---
|
||||
@commands.Cog.listener()
|
||||
@ -613,13 +640,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(
|
||||
name=str(thread.owner), icon_url=thread.owner.display_avatar.url
|
||||
)
|
||||
await self._send_log_embed(guild, embed)
|
||||
|
||||
@commands.Cog.listener()
|
||||
|
Loading…
x
Reference in New Issue
Block a user