xdragxt commited on
Commit
7062b9f
·
verified ·
1 Parent(s): ea4e8b4

Update jarvis.py

Browse files
Files changed (1) hide show
  1. jarvis.py +37 -17
jarvis.py CHANGED
@@ -222,26 +222,35 @@ async def jarvis_trigger(client, message):
222
  await progress_msg.edit(f"`Attempt {attempt}/5:` Thinking and generating code...\n- Executing prerequisite shell commands...\n- Testing generated code...\n- Tests passed. Writing files...\n- Files written. Initiating restart...")
223
 
224
  # === NEW: Show module details before restart ===
225
- commands = extract_commands(code)
226
- commands_str = ', '.join(f'/{cmd}' for cmd in commands) if commands else 'No commands found.'
227
- explain_prompt = (
228
- f"Explain in 2-3 sentences what this Pyrogram Telegram bot module does, given the following code and the user's request.\n"
229
- f"User request: {description}\n"
230
- f"Module code:\n{code}\n"
231
- f"Be concise and clear."
232
- )
233
  try:
 
 
 
 
 
 
 
 
 
 
 
 
234
  explain_response = model.generate_content(explain_prompt)
235
  explanation = explain_response.text.strip()
236
  except Exception as exp_explain:
237
- explanation = f"(Could not generate explanation: {exp_explain})"
238
- details_msg = (
239
- f" Module created successfully!\n\n"
240
- f"Commands: {commands_str}\n\n"
241
- f"What it does:\n{explanation}\n\n"
242
- f"♻️ Restarting bot to load the new module..."
243
- )
244
- await progress_msg.edit(details_msg, parse_mode=ParseMode.MARKDOWN)
 
 
 
 
 
245
  # === END NEW ===
246
  await asyncio.sleep(2)
247
  asyncio.create_task(restart_bot(message.chat.id))
@@ -250,7 +259,18 @@ async def jarvis_trigger(client, message):
250
 
251
  except Exception as e:
252
  last_error = e
253
- await progress_msg.edit(f"❌ Attempt {attempt} Error: `{str(e)[:100]}...`")
 
 
 
 
 
 
 
 
 
 
 
254
 
255
  if not success:
256
  await progress_msg.edit("❌ All 5 attempts failed. Please try again with a simpler instruction.")
 
222
  await progress_msg.edit(f"`Attempt {attempt}/5:` Thinking and generating code...\n- Executing prerequisite shell commands...\n- Testing generated code...\n- Tests passed. Writing files...\n- Files written. Initiating restart...")
223
 
224
  # === NEW: Show module details before restart ===
 
 
 
 
 
 
 
 
225
  try:
226
+ commands = extract_commands(code)
227
+ commands_str = ', '.join(f'/{cmd}' for cmd in commands) if commands else 'No commands found.'
228
+ except Exception as cmd_error:
229
+ commands_str = f'Error extracting commands: {cmd_error}'
230
+
231
+ try:
232
+ explain_prompt = (
233
+ f"Explain in 2-3 sentences what this Pyrogram Telegram bot module does, given the following code and the user's request.\n"
234
+ f"User request: {description}\n"
235
+ f"Module code:\n{code}\n"
236
+ f"Be concise and clear."
237
+ )
238
  explain_response = model.generate_content(explain_prompt)
239
  explanation = explain_response.text.strip()
240
  except Exception as exp_explain:
241
+ explanation = f"Could not generate explanation: {exp_explain}"
242
+
243
+ try:
244
+ details_msg = (
245
+ f" Module created successfully!\n\n"
246
+ f"**Commands:** {commands_str}\n\n"
247
+ f"**What it does:**\n{explanation}\n\n"
248
+ f"♻️ Restarting bot to load the new module..."
249
+ )
250
+ await progress_msg.edit(details_msg, parse_mode=ParseMode.MARKDOWN)
251
+ except Exception as msg_error:
252
+ # Fallback message if formatting fails
253
+ await progress_msg.edit(f"✅ Module created successfully! Commands: {commands_str}\n\nWhat it does: {explanation}\n\n♻️ Restarting bot...")
254
  # === END NEW ===
255
  await asyncio.sleep(2)
256
  asyncio.create_task(restart_bot(message.chat.id))
 
259
 
260
  except Exception as e:
261
  last_error = e
262
+ error_msg = f"❌ Attempt {attempt} Error: {str(e)}"
263
+ print(f"DEBUG: Module generation error on attempt {attempt}: {e}")
264
+ print(f"DEBUG: Error type: {type(e).__name__}")
265
+ try:
266
+ await progress_msg.edit(error_msg[:100] + "..." if len(error_msg) > 100 else error_msg)
267
+ except Exception as edit_error:
268
+ print(f"DEBUG: Failed to edit progress message: {edit_error}")
269
+ # Try to send a new message if editing fails
270
+ try:
271
+ await message.reply(f"❌ Attempt {attempt} failed. Check logs for details.")
272
+ except:
273
+ pass
274
 
275
  if not success:
276
  await progress_msg.edit("❌ All 5 attempts failed. Please try again with a simpler instruction.")