aboutsummaryrefslogtreecommitdiffstats
path: root/cogs/jarvis.py
diff options
context:
space:
mode:
authorsalmonik <raisersoft@proton.me>2026-03-19 22:03:03 +0100
committersalmonik <raisersoft@proton.me>2026-03-19 22:03:03 +0100
commitf3d8578759d2fea9e481696b7a29e2d2a1c30cc9 (patch)
tree80e643f41fd8ed83e51c75104224c2741a5c0cf0 /cogs/jarvis.py
parentvclogs afk/active time (diff)
downloadsenator-sperma-f3d8578759d2fea9e481696b7a29e2d2a1c30cc9.tar.gz
senator-sperma-f3d8578759d2fea9e481696b7a29e2d2a1c30cc9.zip
normalised times on vclogs, and improved jarvis via reply chaining
Diffstat (limited to '')
-rw-r--r--cogs/jarvis.py95
1 files changed, 37 insertions, 58 deletions
diff --git a/cogs/jarvis.py b/cogs/jarvis.py
index 4f34ea8..866700e 100644
--- a/cogs/jarvis.py
+++ b/cogs/jarvis.py
@@ -24,10 +24,10 @@ class Jarvis(commands.Cog):
24 24
25 @commands.Cog.listener() 25 @commands.Cog.listener()
26 async def on_message(self, message): 26 async def on_message(self, message):
27 print(message.content)
28 if message.author == self.bot.user: 27 if message.author == self.bot.user:
29 return 28 return
30 29
30 logger.info(message.content)
31 if message.mentions: 31 if message.mentions:
32 if message.mentions[0].id == self.bot.user.id: 32 if message.mentions[0].id == self.bot.user.id:
33 await self.jarvis(message) 33 await self.jarvis(message)
@@ -42,7 +42,8 @@ class Jarvis(commands.Cog):
42 "Content-Type": "application/json" 42 "Content-Type": "application/json"
43 } 43 }
44 44
45 messages = Jarvis._build_messages(message) 45 chain = await Jarvis._build_message_chain(message)
46 messages = Jarvis._build_messages(message, chain)
46 payload = Jarvis._build_payload(messages) 47 payload = Jarvis._build_payload(messages)
47 48
48 response_data = await Jarvis._make_api_request(payload, headers) 49 response_data = await Jarvis._make_api_request(payload, headers)
@@ -55,46 +56,48 @@ class Jarvis(commands.Cog):
55 await Jarvis._handle_download_action(message, channel) 56 await Jarvis._handle_download_action(message, channel)
56 57
57 @staticmethod 58 @staticmethod
58 def _build_messages(message): 59 async def _build_message_chain(message):
60 chain = []
61 current = message
62 max_depth = 5
63
64 while current and len(chain) < max_depth:
65 chain.append(current)
66 if not current.reference:
67 break
68 try:
69 if current.reference.resolved:
70 current = current.reference.resolved
71 else:
72 current = await current.channel.fetch_message(current.reference.message_id)
73 except discord.NotFound:
74 break
75
76 return list(reversed(chain))
77
78 @staticmethod
79 def _build_messages(message, chain=None):
59 messages = [{ 80 messages = [{
60 "role": "system", 81 "role": "system",
61 "content": "You are an alter ego of Senator Sperma Armstrong.\n" 82 "content": "Jesteś Senator Sperma Armostrong, także znany jako Jarvis."
62 "your task is to tell the program what to do and how to respond after receiving a message.\n" 83 "Twoim zadaniem, po za asystowaniem użytkownika, jest mówienie programowi nadrzędnemu jak sie zachować"
63 "message field has to be filled out in polish.\n" 84 "pole 'message' może być tylko wypełnione w języku Polskim."
64 "act like jarvis (only behavior wise), be a personal assistant to user, do not use emojis\n" 85 "zachowuj sie jak Jarvis, bądź osobistym asystentem użytkownika, nie używaj emotikon"
65 "do not ask the user if they want to do an action. the user will tell you that." 86 "nie pytaj sie użytkownika czy chcesz abyś coś zrobił, użytkownik ci sam powie abyś coś wykonał"
66 }] 87 }]
67 88
68 messages.append({ 89 if chain is None:
69 "role": "user", 90 chain = [message]
70 "content": f"{message.author.display_name}: {message.content}"
71
72 })
73 91
74 if Jarvis._is_reply(message): 92 for msg in chain:
75 messages.extend(Jarvis._build_reply_messages(message)) 93 messages.append({
94 "role": "user",
95 "content": f"{msg.author.display_name}: {msg.content}"
96 })
76 97
77 return messages 98 return messages
78 99
79 @staticmethod 100 @staticmethod
80 def _is_reply(message):
81 return message.reference and (message.type == discord.MessageType.reply or message.reference.resolved)
82
83 @staticmethod
84 def _build_reply_messages(message):
85 original_msg = message.reference.resolved
86 return [
87 {
88 "role": "user",
89 "content": f"{original_msg.author.display_name}: {original_msg.content}"
90 },
91 {
92 "role": "user",
93 "content": f"{message.author.display_name}: {message.content}"
94 }
95 ]
96
97 @staticmethod
98 def _build_payload(messages): 101 def _build_payload(messages):
99 return { 102 return {
100 "model": "arcee-ai/trinity-large-preview:free", 103 "model": "arcee-ai/trinity-large-preview:free",
@@ -191,29 +194,5 @@ class Jarvis(commands.Cog):
191 logger.error(f"Details: {response['details']}") 194 logger.error(f"Details: {response['details']}")
192 shutil.rmtree(response["temp_dir"]) 195 shutil.rmtree(response["temp_dir"])
193 196
194 @staticmethod
195 async def get_original(message):
196 if message.type == discord.MessageType.reply:
197 # The original message is already resolved (cached)
198 reply = message.reference.resolved
199 elif message.reference:
200 # If not cached, fetch it from the API
201 try:
202 reply = await message.channel.fetch_message(message.reference.message_id)
203 except discord.NotFound:
204 reply = None
205 else:
206 reply = None
207
208 if reply:
209 reply_content = reply.content
210 else:
211 reply_content = None
212
213 if reply_content:
214 return f"{message.content} [which is a reply to] {reply_content}"
215 else:
216 return message.content
217
218def setup(bot): 197def setup(bot):
219 bot.add_cog(Jarvis(bot)) 198 bot.add_cog(Jarvis(bot))