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.container = ui.Container(accent_colour=color)
|
||||||
self.add_item(self.container)
|
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:
|
if author is not None:
|
||||||
header = ui.Section(
|
self.header_section = ui.Section(
|
||||||
accessory=ui.Thumbnail(media=author.display_avatar.url)
|
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:
|
else:
|
||||||
header = ui.Section()
|
for item in self.header_items:
|
||||||
|
self.container.add_item(item)
|
||||||
header.add_item(ui.TextDisplay(f"**{title}**"))
|
|
||||||
if description:
|
|
||||||
header.add_item(ui.TextDisplay(description))
|
|
||||||
self.container.add_item(header)
|
|
||||||
self.container.add_item(
|
self.container.add_item(
|
||||||
ui.Separator(spacing=discord.SeparatorSpacing.small)
|
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:
|
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:
|
||||||
|
"""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:
|
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 +566,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 +611,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()
|
||||||
@ -613,13 +640,9 @@ class LoggingCog(commands.Cog):
|
|||||||
title="🧵 Thread Created",
|
title="🧵 Thread Created",
|
||||||
description=f"Thread {thread.mention} (`{thread.name}`) created in {thread.parent.mention}.",
|
description=f"Thread {thread.mention} (`{thread.name}`) created in {thread.parent.mention}.",
|
||||||
color=discord.Color.dark_blue(),
|
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}",
|
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)
|
await self._send_log_embed(guild, embed)
|
||||||
|
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user