File size: 1,736 Bytes
80287e2 |
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 42 43 44 45 46 |
import subprocess
from pyrogram import Client, filters
from Devine import app
from config import OWNER_ID
@app.on_message(filters.command("redeploy") & filters.user(OWNER_ID))
async def redeploy(client, message):
msg = await message.reply("Starting bot redeployment process...")
try:
await msg.edit("Pulling the latest changes from GitHub...")
pull_process = subprocess.run(
["git", "pull", "origin", "main"],
capture_output=True, text=True
)
if pull_process.returncode != 0:
raise Exception(f"Git pull failed: {pull_process.stderr}")
await msg.edit("Deploying changes to Heroku...")
deploy_process = subprocess.run(
["heroku", "git:remote", "-a", "your-heroku-app-name"],
capture_output=True, text=True
)
if deploy_process.returncode != 0:
raise Exception(f"Heroku remote setup failed: {deploy_process.stderr}")
deploy_process = subprocess.run(
["git", "push", "heroku", "main"],
capture_output=True, text=True
)
if deploy_process.returncode != 0:
raise Exception(f"Git push to Heroku failed: {deploy_process.stderr}")
await msg.edit("Restarting the Heroku app...")
restart_process = subprocess.run(
["heroku", "ps:restart", "--app", "your-heroku-app-name"],
capture_output=True, text=True
)
if restart_process.returncode != 0:
raise Exception(f"Heroku restart failed: {restart_process.stderr}")
await msg.edit("Bot redeployment completed successfully!")
except Exception as e:
await msg.edit(f"Error during redeployment: {str(e)}")
|