From 5c57c4c42b38ee1ef9d79dbc9b4f11b9cd16e4c7 Mon Sep 17 00:00:00 2001 From: levina <82658782+levina-lab@users.noreply.github.com> Date: Sat, 26 Feb 2022 20:44:28 +0700 Subject: [PATCH] [check] some fixes fixed the restarted function --- program/updater.py | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/program/updater.py b/program/updater.py index f2fd8cf..d002c23 100644 --- a/program/updater.py +++ b/program/updater.py @@ -1,3 +1,23 @@ +""" +Video + Music Stream Telegram Bot +Copyright (c) 2022-present levina=lab + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but without any warranty; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see +""" + + +import os import sys from git import Repo @@ -6,6 +26,8 @@ from git.exc import InvalidGitRepositoryError from pyrogram.types import Message from pyrogram import Client, filters + +from program import LOGS from config import UPSTREAM_REPO, BOT_USERNAME from driver.filters import command @@ -68,8 +90,11 @@ async def update_bot(_, message: Message): @Client.on_message(command(["restart", f"restart@{BOT_USERNAME}"]) & ~filters.edited) @bot_creator async def restart_bot(_, message: Message): - msg = await message.reply("❖ Restarting bot...") - args = [sys.executable, "main.py"] - await msg.edit("✅ Bot restarted !\n\n• wait until 1 minutes after bot Rebooted.") - execle(sys.executable, *args, environ) - return + try: + msg = await message.reply_text("❖ Restarting bot...") + LOGS.info("[INFO]: BOT SERVER RESTARTED !!") + except BaseException as err: + LOGS.info(f"[ERROR]: {err}") + return + await msg.edit_text("✅ Bot has restarted !\n\n» back active again in 5-10 seconds.") + os.system(f"kill -9 {os.getpid()} && python3 main.py")