Второй стрим

This commit is contained in:
2024-03-11 01:56:43 +04:00
parent 2649b9136a
commit 62922cf613
11 changed files with 147 additions and 12 deletions

12
app/handlers/events.py Normal file
View File

@ -0,0 +1,12 @@
from app.settings import bot, Secrets
from app.utils.commands import set_commands
from app import views
async def start_bot():
await set_commands(bot)
await bot.send_message(Secrets.admin_id, views.start_bot_message())
async def stop_bot():
await bot.send_message(Secrets.admin_id, views.stop_bot_message())

View File

View 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("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
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)

7
app/handlers/simple.py Normal file
View File

@ -0,0 +1,7 @@
from aiogram.types import Message
from app import views
async def start_command(message: Message):
await message.answer(views.start_text())

View File

@ -0,0 +1,12 @@
import subprocess
from aiogram.types import Message
from app import views
async def execute_command(message: Message):
user_command = message.text.split()[1:]
sub = subprocess.check_output(user_command, shell=True)
res = sub.decode().replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
await message.answer(views.user_command(res), parse_mode="HTML")

View File

@ -1,11 +0,0 @@
import subprocess
from aiogram.types import Message
async def execute_command(message: Message):
user_command = message.text.split()[1:]
print(user_command)
sub = subprocess.check_output(user_command)
# print(sub)
await message.answer(f"<pre><code>{sub.decode()}</code></pre>", parse_mode="HTML")