Update jarvis.py
Browse files
jarvis.py
CHANGED
|
@@ -14,6 +14,7 @@ API_ID = os.environ.get("API_ID") # Replace with your API ID
|
|
| 14 |
API_HASH = os.environ.get("API_HASH") # Replace with your API HASH
|
| 15 |
BOT_TOKEN = os.environ.get("BOT_TOKEN")
|
| 16 |
GEMINI_API_KEY = os.environ.get("GEMINI_API_KEY")
|
|
|
|
| 17 |
if not BOT_TOKEN:
|
| 18 |
raise RuntimeError("BOT_TOKEN environment variable not set!")
|
| 19 |
if not GEMINI_API_KEY:
|
|
@@ -123,7 +124,10 @@ async def restart_bot(chat_id):
|
|
| 123 |
@bot.on_message(filters.private & filters.text)
|
| 124 |
async def jarvis_trigger(client, message):
|
| 125 |
# Owner-only access control
|
| 126 |
-
|
|
|
|
|
|
|
|
|
|
| 127 |
return await message.reply("β Access denied. Only the owner can use this bot.")
|
| 128 |
|
| 129 |
text = message.text.strip()
|
|
@@ -201,7 +205,9 @@ async def jarvis_trigger(client, message):
|
|
| 201 |
f"2. Include commands using @bot.on_message(filters.command(...))\n"
|
| 202 |
f"3. Import only what you need from pyrogram\n and use 'from ..t1 import bot'\n 'try: from ..t1 import bot except (ImportError, ValueError): \n from __main__ import bot' \n"
|
| 203 |
f"4. Don't create a new Client instance\n"
|
| 204 |
-
f"5. Make functions async when using bot methods\n
|
|
|
|
|
|
|
| 205 |
f"Output ONLY Python code, no explanations or markdown."
|
| 206 |
)
|
| 207 |
if attempt > 1 and last_error is not None:
|
|
@@ -214,6 +220,24 @@ async def jarvis_trigger(client, message):
|
|
| 214 |
code = code.replace('asyncio.PIPE', 'subprocess.PIPE')
|
| 215 |
# Add more auto-fixes as needed
|
| 216 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
# === LINTER/STATIC CHECKER ===
|
| 218 |
with open('tmp_lint_module.py', 'w', encoding='utf-8') as tmpf:
|
| 219 |
tmpf.write(code)
|
|
@@ -325,7 +349,7 @@ async def jarvis_trigger(client, message):
|
|
| 325 |
@bot.on_message(filters.command("modules") & filters.private)
|
| 326 |
async def list_modules(client, message):
|
| 327 |
# Owner-only access control
|
| 328 |
-
if message.from_user.id !=
|
| 329 |
return await message.reply("β Access denied. Only the owner can use this bot.")
|
| 330 |
|
| 331 |
modules = [f for f in os.listdir("modules") if f.endswith(".py")]
|
|
@@ -339,7 +363,7 @@ async def list_modules(client, message):
|
|
| 339 |
@bot.on_message(filters.command("delete") & filters.private)
|
| 340 |
async def delete_module(client, message):
|
| 341 |
# Owner-only access control
|
| 342 |
-
if message.from_user.id !=
|
| 343 |
return await message.reply("β Access denied. Only the owner can use this bot.")
|
| 344 |
|
| 345 |
if len(message.command) < 2:
|
|
@@ -358,7 +382,7 @@ async def delete_module(client, message):
|
|
| 358 |
@bot.on_message(filters.regex(r"(?i)what( can)? i do\??") & filters.private)
|
| 359 |
async def what_to_do(_, message):
|
| 360 |
# Owner-only access control
|
| 361 |
-
if message.from_user.id !=
|
| 362 |
return await message.reply("β Access denied. Only the owner can use this bot.")
|
| 363 |
|
| 364 |
await message.reply(
|
|
|
|
| 14 |
API_HASH = os.environ.get("API_HASH") # Replace with your API HASH
|
| 15 |
BOT_TOKEN = os.environ.get("BOT_TOKEN")
|
| 16 |
GEMINI_API_KEY = os.environ.get("GEMINI_API_KEY")
|
| 17 |
+
OWNER_ID = int(os.environ.get("OWNER_ID", "7361622601")) # Owner user ID
|
| 18 |
if not BOT_TOKEN:
|
| 19 |
raise RuntimeError("BOT_TOKEN environment variable not set!")
|
| 20 |
if not GEMINI_API_KEY:
|
|
|
|
| 124 |
@bot.on_message(filters.private & filters.text)
|
| 125 |
async def jarvis_trigger(client, message):
|
| 126 |
# Owner-only access control
|
| 127 |
+
print(f"DEBUG: User ID: {message.from_user.id}, Expected: {OWNER_ID}")
|
| 128 |
+
print(f"DEBUG: User: {message.from_user.first_name} {message.from_user.last_name}")
|
| 129 |
+
if message.from_user.id != OWNER_ID:
|
| 130 |
+
print(f"DEBUG: Access denied for user {message.from_user.id}")
|
| 131 |
return await message.reply("β Access denied. Only the owner can use this bot.")
|
| 132 |
|
| 133 |
text = message.text.strip()
|
|
|
|
| 205 |
f"2. Include commands using @bot.on_message(filters.command(...))\n"
|
| 206 |
f"3. Import only what you need from pyrogram\n and use 'from ..t1 import bot'\n 'try: from ..t1 import bot except (ImportError, ValueError): \n from __main__ import bot' \n"
|
| 207 |
f"4. Don't create a new Client instance\n"
|
| 208 |
+
f"5. Make functions async when using bot methods\n"
|
| 209 |
+
f"6. ONLY create the specific commands requested - do NOT add standard commands like /start, /help, /about unless explicitly asked for\n"
|
| 210 |
+
f"7. If the user asks for '/bash', only create the /bash command, not additional commands\n\n"
|
| 211 |
f"Output ONLY Python code, no explanations or markdown."
|
| 212 |
)
|
| 213 |
if attempt > 1 and last_error is not None:
|
|
|
|
| 220 |
code = code.replace('asyncio.PIPE', 'subprocess.PIPE')
|
| 221 |
# Add more auto-fixes as needed
|
| 222 |
|
| 223 |
+
# === REMOVE UNWANTED STANDARD COMMANDS ===
|
| 224 |
+
# Only keep commands that were explicitly requested
|
| 225 |
+
import re
|
| 226 |
+
requested_commands = []
|
| 227 |
+
# Extract commands mentioned in the description
|
| 228 |
+
cmd_matches = re.findall(r'/(\w+)', description.lower())
|
| 229 |
+
if cmd_matches:
|
| 230 |
+
requested_commands = [f'/{cmd}' for cmd in cmd_matches]
|
| 231 |
+
|
| 232 |
+
# If specific commands were requested, remove unwanted standard commands
|
| 233 |
+
if requested_commands:
|
| 234 |
+
unwanted_commands = ['/start', '/help', '/about', '/info']
|
| 235 |
+
for unwanted in unwanted_commands:
|
| 236 |
+
if unwanted not in requested_commands:
|
| 237 |
+
# Remove the entire function/handler for unwanted commands
|
| 238 |
+
pattern = rf'@bot\.on_message\(filters\.command\(["\']{unwanted[1:]}["\']\)\).*?(?=@bot\.on_message|$)'
|
| 239 |
+
code = re.sub(pattern, '', code, flags=re.DOTALL)
|
| 240 |
+
|
| 241 |
# === LINTER/STATIC CHECKER ===
|
| 242 |
with open('tmp_lint_module.py', 'w', encoding='utf-8') as tmpf:
|
| 243 |
tmpf.write(code)
|
|
|
|
| 349 |
@bot.on_message(filters.command("modules") & filters.private)
|
| 350 |
async def list_modules(client, message):
|
| 351 |
# Owner-only access control
|
| 352 |
+
if message.from_user.id != OWNER_ID:
|
| 353 |
return await message.reply("β Access denied. Only the owner can use this bot.")
|
| 354 |
|
| 355 |
modules = [f for f in os.listdir("modules") if f.endswith(".py")]
|
|
|
|
| 363 |
@bot.on_message(filters.command("delete") & filters.private)
|
| 364 |
async def delete_module(client, message):
|
| 365 |
# Owner-only access control
|
| 366 |
+
if message.from_user.id != OWNER_ID:
|
| 367 |
return await message.reply("β Access denied. Only the owner can use this bot.")
|
| 368 |
|
| 369 |
if len(message.command) < 2:
|
|
|
|
| 382 |
@bot.on_message(filters.regex(r"(?i)what( can)? i do\??") & filters.private)
|
| 383 |
async def what_to_do(_, message):
|
| 384 |
# Owner-only access control
|
| 385 |
+
if message.from_user.id != OWNER_ID:
|
| 386 |
return await message.reply("β Access denied. Only the owner can use this bot.")
|
| 387 |
|
| 388 |
await message.reply(
|