From 6177ae3d370c8cc53689feaa3b8783264f7d2f4c Mon Sep 17 00:00:00 2001 From: salmonik Date: Mon, 19 Jan 2026 21:30:03 +0100 Subject: WIP context for jarvis via replies --- cogs/jarvis.py | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'cogs/jarvis.py') diff --git a/cogs/jarvis.py b/cogs/jarvis.py index 3382f5b..c94ab7c 100644 --- a/cogs/jarvis.py +++ b/cogs/jarvis.py @@ -24,13 +24,15 @@ class Jarvis(commands.Cog): if message.mentions: if message.mentions[0].id == self.bot.user.id: - await self.jarvis(message) + content = await self.get_original(message) + await self.jarvis(message, content) - if "jarvis" in message.content.lower(): - await self.jarvis(message) + elif "jarvis" in message.content.lower(): + content = await self.get_original(message) + await self.jarvis(message, content) @staticmethod - async def jarvis(message): + async def jarvis(message, content): url = "https://openrouter.ai/api/v1/chat/completions" headers = { @@ -49,7 +51,7 @@ class Jarvis(commands.Cog): }, { "role": "user", - "content": f"{message.content}" + "content": f"{content}" } ], "response_format": { @@ -95,7 +97,7 @@ class Jarvis(commands.Cog): action = inner_data['action'] # "none OR download OR compress" channel = message.channel logger.info(response_message) - logger.debug(action) + logger.info(action) await channel.send(response_message) @@ -124,5 +126,29 @@ class Jarvis(commands.Cog): elif action == "compress": pass + @staticmethod + async def get_original(message): + if message.type == discord.MessageType.reply: + # The original message is already resolved (cached) + reply = message.reference.resolved + elif message.reference: + # If not cached, fetch it from the API + try: + reply = await message.channel.fetch_message(message.reference.message_id) + except discord.NotFound: + reply = None + else: + reply = None + + if reply: + reply_content = reply.content + else: + reply_content = None + + if reply_content: + return f"{message.content} [which is a reply to] {reply_content}" + else: + return message.content + def setup(bot): bot.add_cog(Jarvis(bot)) -- cgit v1.2.3