Update jarvis.py
Browse files
jarvis.py
CHANGED
|
@@ -21,7 +21,7 @@ if not GEMINI_API_KEY:
|
|
| 21 |
# === SETUP ===
|
| 22 |
genai.configure(api_key=GEMINI_API_KEY)
|
| 23 |
model = genai.GenerativeModel("gemini-2.5-flash")
|
| 24 |
-
bot = Client("
|
| 25 |
os.makedirs("modules", exist_ok=True)
|
| 26 |
|
| 27 |
# === MODULE LOADER ===
|
|
@@ -219,6 +219,29 @@ async def jarvis_trigger(client, message):
|
|
| 219 |
raise RuntimeError(f"Testing error: {test_error}")
|
| 220 |
|
| 221 |
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...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
await asyncio.sleep(2)
|
| 223 |
asyncio.create_task(restart_bot(message.chat.id))
|
| 224 |
success = True
|
|
@@ -259,9 +282,9 @@ async def delete_module(client, message):
|
|
| 259 |
@bot.on_message(filters.regex(r"(?i)what( can)? i do\??") & filters.private)
|
| 260 |
async def what_to_do(_, message):
|
| 261 |
await message.reply(
|
| 262 |
-
"🧠 Jarvis Assistant**\n\n"
|
| 263 |
"I can generate custom bot modules for you!\n\n"
|
| 264 |
-
"Commands:\n"
|
| 265 |
"`jarvis make a calculator` - Natural language trigger\n"
|
| 266 |
"`/modules` - List all modules\n"
|
| 267 |
"`/delete <name>` - Delete a module\n\n"
|
|
|
|
| 21 |
# === SETUP ===
|
| 22 |
genai.configure(api_key=GEMINI_API_KEY)
|
| 23 |
model = genai.GenerativeModel("gemini-2.5-flash")
|
| 24 |
+
bot = Client("JarvisBot", api_id=API_ID, api_hash=API_HASH, bot_token=BOT_TOKEN)
|
| 25 |
os.makedirs("modules", exist_ok=True)
|
| 26 |
|
| 27 |
# === MODULE LOADER ===
|
|
|
|
| 219 |
raise RuntimeError(f"Testing error: {test_error}")
|
| 220 |
|
| 221 |
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...")
|
| 222 |
+
|
| 223 |
+
# === NEW: Show module details before restart ===
|
| 224 |
+
commands = extract_commands(code)
|
| 225 |
+
commands_str = ', '.join(f'/{cmd}' for cmd in commands) if commands else 'No commands found.'
|
| 226 |
+
explain_prompt = (
|
| 227 |
+
f"Explain in 2-3 sentences what this Pyrogram Telegram bot module does, given the following code and the user's request.\n"
|
| 228 |
+
f"User request: {description}\n"
|
| 229 |
+
f"Module code:\n{code}\n"
|
| 230 |
+
f"Be concise and clear."
|
| 231 |
+
)
|
| 232 |
+
try:
|
| 233 |
+
explain_response = model.generate_content(explain_prompt)
|
| 234 |
+
explanation = explain_response.text.strip()
|
| 235 |
+
except Exception as exp_explain:
|
| 236 |
+
explanation = f"(Could not generate explanation: {exp_explain})"
|
| 237 |
+
details_msg = (
|
| 238 |
+
f" Module created successfully!\n\n"
|
| 239 |
+
f"Commands: {commands_str}\n\n"
|
| 240 |
+
f"What it does:\n{explanation}\n\n"
|
| 241 |
+
f"♻️ Restarting bot to load the new module..."
|
| 242 |
+
)
|
| 243 |
+
await progress_msg.edit(details_msg, parse_mode=ParseMode.MARKDOWN)
|
| 244 |
+
# === END NEW ===
|
| 245 |
await asyncio.sleep(2)
|
| 246 |
asyncio.create_task(restart_bot(message.chat.id))
|
| 247 |
success = True
|
|
|
|
| 282 |
@bot.on_message(filters.regex(r"(?i)what( can)? i do\??") & filters.private)
|
| 283 |
async def what_to_do(_, message):
|
| 284 |
await message.reply(
|
| 285 |
+
"**🧠 Jarvis Assistant**\n\n"
|
| 286 |
"I can generate custom bot modules for you!\n\n"
|
| 287 |
+
"**Commands:**\n"
|
| 288 |
"`jarvis make a calculator` - Natural language trigger\n"
|
| 289 |
"`/modules` - List all modules\n"
|
| 290 |
"`/delete <name>` - Delete a module\n\n"
|