Spaces:
Running
Running
File size: 1,263 Bytes
9e317fd de048da 9e317fd de048da 9e317fd de048da 9e317fd de048da 9e317fd de048da 9e317fd de048da 9e317fd de048da 9e317fd de048da 9e317fd de048da | 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 | import telebot
import subprocess
import os
import time
bot = telebot.TeleBot("8150956564:AAHmU5PgnEFAMcnttF2Sy-xWTs3Gj-fAg7Y")
ADMIN_ID = 6509375663
@bot.message_handler(commands=['run'])
def run_command(message):
if message.from_user.id != ADMIN_ID:
return
text_split = message.text.split(maxsplit=1)
if len(text_split) < 2:
bot.reply_to(message, "Usage: /run <command>")
return
command = text_split[1]
msg = bot.reply_to(message, "⚙️ Executing...")
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
output = ""
last_send_time = time.time()
for line in iter(process.stdout.readline, ""):
output += line
# Update message every 2 seconds to avoid Telegram ban
if time.time() - last_send_time > 2:
try:
bot.edit_message_text(f"🚀 **Output:**\n`{output[-1000:]}`", message.chat.id, msg.message_id, parse_mode="Markdown")
last_send_time = time.time()
except:
pass
process.wait()
bot.send_message(message.chat.id, f"✅ **Finished:**\n`{output[-1000:]}`", parse_mode="Markdown")
bot.polling(non_stop=True)
|