Второй стрим
This commit is contained in:
39
app/handlers/multiply_commands.py
Normal file
39
app/handlers/multiply_commands.py
Normal file
@ -0,0 +1,39 @@
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
from aiogram.fsm.context import FSMContext
|
||||
from aiogram.types import Message
|
||||
|
||||
from app import views
|
||||
from app.utils.statesform import ExecuteCommandsSteps
|
||||
|
||||
|
||||
async def multiply_commands(message: Message, state: FSMContext):
|
||||
cwd = os.getcwd()
|
||||
await message.answer(views.exec_command_message(cwd))
|
||||
await state.set_data({"cwd": cwd})
|
||||
await state.set_state(ExecuteCommandsSteps.EXECUTE)
|
||||
|
||||
|
||||
async def execute_commands(message: Message, state: FSMContext):
|
||||
if message.text.lower() == "cancel":
|
||||
await message.answer(views.exec_canceled())
|
||||
await state.clear()
|
||||
else:
|
||||
data = await state.get_data()
|
||||
|
||||
if message.text.lower().split()[0] == "cd":
|
||||
new_cwd = os.path.join(data.get("cwd"), " ".join(message.text.split()[1:]))
|
||||
os.chdir(new_cwd)
|
||||
await state.set_data({"cwd": new_cwd})
|
||||
res = views.changed_dir(new_cwd)
|
||||
else:
|
||||
try:
|
||||
sub = subprocess.check_output(message.text, shell=True, cwd=data.get("cwd"))
|
||||
res = sub.decode().replace("&", "&").replace("<", "<").replace(">", ">")
|
||||
except subprocess.CalledProcessError as e:
|
||||
res = views.subprocess_error(e)
|
||||
|
||||
await message.answer(views.user_command(res), parse_mode="HTML")
|
||||
|
||||
await state.set_state(ExecuteCommandsSteps.EXECUTE)
|
Reference in New Issue
Block a user