Второй стрим
This commit is contained in:
12
app/handlers/events.py
Normal file
12
app/handlers/events.py
Normal 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())
|
0
app/handlers/favorites.py
Normal file
0
app/handlers/favorites.py
Normal file
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)
|
7
app/handlers/simple.py
Normal file
7
app/handlers/simple.py
Normal 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())
|
||||
|
12
app/handlers/single_command.py
Normal file
12
app/handlers/single_command.py
Normal 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("&", "&").replace("<", "<").replace(">", ">")
|
||||
await message.answer(views.user_command(res), parse_mode="HTML")
|
@ -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")
|
Reference in New Issue
Block a user