Applying previous commit.

This commit is contained in:
Slipstream 2025-06-06 06:53:43 +00:00
parent 92746ac51f
commit 57a535358d
Signed by: slipstream
GPG Key ID: 13E498CE010AC6FD

View File

@ -116,17 +116,15 @@ class LoggingCog(commands.Cog):
self.container = ui.Container(accent_colour=color) self.container = ui.Container(accent_colour=color)
self.add_item(self.container) self.add_item(self.container)
self.header_section = ui.Section()
if author is not None: if author is not None:
header = ui.Section( self.header_section.accessory = ui.Thumbnail(
accessory=ui.Thumbnail(media=author.display_avatar.url) media=author.display_avatar.url
) )
else: self.header_section.add_item(ui.TextDisplay(f"**{title}**"))
header = ui.Section()
header.add_item(ui.TextDisplay(f"**{title}**"))
if description: if description:
header.add_item(ui.TextDisplay(description)) self.header_section.add_item(ui.TextDisplay(description))
self.container.add_item(header) self.container.add_item(self.header_section)
self.container.add_item( self.container.add_item(
ui.Separator(spacing=discord.SeparatorSpacing.small) ui.Separator(spacing=discord.SeparatorSpacing.small)
) )
@ -148,6 +146,12 @@ class LoggingCog(commands.Cog):
def add_field(self, name: str, value: str, inline: bool = False) -> None: def add_field(self, name: str, value: str, inline: bool = False) -> None:
self.content_container.add_item(ui.TextDisplay(f"**{name}:** {value}")) 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)
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: def _user_display(self, user: Union[discord.Member, discord.User]) -> str:
"""Return display name, username and ID string for a user.""" """Return display name, username and ID string for a user."""
display = user.display_name if isinstance(user, discord.Member) else user.name display = user.display_name if isinstance(user, discord.Member) else user.name
@ -539,44 +543,38 @@ class LoggingCog(commands.Cog):
guild_id = ctx.guild.id guild_id = ctx.guild.id
toggles = await settings_manager.get_all_log_event_toggles(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 = [] lines = []
for key in ALL_EVENT_KEYS: 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) is_enabled = toggles.get(key, True)
status_emoji = "" if is_enabled else "" status_emoji = "" if is_enabled else ""
lines.append(f"{status_emoji} `{key}`") lines.append(f"{status_emoji} `{key}`")
# Paginate if too long for one embed description
description = "" description = ""
for line in lines: for line in lines:
if ( if len(description) + len(line) + 1 > 4000:
len(description) + len(line) + 1 > 4000 view = self._create_log_embed(
): # Embed description limit (approx) title=f"Logging Status for {ctx.guild.name}",
embed.description = description description=description.strip(),
await ctx.send(embed=embed, allowed_mentions=AllowedMentions.none()) color=discord.Color.blue(),
description = line + "\n" # Start new description )
embed = discord.Embed( await ctx.send(view=view, allowed_mentions=AllowedMentions.none())
color=discord.Color.blue() description = line + "\n"
) # New embed for continuation
else: else:
description += line + "\n" description += line + "\n"
if description: # Send the last embed page if description:
embed.description = description.strip() view = self._create_log_embed(
await ctx.send(embed=embed, allowed_mentions=AllowedMentions.none()) 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") @log_group.command(name="list_keys")
async def log_list_keys(self, ctx: commands.Context): async def log_list_keys(self, ctx: commands.Context):
"""Lists all valid event keys for use with the 'log toggle' command.""" """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) keys_text = "\n".join(f"`{key}`" for key in ALL_EVENT_KEYS)
# Paginate if needed
if len(keys_text) > 4000: if len(keys_text) > 4000:
parts = [] parts = []
current_part = "" current_part = ""
@ -590,16 +588,22 @@ class LoggingCog(commands.Cog):
if current_part: if current_part:
parts.append(current_part) parts.append(current_part)
embed.description = parts[0] first = True
await ctx.send(embed=embed, allowed_mentions=AllowedMentions.none()) for part in parts:
for part in parts[1:]: view = self._create_log_embed(
await ctx.send( title="Available Logging Event Keys" if first else "",
embed=discord.Embed(description=part, color=discord.Color.purple()), description=part.strip(),
allowed_mentions=AllowedMentions.none(), color=discord.Color.purple(),
) )
await ctx.send(view=view, allowed_mentions=AllowedMentions.none())
first = False
else: else:
embed.description = keys_text view = self._create_log_embed(
await ctx.send(embed=embed, allowed_mentions=AllowedMentions.none()) title="Available Logging Event Keys",
description=keys_text,
color=discord.Color.purple(),
)
await ctx.send(view=view, allowed_mentions=AllowedMentions.none())
# --- Thread Events --- # --- Thread Events ---
@commands.Cog.listener() @commands.Cog.listener()
@ -617,9 +621,7 @@ class LoggingCog(commands.Cog):
footer=f"Thread ID: {thread.id} | Parent ID: {thread.parent_id}", footer=f"Thread ID: {thread.id} | Parent ID: {thread.parent_id}",
) )
if thread.owner: # Sometimes owner isn't cached immediately if thread.owner: # Sometimes owner isn't cached immediately
embed.set_author( embed.set_author(thread.owner)
name=str(thread.owner), icon_url=thread.owner.display_avatar.url
)
await self._send_log_embed(guild, embed) await self._send_log_embed(guild, embed)
@commands.Cog.listener() @commands.Cog.listener()