Merge branch 'master' of https://git.slipstreamm.dev/discordbot
This commit is contained in:
commit
f3e7727e24
@ -77,25 +77,35 @@ class LoggingCog(commands.Cog):
|
|||||||
self.header.add_item(ui.TextDisplay(description))
|
self.header.add_item(ui.TextDisplay(description))
|
||||||
self.container.add_item(self.header)
|
self.container.add_item(self.header)
|
||||||
|
|
||||||
# Section to hold log fields with no accessory. The API requires a
|
# Placeholder for future field sections. They are inserted before
|
||||||
# valid component type, so use a disabled button with an invisible
|
# the separator when the first field is added.
|
||||||
# label as a placeholder accessory.
|
self._field_sections: list[ui.Section] = []
|
||||||
self.fields_section = ui.Section(
|
|
||||||
accessory=ui.Button(label="\u200b", disabled=True)
|
|
||||||
)
|
|
||||||
self.container.add_item(self.fields_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}" + (
|
footer_text = footer or f"Bot ID: {bot.user.id}" + (
|
||||||
f" | User ID: {author.id}" if author else "")
|
f" | User ID: {author.id}" if author else "")
|
||||||
self.footer_display = ui.TextDisplay(footer_text)
|
self.footer_display = ui.TextDisplay(footer_text)
|
||||||
|
|
||||||
|
self.container.add_item(self.separator)
|
||||||
self.container.add_item(self.footer_display)
|
self.container.add_item(self.footer_display)
|
||||||
|
|
||||||
# --- Compatibility helpers ---
|
# --- Compatibility helpers ---
|
||||||
def add_field(self, name: str, value: str, inline: bool = False):
|
def add_field(self, name: str, value: str, inline: bool = False):
|
||||||
"""Mimic Embed.add_field by appending a bolded name/value line."""
|
"""Mimic Embed.add_field by appending a bolded name/value line."""
|
||||||
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):
|
def set_footer(self, text: str):
|
||||||
"""Mimic Embed.set_footer by replacing the footer text display."""
|
"""Mimic Embed.set_footer by replacing the footer text display."""
|
||||||
@ -295,12 +305,16 @@ class LoggingCog(commands.Cog):
|
|||||||
await ctx.send(f"✅ Successfully configured logging to send messages to {channel.mention} via the new webhook `{new_webhook.name}`.")
|
await ctx.send(f"✅ Successfully configured logging to send messages to {channel.mention} via the new webhook `{new_webhook.name}`.")
|
||||||
# Test send (optional)
|
# Test send (optional)
|
||||||
try:
|
try:
|
||||||
test_embed = self._create_log_embed(
|
test_view = self._create_log_embed(
|
||||||
"✅ Logging Setup Complete",
|
"✅ Logging Setup Complete",
|
||||||
f"Logs will now be sent to this channel via the webhook `{new_webhook.name}`.",
|
f"Logs will now be sent to this channel via the webhook `{new_webhook.name}`.",
|
||||||
color=discord.Color.green(),
|
color=discord.Color.green(),
|
||||||
)
|
)
|
||||||
await new_webhook.send(view=test_embed, username=webhook_name, avatar_url=self.bot.user.display_avatar.url)
|
await new_webhook.send(
|
||||||
|
view=test_view,
|
||||||
|
username=webhook_name,
|
||||||
|
avatar_url=self.bot.user.display_avatar.url,
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error(f"Failed to send test message via new webhook for guild {guild.id}: {e}")
|
log.error(f"Failed to send test message via new webhook for guild {guild.id}: {e}")
|
||||||
await ctx.send("⚠️ Could not send a test message via the new webhook, but the URL has been saved.")
|
await ctx.send("⚠️ Could not send a test message via the new webhook, but the URL has been saved.")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user