chore(userbot): apply ruff check --fix and ruff format
- ruff check --fix: 210 auto-fixed errors (import sorting, trailing whitespace, unused imports, f-string fixups, deprecated annotations) - ruff format: 104 files reformatted to consistent style - 268 non-auto-fixable issues remain (S113 requests timeout, etc.)
This commit is contained in:
+12
-13
@@ -14,21 +14,20 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from subprocess import Popen, PIPE, TimeoutExpired
|
||||
import os
|
||||
from subprocess import PIPE, Popen, TimeoutExpired
|
||||
from time import perf_counter
|
||||
|
||||
from pyrogram import Client, filters
|
||||
from pyrogram.types import Message
|
||||
from pyrogram.errors import MessageTooLong
|
||||
|
||||
from pyrogram.types import Message
|
||||
from utils.misc import modules_help, prefix
|
||||
|
||||
|
||||
@Client.on_message(filters.command(["shell", "sh"], prefix) & filters.me)
|
||||
@Client.on_message(filters.command(['shell', 'sh'], prefix) & filters.me)
|
||||
async def shell(_, message: Message):
|
||||
if len(message.command) < 2:
|
||||
return await message.edit("<b>Specify the command in message text</b>")
|
||||
return await message.edit('<b>Specify the command in message text</b>')
|
||||
cmd_text = message.text.split(maxsplit=1)[1]
|
||||
cmd_args = cmd_text.split()
|
||||
cmd_obj = Popen(
|
||||
@@ -38,22 +37,22 @@ async def shell(_, message: Message):
|
||||
text=True,
|
||||
)
|
||||
|
||||
char = "#" if os.getuid() == 0 else "$"
|
||||
text = f"<b>{char}</b> <code>{cmd_text}</code>\n\n"
|
||||
char = '#' if os.getuid() == 0 else '$'
|
||||
text = f'<b>{char}</b> <code>{cmd_text}</code>\n\n'
|
||||
|
||||
await message.edit(text + "<b>Running...</b>")
|
||||
await message.edit(text + '<b>Running...</b>')
|
||||
try:
|
||||
start_time = perf_counter()
|
||||
stdout, stderr = cmd_obj.communicate(timeout=60)
|
||||
except TimeoutExpired:
|
||||
text += "<b>Timeout expired (60 seconds)</b>"
|
||||
text += '<b>Timeout expired (60 seconds)</b>'
|
||||
else:
|
||||
stop_time = perf_counter()
|
||||
if stdout:
|
||||
text += f"<b>Output:</b>\n<code>{stdout}</code>\n\n"
|
||||
text += f'<b>Output:</b>\n<code>{stdout}</code>\n\n'
|
||||
if stderr:
|
||||
text += f"<b>Error:</b>\n<code>{stderr}</code>\n\n"
|
||||
text += f"<b>Completed in {round(stop_time - start_time, 5)} seconds with code {cmd_obj.returncode}</b>"
|
||||
text += f'<b>Error:</b>\n<code>{stderr}</code>\n\n'
|
||||
text += f'<b>Completed in {round(stop_time - start_time, 5)} seconds with code {cmd_obj.returncode}</b>'
|
||||
try:
|
||||
await message.edit(text)
|
||||
except MessageTooLong:
|
||||
@@ -61,4 +60,4 @@ async def shell(_, message: Message):
|
||||
cmd_obj.kill()
|
||||
|
||||
|
||||
modules_help["shell"] = {"sh [command]*": "Execute command in shell"}
|
||||
modules_help['shell'] = {'sh [command]*': 'Execute command in shell'}
|
||||
|
||||
Reference in New Issue
Block a user