Update jarvis.py
Browse files
jarvis.py
CHANGED
@@ -7,10 +7,8 @@ from pyrogram import Client, filters
|
|
7 |
from pyrogram.enums import ParseMode
|
8 |
import google.generativeai as genai
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
API_ID = os.environ.get("API_ID") # Replace with your API ID
|
13 |
-
API_HASH = os.environ.get("API_HASH") # Replace with your API HASH
|
14 |
BOT_TOKEN = os.environ.get("BOT_TOKEN")
|
15 |
GEMINI_API_KEY = os.environ.get("GEMINI_API_KEY")
|
16 |
if not BOT_TOKEN:
|
@@ -18,13 +16,11 @@ if not BOT_TOKEN:
|
|
18 |
if not GEMINI_API_KEY:
|
19 |
raise RuntimeError("GEMINI_API_KEY environment variable not set!")
|
20 |
|
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 ===
|
28 |
def load_modules(folder="modules"):
|
29 |
for file in os.listdir(folder):
|
30 |
if file.endswith(".py"):
|
@@ -36,13 +32,12 @@ def load_modules(folder="modules"):
|
|
36 |
|
37 |
load_modules()
|
38 |
|
39 |
-
# === HELPERS ===
|
40 |
def extract_module_name(code: str) -> str:
|
41 |
match = re.search(r"def\\s+([a-zA-Z_][a-zA-Z0-9_]*)", code)
|
42 |
return match.group(1).lower() if match else f"mod_{os.urandom(2).hex()}"
|
43 |
|
44 |
def extract_commands(code: str) -> list:
|
45 |
-
return re.findall(r'filters
|
46 |
|
47 |
def determine_intent(text: str) -> str:
|
48 |
lowered = text.lower()
|
@@ -65,62 +60,71 @@ def clean_code_blocks(code: str) -> str:
|
|
65 |
return code.strip()
|
66 |
|
67 |
def extract_module_name_from_description(description: str) -> str:
|
68 |
-
# Try to extract the last noun/phrase as the module name
|
69 |
-
# Remove common verbs and stopwords
|
70 |
import re
|
71 |
-
stopwords =
|
72 |
-
'jarvis', 'make', 'create', 'build', 'generate', 'a', 'an', 'the', 'please', 'module',
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
name = re.sub(r'_+', '_', name).strip('_')
|
84 |
-
|
85 |
if not name:
|
86 |
-
|
87 |
return name
|
88 |
|
89 |
async def restart_bot(chat_id):
|
90 |
-
await bot.send_message(chat_id, "
|
91 |
await bot.stop()
|
92 |
os.execl(sys.executable, sys.executable, *sys.argv)
|
93 |
-
os._exit(0)
|
94 |
|
95 |
-
# === WORD TRIGGER ===
|
96 |
@bot.on_message(filters.private & filters.text)
|
97 |
async def jarvis_trigger(client, message):
|
|
|
|
|
|
|
98 |
text = message.text.strip()
|
99 |
if not text.lower().startswith("jarvis"):
|
100 |
return
|
101 |
|
102 |
description = text[6:].strip()
|
103 |
if not description:
|
104 |
-
return await message.reply("
|
105 |
|
106 |
intent = determine_intent(description)
|
107 |
-
progress_msg = await message.reply(f"
|
108 |
|
109 |
-
# --- NEW: Handle EDIT intent for existing files ---
|
110 |
if intent == "EDIT":
|
111 |
-
# Try to extract filename and edit instruction
|
112 |
match = re.match(r"edit\s+([\w/\\.]+)\s+(.*)", description, re.IGNORECASE)
|
113 |
if match:
|
114 |
file_path = match.group(1)
|
115 |
edit_instruction = match.group(2)
|
116 |
if not os.path.exists(file_path):
|
117 |
-
await progress_msg.edit(f"
|
118 |
return
|
119 |
with open(file_path, "r", encoding="utf-8") as f:
|
120 |
current_content = f.read()
|
121 |
edit_prompt = (
|
122 |
f"You are an expert Python developer. Here is the current content of `{file_path}`:\n"
|
123 |
-
f"
|
124 |
f"Please edit this file to: {edit_instruction}.\n"
|
125 |
f"Output ONLY the new Python code, no explanations or markdown."
|
126 |
)
|
@@ -128,11 +132,10 @@ async def jarvis_trigger(client, message):
|
|
128 |
response = model.generate_content(edit_prompt)
|
129 |
new_code = clean_code_blocks(response.text.strip())
|
130 |
if not new_code or "def " not in new_code:
|
131 |
-
await progress_msg.edit(f"
|
132 |
return
|
133 |
with open(file_path, "w", encoding="utf-8") as f:
|
134 |
f.write(new_code)
|
135 |
-
# Try to reload the module if it's in modules/
|
136 |
if file_path.startswith("modules/") and file_path.endswith(".py"):
|
137 |
mod_name = os.path.basename(file_path)[:-3]
|
138 |
try:
|
@@ -141,25 +144,24 @@ async def jarvis_trigger(client, message):
|
|
141 |
mod.bot = bot
|
142 |
spec.loader.exec_module(mod)
|
143 |
except Exception as test_error:
|
144 |
-
await progress_msg.edit(f"
|
145 |
return
|
146 |
-
await progress_msg.edit(f"
|
147 |
await asyncio.sleep(2)
|
148 |
asyncio.create_task(restart_bot(message.chat.id))
|
149 |
return
|
150 |
except Exception as e:
|
151 |
-
await progress_msg.edit(f"
|
152 |
return
|
153 |
else:
|
154 |
-
await progress_msg.edit("
|
155 |
return
|
156 |
-
# --- END NEW ---
|
157 |
|
158 |
success = False
|
159 |
code = ""
|
160 |
last_error = None
|
161 |
for attempt in range(1, 6):
|
162 |
-
await progress_msg.edit(f"
|
163 |
|
164 |
try:
|
165 |
prompt = (
|
@@ -180,10 +182,9 @@ async def jarvis_trigger(client, message):
|
|
180 |
code = clean_code_blocks(response.text.strip())
|
181 |
|
182 |
if "def " not in code or "@bot" not in code:
|
183 |
-
await progress_msg.edit(f"
|
184 |
continue
|
185 |
|
186 |
-
# --- NEW: Use file path from description if present ---
|
187 |
import re
|
188 |
file_path_match = re.search(r"(modules/[\w\-]+\.py)", description)
|
189 |
if file_path_match:
|
@@ -192,24 +193,23 @@ async def jarvis_trigger(client, message):
|
|
192 |
else:
|
193 |
mod_name = extract_module_name_from_description(description)
|
194 |
mod_path = f"modules/{mod_name}.py"
|
195 |
-
|
196 |
if os.path.exists(mod_path):
|
197 |
with open(mod_path, "r", encoding="utf-8") as f:
|
198 |
current_content = f.read()
|
199 |
edit_prompt = (
|
200 |
f"You are an expert Python developer. Here is the current content of `{mod_path}`:\n"
|
201 |
-
f"
|
202 |
f"Please update this file to: {description}.\n"
|
203 |
f"Output ONLY the new Python code, no explanations or markdown."
|
204 |
)
|
205 |
response = model.generate_content(edit_prompt)
|
206 |
code = clean_code_blocks(response.text.strip())
|
207 |
-
# --- END NEW ---
|
208 |
|
209 |
with open(mod_path, "w", encoding="utf-8") as f:
|
210 |
f.write(code)
|
211 |
|
212 |
-
await progress_msg.edit(f"
|
213 |
|
214 |
try:
|
215 |
spec = importlib.util.spec_from_file_location(mod_name, mod_path)
|
@@ -219,15 +219,9 @@ async def jarvis_trigger(client, message):
|
|
219 |
except Exception as test_error:
|
220 |
raise RuntimeError(f"Testing error: {test_error}")
|
221 |
|
222 |
-
|
|
|
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"
|
@@ -239,19 +233,15 @@ async def jarvis_trigger(client, message):
|
|
239 |
explanation = explain_response.text.strip()
|
240 |
except Exception as exp_explain:
|
241 |
explanation = f"Could not generate explanation: {exp_explain}"
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
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))
|
257 |
success = True
|
@@ -259,66 +249,58 @@ async def jarvis_trigger(client, message):
|
|
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(
|
267 |
-
except
|
268 |
-
|
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("
|
277 |
|
278 |
-
# === /modules ===
|
279 |
@bot.on_message(filters.command("modules") & filters.private)
|
280 |
async def list_modules(client, message):
|
|
|
|
|
281 |
modules = [f for f in os.listdir("modules") if f.endswith(".py")]
|
282 |
if modules:
|
283 |
module_list = "\n".join([f"• {m[:-3]}" for m in modules])
|
284 |
-
await message.reply(f"
|
285 |
else:
|
286 |
-
await message.reply("
|
287 |
|
288 |
-
# === /delete ===
|
289 |
@bot.on_message(filters.command("delete") & filters.private)
|
290 |
async def delete_module(client, message):
|
|
|
|
|
291 |
if len(message.command) < 2:
|
292 |
-
return await message.reply("
|
293 |
-
|
294 |
mod_name = message.command[1].lower()
|
295 |
mod_path = f"modules/{mod_name}.py"
|
296 |
-
|
297 |
if os.path.exists(mod_path):
|
298 |
os.remove(mod_path)
|
299 |
-
await message.reply(f"
|
300 |
else:
|
301 |
-
await message.reply(f"
|
302 |
|
303 |
-
# === /what to do ===
|
304 |
@bot.on_message(filters.regex(r"(?i)what( can)? i do\??") & filters.private)
|
305 |
async def what_to_do(_, message):
|
|
|
|
|
306 |
await message.reply(
|
307 |
-
"
|
308 |
"I can generate custom bot modules for you!\n\n"
|
309 |
-
"
|
310 |
-
"
|
311 |
-
"
|
312 |
-
"
|
313 |
-
"
|
314 |
-
"
|
315 |
-
"
|
316 |
-
"
|
317 |
parse_mode=ParseMode.MARKDOWN
|
318 |
)
|
319 |
|
320 |
-
|
321 |
-
print("🚀 Starting Jarvis Bot...")
|
322 |
load_modules()
|
323 |
-
print("
|
324 |
bot.run()
|
|
|
7 |
from pyrogram.enums import ParseMode
|
8 |
import google.generativeai as genai
|
9 |
|
10 |
+
API_ID = os.environ.get("API_ID")
|
11 |
+
API_HASH = os.environ.get("API_HASH")
|
|
|
|
|
12 |
BOT_TOKEN = os.environ.get("BOT_TOKEN")
|
13 |
GEMINI_API_KEY = os.environ.get("GEMINI_API_KEY")
|
14 |
if not BOT_TOKEN:
|
|
|
16 |
if not GEMINI_API_KEY:
|
17 |
raise RuntimeError("GEMINI_API_KEY environment variable not set!")
|
18 |
|
|
|
19 |
genai.configure(api_key=GEMINI_API_KEY)
|
20 |
model = genai.GenerativeModel("gemini-2.5-flash")
|
21 |
bot = Client("JarvisBot", api_id=API_ID, api_hash=API_HASH, bot_token=BOT_TOKEN)
|
22 |
os.makedirs("modules", exist_ok=True)
|
23 |
|
|
|
24 |
def load_modules(folder="modules"):
|
25 |
for file in os.listdir(folder):
|
26 |
if file.endswith(".py"):
|
|
|
32 |
|
33 |
load_modules()
|
34 |
|
|
|
35 |
def extract_module_name(code: str) -> str:
|
36 |
match = re.search(r"def\\s+([a-zA-Z_][a-zA-Z0-9_]*)", code)
|
37 |
return match.group(1).lower() if match else f"mod_{os.urandom(2).hex()}"
|
38 |
|
39 |
def extract_commands(code: str) -> list:
|
40 |
+
return re.findall(r'filters\.command\(["\'](\w+)["\']', code)
|
41 |
|
42 |
def determine_intent(text: str) -> str:
|
43 |
lowered = text.lower()
|
|
|
60 |
return code.strip()
|
61 |
|
62 |
def extract_module_name_from_description(description: str) -> str:
|
|
|
|
|
63 |
import re
|
64 |
+
stopwords = {
|
65 |
+
'jarvis', 'make', 'create', 'build', 'generate', 'a', 'an', 'the', 'please', 'module',
|
66 |
+
'for', 'me', 'to', 'with', 'add', 'new', 'of', 'system', 'bot', 'command', 'that', 'and',
|
67 |
+
'in', 'on', 'by', 'as', 'is', 'it', 'my', 'this', 'do', 'can', 'you', 'i', 'want', 'need',
|
68 |
+
'from', 'like', 'using', 'feature', 'function', 'implement', 'write', 'code', 'file',
|
69 |
+
'python', 'telegram', 'pyrogram', 'handler', 'example', 'mod', 'mod_', 'particular', 'user'
|
70 |
+
}
|
71 |
+
desc = re.sub(r'[^a-zA-Z0-9_\s]', ' ', description.lower())
|
72 |
+
words = desc.split()
|
73 |
+
filtered_words = []
|
74 |
+
for word in words:
|
75 |
+
if word not in stopwords and len(word) > 2:
|
76 |
+
filtered_words.append(word)
|
77 |
+
if filtered_words:
|
78 |
+
name_words = filtered_words[:3]
|
79 |
+
name = '_'.join(name_words)
|
80 |
+
else:
|
81 |
+
meaningful_words = [w for w in words if len(w) > 3 and w not in stopwords]
|
82 |
+
if meaningful_words:
|
83 |
+
name = meaningful_words[0]
|
84 |
+
else:
|
85 |
+
clean_desc = re.sub(r'[^a-zA-Z0-9]', '', description.lower())
|
86 |
+
name = clean_desc[:10] if clean_desc else f"mod_{os.urandom(2).hex()}"
|
87 |
name = re.sub(r'_+', '_', name).strip('_')
|
88 |
+
name = name.lower()
|
89 |
if not name:
|
90 |
+
name = f"mod_{os.urandom(2).hex()}"
|
91 |
return name
|
92 |
|
93 |
async def restart_bot(chat_id):
|
94 |
+
await bot.send_message(chat_id, "Restarting to apply new module...")
|
95 |
await bot.stop()
|
96 |
os.execl(sys.executable, sys.executable, *sys.argv)
|
97 |
+
os._exit(0)
|
98 |
|
|
|
99 |
@bot.on_message(filters.private & filters.text)
|
100 |
async def jarvis_trigger(client, message):
|
101 |
+
if message.from_user.id != 7361622601:
|
102 |
+
return await message.reply("Access denied. Only the owner can use this bot.")
|
103 |
+
|
104 |
text = message.text.strip()
|
105 |
if not text.lower().startswith("jarvis"):
|
106 |
return
|
107 |
|
108 |
description = text[6:].strip()
|
109 |
if not description:
|
110 |
+
return await message.reply("Hello, what would you like me to do?")
|
111 |
|
112 |
intent = determine_intent(description)
|
113 |
+
progress_msg = await message.reply(f"Acknowledged.\nDetermining intent...\nIntent: {intent}\nTask: `{description}`", parse_mode=ParseMode.MARKDOWN)
|
114 |
|
|
|
115 |
if intent == "EDIT":
|
|
|
116 |
match = re.match(r"edit\s+([\w/\\.]+)\s+(.*)", description, re.IGNORECASE)
|
117 |
if match:
|
118 |
file_path = match.group(1)
|
119 |
edit_instruction = match.group(2)
|
120 |
if not os.path.exists(file_path):
|
121 |
+
await progress_msg.edit(f"File `{file_path}` not found.")
|
122 |
return
|
123 |
with open(file_path, "r", encoding="utf-8") as f:
|
124 |
current_content = f.read()
|
125 |
edit_prompt = (
|
126 |
f"You are an expert Python developer. Here is the current content of `{file_path}`:\n"
|
127 |
+
f"{current_content}\n"
|
128 |
f"Please edit this file to: {edit_instruction}.\n"
|
129 |
f"Output ONLY the new Python code, no explanations or markdown."
|
130 |
)
|
|
|
132 |
response = model.generate_content(edit_prompt)
|
133 |
new_code = clean_code_blocks(response.text.strip())
|
134 |
if not new_code or "def " not in new_code:
|
135 |
+
await progress_msg.edit(f"Edit failed: No valid code returned.")
|
136 |
return
|
137 |
with open(file_path, "w", encoding="utf-8") as f:
|
138 |
f.write(new_code)
|
|
|
139 |
if file_path.startswith("modules/") and file_path.endswith(".py"):
|
140 |
mod_name = os.path.basename(file_path)[:-3]
|
141 |
try:
|
|
|
144 |
mod.bot = bot
|
145 |
spec.loader.exec_module(mod)
|
146 |
except Exception as test_error:
|
147 |
+
await progress_msg.edit(f"Edit applied, but module reload failed: {test_error}")
|
148 |
return
|
149 |
+
await progress_msg.edit(f"Edit applied to `{file_path}`. Restarting bot...")
|
150 |
await asyncio.sleep(2)
|
151 |
asyncio.create_task(restart_bot(message.chat.id))
|
152 |
return
|
153 |
except Exception as e:
|
154 |
+
await progress_msg.edit(f"Edit failed: `{str(e)[:100]}...`")
|
155 |
return
|
156 |
else:
|
157 |
+
await progress_msg.edit("Could not parse edit command. Use: 'edit <file> <instruction>'")
|
158 |
return
|
|
|
159 |
|
160 |
success = False
|
161 |
code = ""
|
162 |
last_error = None
|
163 |
for attempt in range(1, 6):
|
164 |
+
await progress_msg.edit(f"Attempt {attempt}/5: Thinking and generating code...\n- Executing prerequisite shell commands...")
|
165 |
|
166 |
try:
|
167 |
prompt = (
|
|
|
182 |
code = clean_code_blocks(response.text.strip())
|
183 |
|
184 |
if "def " not in code or "@bot" not in code:
|
185 |
+
await progress_msg.edit(f"Attempt {attempt}: Invalid function or handler.")
|
186 |
continue
|
187 |
|
|
|
188 |
import re
|
189 |
file_path_match = re.search(r"(modules/[\w\-]+\.py)", description)
|
190 |
if file_path_match:
|
|
|
193 |
else:
|
194 |
mod_name = extract_module_name_from_description(description)
|
195 |
mod_path = f"modules/{mod_name}.py"
|
196 |
+
|
197 |
if os.path.exists(mod_path):
|
198 |
with open(mod_path, "r", encoding="utf-8") as f:
|
199 |
current_content = f.read()
|
200 |
edit_prompt = (
|
201 |
f"You are an expert Python developer. Here is the current content of `{mod_path}`:\n"
|
202 |
+
f"{current_content}\n"
|
203 |
f"Please update this file to: {description}.\n"
|
204 |
f"Output ONLY the new Python code, no explanations or markdown."
|
205 |
)
|
206 |
response = model.generate_content(edit_prompt)
|
207 |
code = clean_code_blocks(response.text.strip())
|
|
|
208 |
|
209 |
with open(mod_path, "w", encoding="utf-8") as f:
|
210 |
f.write(code)
|
211 |
|
212 |
+
await progress_msg.edit(f"Attempt {attempt}/5: Thinking and generating code...\n- Executing prerequisite shell commands...\n- Testing generated code...")
|
213 |
|
214 |
try:
|
215 |
spec = importlib.util.spec_from_file_location(mod_name, mod_path)
|
|
|
219 |
except Exception as test_error:
|
220 |
raise RuntimeError(f"Testing error: {test_error}")
|
221 |
|
222 |
+
commands = extract_commands(code)
|
223 |
+
commands_str = ', '.join(f'/{cmd}' for cmd in commands) if commands else 'No commands found.'
|
224 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
try:
|
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"
|
|
|
233 |
explanation = explain_response.text.strip()
|
234 |
except Exception as exp_explain:
|
235 |
explanation = f"Could not generate explanation: {exp_explain}"
|
236 |
+
|
237 |
+
await progress_msg.edit(
|
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 |
+
parse_mode=ParseMode.MARKDOWN
|
243 |
+
)
|
244 |
+
|
|
|
|
|
|
|
|
|
245 |
await asyncio.sleep(2)
|
246 |
asyncio.create_task(restart_bot(message.chat.id))
|
247 |
success = True
|
|
|
249 |
|
250 |
except Exception as e:
|
251 |
last_error = e
|
|
|
|
|
|
|
252 |
try:
|
253 |
+
await progress_msg.edit(f"Attempt {attempt} Error: {str(e)[:100]}...")
|
254 |
+
except:
|
255 |
+
await message.reply(f"Attempt {attempt} failed. Check logs.")
|
|
|
|
|
|
|
|
|
|
|
256 |
|
257 |
if not success:
|
258 |
+
await progress_msg.edit("All 5 attempts failed. Please try again with a simpler instruction.")
|
259 |
|
|
|
260 |
@bot.on_message(filters.command("modules") & filters.private)
|
261 |
async def list_modules(client, message):
|
262 |
+
if message.from_user.id != 7361622601:
|
263 |
+
return await message.reply("Access denied. Only the owner can use this bot.")
|
264 |
modules = [f for f in os.listdir("modules") if f.endswith(".py")]
|
265 |
if modules:
|
266 |
module_list = "\n".join([f"• {m[:-3]}" for m in modules])
|
267 |
+
await message.reply(f"Loaded Modules:\n{module_list}", parse_mode=ParseMode.MARKDOWN)
|
268 |
else:
|
269 |
+
await message.reply("No modules found.", parse_mode=ParseMode.MARKDOWN)
|
270 |
|
|
|
271 |
@bot.on_message(filters.command("delete") & filters.private)
|
272 |
async def delete_module(client, message):
|
273 |
+
if message.from_user.id != 7361622601:
|
274 |
+
return await message.reply("Access denied. Only the owner can use this bot.")
|
275 |
if len(message.command) < 2:
|
276 |
+
return await message.reply("Specify module name.\n\nExample: /delete calculator", parse_mode=ParseMode.MARKDOWN)
|
|
|
277 |
mod_name = message.command[1].lower()
|
278 |
mod_path = f"modules/{mod_name}.py"
|
|
|
279 |
if os.path.exists(mod_path):
|
280 |
os.remove(mod_path)
|
281 |
+
await message.reply(f"Deleted {mod_name}.py\nRestart required to take effect.", parse_mode=ParseMode.MARKDOWN)
|
282 |
else:
|
283 |
+
await message.reply(f"Module {mod_name}.py not found.", parse_mode=ParseMode.MARKDOWN)
|
284 |
|
|
|
285 |
@bot.on_message(filters.regex(r"(?i)what( can)? i do\??") & filters.private)
|
286 |
async def what_to_do(_, message):
|
287 |
+
if message.from_user.id != 7361622601:
|
288 |
+
return await message.reply("Access denied. Only the owner can use this bot.")
|
289 |
await message.reply(
|
290 |
+
"Jarvis Assistant\n\n"
|
291 |
"I can generate custom bot modules for you!\n\n"
|
292 |
+
"Commands:\n"
|
293 |
+
"jarvis make a calculator - Natural language trigger\n"
|
294 |
+
"/modules - List all modules\n"
|
295 |
+
"/delete <name> - Delete a module\n\n"
|
296 |
+
"Examples:\n"
|
297 |
+
"jarvis build a reminder system\n"
|
298 |
+
"jarvis create a dice game\n"
|
299 |
+
"jarvis weather checker",
|
300 |
parse_mode=ParseMode.MARKDOWN
|
301 |
)
|
302 |
|
303 |
+
print("Starting Jarvis Bot...")
|
|
|
304 |
load_modules()
|
305 |
+
print("Bot is ready!")
|
306 |
bot.run()
|