chess / bot.py
SulikProMax's picture
Update bot.py
de048da verified
Raw
History Blame Contribute Delete
1.26 kB
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)