This commit is contained in:
Slipstream 2025-06-05 23:32:08 -06:00
commit 950e7dff10
Signed by: slipstream
GPG Key ID: 13E498CE010AC6FD

View File

@ -1,6 +1,6 @@
import discord
from discord.ext import commands, tasks
from discord import AllowedMentions
from discord import AllowedMentions, ui
import datetime
import asyncio
import aiohttp # Added for webhook sending
@ -93,8 +93,8 @@ class LoggingCog(commands.Cog):
self.start_audit_log_poller_when_ready()
) # Keep this for initial start
class LogView(discord.Embed):
"""Embed wrapper used for logging messages."""
class LogView(ui.LayoutView):
"""View used for logging messages."""
def __init__(
self,
@ -105,14 +105,34 @@ class LoggingCog(commands.Cog):
author: Optional[discord.abc.User],
footer: Optional[str],
) -> None:
super().__init__(title=title, description=description, color=color)
super().__init__(timeout=None)
self.container = ui.Container(accent_colour=color)
self.add_item(self.container)
if author is not None:
self.set_author(name=author.display_name, icon_url=author.display_avatar.url)
header = ui.Section(
accessory=ui.Thumbnail(media=author.display_avatar.url)
)
else:
header = ui.Section()
header.add_item(ui.TextDisplay(f"**{title}**"))
if description:
header.add_item(ui.TextDisplay(description))
self.container.add_item(header)
self.container.add_item(
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.set_footer(text=footer_text)
self.footer_display = ui.TextDisplay(footer_text)
self.container.add_item(self.footer_display)
def add_field(self, name: str, value: str, inline: bool = False) -> None:
self.container.add_item(ui.TextDisplay(f"**{name}:** {value}"))
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
@ -183,7 +203,7 @@ class LoggingCog(commands.Cog):
await self.session.close()
log.info("aiohttp ClientSession closed for LoggingCog.")
async def _send_log_embed(self, guild: discord.Guild, embed: discord.Embed) -> None:
async def _send_log_embed(self, guild: discord.Guild, embed: ui.LayoutView) -> None:
"""Sends the log view via the configured webhook for the guild."""
if not self.session or self.session.closed:
log.error(
@ -204,7 +224,7 @@ class LoggingCog(commands.Cog):
client=self.bot,
)
await webhook.send(
embed=embed,
view=embed,
username=f"{self.bot.user.name} Logs",
avatar_url=self.bot.user.display_avatar.url,
allowed_mentions=AllowedMentions.none(),
@ -240,13 +260,13 @@ class LoggingCog(commands.Cog):
color: discord.Color = discord.Color.blue(),
author: Optional[Union[discord.User, discord.Member]] = None,
footer: Optional[str] = None,
) -> discord.Embed:
"""Creates a standardized log embed."""
) -> ui.LayoutView:
"""Creates a standardized log view."""
return self.LogView(self.bot, title, description, color, author, footer)
def _add_id_footer(
self,
embed: discord.Embed,
embed: ui.LayoutView,
obj: Union[
discord.Member,
discord.User,
@ -262,12 +282,10 @@ class LoggingCog(commands.Cog):
"""Adds an ID to the footer text if possible."""
target_id = obj_id or (obj.id if obj else None)
if target_id:
existing_footer = embed.footer.text or ""
separator = " | " if existing_footer else ""
embed.set_footer(
text=f"{existing_footer}{separator}{id_name}: {target_id}",
icon_url=embed.footer.icon_url,
)
existing_footer = getattr(embed, "footer_display", None)
if existing_footer:
sep = " | " if existing_footer.content else ""
existing_footer.content += f"{sep}{id_name}: {target_id}"
async def _check_log_enabled(self, guild_id: int, event_key: str) -> bool:
"""Checks if logging is enabled for a specific event key in a guild."""