From 30796652253319c4cbec3149bc759a3f9e48a889 Mon Sep 17 00:00:00 2001 From: Codex Date: Thu, 5 Jun 2025 21:28:47 +0000 Subject: [PATCH 1/2] fix logging webhook --- cogs/logging_cog.py | 120 ++++++++++++++++---------------------------- 1 file changed, 43 insertions(+), 77 deletions(-) diff --git a/cogs/logging_cog.py b/cogs/logging_cog.py index 2d70641..13299b2 100644 --- a/cogs/logging_cog.py +++ b/cogs/logging_cog.py @@ -1,6 +1,5 @@ import discord from discord.ext import commands, tasks -from discord import ui import datetime import asyncio import aiohttp # Added for webhook sending @@ -55,70 +54,6 @@ class LoggingCog(commands.Cog): else: asyncio.create_task(self.start_audit_log_poller_when_ready()) # Keep this for initial start - class LogView(ui.LayoutView): - """Simple view for log messages with helper methods.""" - - def __init__(self, bot: commands.Bot, title: str, description: str, - color: discord.Color, author: Optional[discord.abc.User], - footer: Optional[str]): - super().__init__(timeout=None) - self.container = ui.Container(accent_colour=color) - self.add_item(self.container) - - self.header = ui.Section( - accessory=( - ui.Thumbnail(media=author.display_avatar.url) - if author - else ui.Button(label="\u200b", disabled=True) - ) - ) - self.header.add_item(ui.TextDisplay(f"**{title}**")) - if description: - self.header.add_item(ui.TextDisplay(description)) - self.container.add_item(self.header) - - # Placeholder for future field sections. They are inserted before - # the separator when the first field is added. - self._field_sections: list[ui.Section] = [] - - self.separator = 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.footer_display = ui.TextDisplay(footer_text) - - self.container.add_item(self.separator) - self.container.add_item(self.footer_display) - - # --- Compatibility helpers --- - def add_field(self, name: str, value: str, inline: bool = False): - """Mimic Embed.add_field by appending a bolded name/value line.""" - 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): - """Mimic Embed.set_footer by replacing the footer text display.""" - self.footer_display.content = text - - def set_author(self, name: str, icon_url: Optional[str] = None): - """Mimic Embed.set_author by adjusting the header section.""" - self.header.clear_items() - if icon_url: - self.header.accessory = ui.Thumbnail(media=icon_url) - else: - self.header.accessory = ui.Button(label="\u200b", disabled=True) - self.header.add_item(ui.TextDisplay(name)) 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 @@ -174,8 +109,8 @@ 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: ui.LayoutView): - """Sends the log view via the configured webhook for the guild.""" + async def _send_log_embed(self, guild: discord.Guild, embed: discord.Embed) -> None: + """Sends the log embed via the configured webhook for the guild.""" if not self.session or self.session.closed: log.error(f"aiohttp session not available or closed in LoggingCog for guild {guild.id}. Cannot send log.") return @@ -189,7 +124,7 @@ class LoggingCog(commands.Cog): try: webhook = discord.Webhook.from_url(webhook_url, session=self.session) await webhook.send( - view=embed, + embed=embed, username=f"{self.bot.user.name} Logs", avatar_url=self.bot.user.display_avatar.url, ) @@ -210,17 +145,48 @@ class LoggingCog(commands.Cog): log.exception(f"Unexpected error sending log via webhook for guild {guild.id}: {e}") - def _create_log_embed(self, title: str, description: str = "", color: discord.Color = discord.Color.blue(), author: Optional[Union[discord.User, discord.Member]] = None, footer: Optional[str] = None) -> ui.LayoutView: - """Creates a standardized log view.""" - return self.LogView(self.bot, title, description, color, author, footer) + def _create_log_embed( + self, + title: str, + description: str = "", + color: discord.Color = discord.Color.blue(), + author: Optional[Union[discord.User, discord.Member]] = None, + footer: Optional[str] = None, + ) -> discord.Embed: + """Creates a standardized embed for logging.""" + embed = discord.Embed(title=title, description=description, color=color) + if author: + embed.set_author(name=author.display_name, icon_url=author.display_avatar.url) + if footer: + embed.set_footer(text=footer) + else: + footer_text = f"Bot ID: {self.bot.user.id}" + if author: + footer_text += f" | User ID: {author.id}" + embed.set_footer(text=footer_text) + return embed - def _add_id_footer(self, embed: ui.LayoutView, obj: Union[discord.Member, discord.User, discord.Role, discord.abc.GuildChannel, discord.Message, discord.Invite, None] = None, obj_id: Optional[int] = None, id_name: str = "ID"): + def _add_id_footer( + self, + embed: discord.Embed, + obj: Union[ + discord.Member, + discord.User, + discord.Role, + discord.abc.GuildChannel, + discord.Message, + discord.Invite, + None, + ] = None, + obj_id: Optional[int] = None, + id_name: str = "ID", + ) -> None: """Adds an ID to the footer text if possible.""" target_id = obj_id or (obj.id if obj else None) - if target_id and hasattr(embed, "footer_display"): - existing_footer = embed.footer_display.content or "" + if target_id: + existing_footer = embed.footer.text if embed.footer else "" separator = " | " if existing_footer else "" - embed.footer_display.content = f"{existing_footer}{separator}{id_name}: {target_id}" + embed.set_footer(text=f"{existing_footer}{separator}{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.""" @@ -305,13 +271,13 @@ class LoggingCog(commands.Cog): await ctx.send(f"✅ Successfully configured logging to send messages to {channel.mention} via the new webhook `{new_webhook.name}`.") # Test send (optional) try: - test_view = self._create_log_embed( + test_embed = self._create_log_embed( "✅ Logging Setup Complete", f"Logs will now be sent to this channel via the webhook `{new_webhook.name}`.", color=discord.Color.green(), ) await new_webhook.send( - view=test_view, + embed=test_embed, username=webhook_name, avatar_url=self.bot.user.display_avatar.url, ) From 4e035f415135500ad81cdcf2764efb262ea7a1d6 Mon Sep 17 00:00:00 2001 From: Slipstream Date: Thu, 5 Jun 2025 15:34:49 -0600 Subject: [PATCH 2/2] Fix script name in documentation from "tavily.py" to "tavilytool.py" --- AGENTS.md | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 8e18594..4c4bb7f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -9,42 +9,42 @@ - All pip dependencies are installed in the environment. (Except packages related to locally running AI, due to their large size.) - You have the ability to directly push to the git repo over https (url already set). And you should when you finish your task and have tested it. - If you encounter any hard to fix errors when pushing just leave it to the user to fix them. Try fixing merge conflicts/not having work from the remote by yourself. -- You have a python script "tavily.py" in the project root, that you can use to search the web. +- You have a python script "tavilytool.py" in the project root, that you can use to search the web. # Tavily API Script Usage Instructions ## Basic Usage Search for information using simple queries: ```bash -python tavily.py "your search query" +python tavilytool.py "your search query" ``` ## Examples ```bash -python tavily.py "latest AI developments 2024" -python tavily.py "how to make chocolate chip cookies" -python tavily.py "current weather in New York" -python tavily.py "best programming practices Python" +python tavilytool.py "latest AI developments 2024" +python tavilytool.py "how to make chocolate chip cookies" +python tavilytool.py "current weather in New York" +python tavilytool.py "best programming practices Python" ``` ## Advanced Options ### Search Depth -- **Basic search**: `python tavily.py "query"` (default) -- **Advanced search**: `python tavily.py "query" --depth advanced` +- **Basic search**: `python tavilytool.py "query"` (default) +- **Advanced search**: `python tavilytool.py "query" --depth advanced` ### Control Results -- **Limit results**: `python tavily.py "query" --max-results 3` -- **Include images**: `python tavily.py "query" --include-images` -- **Skip AI answer**: `python tavily.py "query" --no-answer` +- **Limit results**: `python tavilytool.py "query" --max-results 3` +- **Include images**: `python tavilytool.py "query" --include-images` +- **Skip AI answer**: `python tavilytool.py "query" --no-answer` ### Domain Filtering -- **Include specific domains**: `python tavily.py "query" --include-domains reddit.com stackoverflow.com` -- **Exclude domains**: `python tavily.py "query" --exclude-domains wikipedia.org` +- **Include specific domains**: `python tavilytool.py "query" --include-domains reddit.com stackoverflow.com` +- **Exclude domains**: `python tavilytool.py "query" --exclude-domains wikipedia.org` ### Output Format -- **Formatted output**: `python tavily.py "query"` (default - human readable) -- **Raw JSON**: `python tavily.py "query" --raw` (for programmatic processing) +- **Formatted output**: `python tavilytool.py "query"` (default - human readable) +- **Raw JSON**: `python tavilytool.py "query" --raw` (for programmatic processing) ## Output Structure The default formatted output includes: @@ -55,13 +55,13 @@ The default formatted output includes: ## Command Combinations ```bash # Advanced search with images, limited results -python tavily.py "machine learning tutorials" --depth advanced --include-images --max-results 3 +python tavilytool.py "machine learning tutorials" --depth advanced --include-images --max-results 3 # Search specific sites only, raw output -python tavily.py "Python best practices" --include-domains github.com stackoverflow.com --raw +python tavilytool.py "Python best practices" --include-domains github.com stackoverflow.com --raw # Quick search without AI answer -python tavily.py "today's news" --no-answer --max-results 5 +python tavilytool.py "today's news" --no-answer --max-results 5 ``` ## Tips