diff --git a/bot/core.py b/bot/core.py index d733058e..4dd28439 100644 --- a/bot/core.py +++ b/bot/core.py @@ -23,6 +23,8 @@ os.environ.update(JISHAKU_NO_UNDERSCORE="True", JISHAKU_NO_DM_TRACEBACK="True", JISHAKU_HIDE="True") ALLOWED_MENTIONS = discord.AllowedMentions(everyone=False, roles=False, users=False) +RUNNING_IN_KUBERNETES = os.environ.get("KUBERNETES_SERVICE_HOST") is not None + class DiscordBot(commands.Bot): def __init__(self, prefixes: tuple[str, ...], extensions: tuple[str, ...], intents: discord.Intents): @@ -117,6 +119,8 @@ async def on_message(self, message): if message.author.bot: return + raise ValueError("Test") + log.debug(f"{message.channel}: {message.author}: {message.clean_content}") await self.process_commands(message) @@ -146,7 +150,7 @@ async def on_app_command_completion( VALUES ($1, $2, $3, $4, $5, $6, $7) """ - res = await Model.pool.execute( + await Model.pool.execute( query, interaction.user.id, interaction.guild_id, @@ -156,11 +160,13 @@ async def on_app_command_completion( command.qualified_name, interaction.data["options"], ) - log.info(f"Command usage inserted {res}") except Exception as e: await self.on_error("on_app_command_completion", e) async def send_error(self, content: str, header: str, invoked_details_document: Document = None) -> None: + if not RUNNING_IN_KUBERNETES: + return + def wrap(code: str) -> str: code = code.replace("`", "\u200b`") return f"```py\n{code}\n```" @@ -180,10 +186,12 @@ def wrap(code: str) -> str: await self.error_webhook.send(embed=embed) async def on_error(self, event_method: str, *args: Any, **kwargs: Any) -> None: - content = "".join(traceback.format_exception(*sys.exc_info())) + error = sys.exc_info() + content = "".join(traceback.format_exception(*error)) header = f"Ignored exception in event method **{event_method}**" await self.send_error(content, header) + log.error(f"Ignored exception in event method {event_method}", exc_info=error) async def on_app_command_error(self, interaction: "InteractionType", error: app_commands.AppCommandError): """Handle errors in app commands.""" diff --git a/bot/extensions/youtube/tasks.py b/bot/extensions/youtube/tasks.py index fc3ffe63..69949ea7 100644 --- a/bot/extensions/youtube/tasks.py +++ b/bot/extensions/youtube/tasks.py @@ -1,3 +1,4 @@ +import logging import re import traceback import xml.etree.ElementTree as ET @@ -15,6 +16,9 @@ RSS_FEED_BASE_URL = "https://www.youtube.com/feeds/videos.xml" +log = logging.getLogger(__name__) + + class Video(BaseModel): link: str title: str @@ -100,6 +104,8 @@ async def find_new_videos(self): header = "Ignored exception when parsing rss feed." document = await paste.create(content=data) + log.error(header, exc_info=e) + return await self.bot.send_error(content, header, invoked_details_document=document) ns = "{http://www.w3.org/2005/Atom}"