diff options
Diffstat (limited to '')
| -rw-r--r-- | cogs/jarvis.py | 38 |
1 files changed, 32 insertions, 6 deletions
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): | |||
| 24 | 24 | ||
| 25 | if message.mentions: | 25 | if message.mentions: |
| 26 | if message.mentions[0].id == self.bot.user.id: | 26 | if message.mentions[0].id == self.bot.user.id: |
| 27 | await self.jarvis(message) | 27 | content = await self.get_original(message) |
| 28 | await self.jarvis(message, content) | ||
| 28 | 29 | ||
| 29 | if "jarvis" in message.content.lower(): | 30 | elif "jarvis" in message.content.lower(): |
| 30 | await self.jarvis(message) | 31 | content = await self.get_original(message) |
| 32 | await self.jarvis(message, content) | ||
| 31 | 33 | ||
| 32 | @staticmethod | 34 | @staticmethod |
| 33 | async def jarvis(message): | 35 | async def jarvis(message, content): |
| 34 | url = "https://openrouter.ai/api/v1/chat/completions" | 36 | url = "https://openrouter.ai/api/v1/chat/completions" |
| 35 | headers = { | 37 | headers = { |
| 36 | 38 | ||
| @@ -49,7 +51,7 @@ class Jarvis(commands.Cog): | |||
| 49 | }, | 51 | }, |
| 50 | { | 52 | { |
| 51 | "role": "user", | 53 | "role": "user", |
| 52 | "content": f"{message.content}" | 54 | "content": f"{content}" |
| 53 | } | 55 | } |
| 54 | ], | 56 | ], |
| 55 | "response_format": { | 57 | "response_format": { |
| @@ -95,7 +97,7 @@ class Jarvis(commands.Cog): | |||
| 95 | action = inner_data['action'] # "none OR download OR compress" | 97 | action = inner_data['action'] # "none OR download OR compress" |
| 96 | channel = message.channel | 98 | channel = message.channel |
| 97 | logger.info(response_message) | 99 | logger.info(response_message) |
| 98 | logger.debug(action) | 100 | logger.info(action) |
| 99 | 101 | ||
| 100 | await channel.send(response_message) | 102 | await channel.send(response_message) |
| 101 | 103 | ||
| @@ -124,5 +126,29 @@ class Jarvis(commands.Cog): | |||
| 124 | elif action == "compress": | 126 | elif action == "compress": |
| 125 | pass | 127 | pass |
| 126 | 128 | ||
| 129 | @staticmethod | ||
| 130 | async def get_original(message): | ||
| 131 | if message.type == discord.MessageType.reply: | ||
| 132 | # The original message is already resolved (cached) | ||
| 133 | reply = message.reference.resolved | ||
| 134 | elif message.reference: | ||
| 135 | # If not cached, fetch it from the API | ||
| 136 | try: | ||
| 137 | reply = await message.channel.fetch_message(message.reference.message_id) | ||
| 138 | except discord.NotFound: | ||
| 139 | reply = None | ||
| 140 | else: | ||
| 141 | reply = None | ||
| 142 | |||
| 143 | if reply: | ||
| 144 | reply_content = reply.content | ||
| 145 | else: | ||
| 146 | reply_content = None | ||
| 147 | |||
| 148 | if reply_content: | ||
| 149 | return f"{message.content} [which is a reply to] {reply_content}" | ||
| 150 | else: | ||
| 151 | return message.content | ||
| 152 | |||
| 127 | def setup(bot): | 153 | def setup(bot): |
| 128 | bot.add_cog(Jarvis(bot)) | 154 | bot.add_cog(Jarvis(bot)) |
