Skip to content
View ayannn09786's full-sized avatar

Block or report ayannn09786

Block user

Prevent this user from interacting with your repositories and sending you notifications. Learn more about blocking users.

You must be logged in to block users.

Please don't include any personal information such as legal names or email addresses. Maximum 100 characters, markdown supported. This note will be visible to only you.
Report abuse

Contact GitHub support about this user’s behavior. Learn more about reporting abuse.

Report abuse
ayannn09786/README.md

import subprocess import time import logging from aiogram import Bot import asyncio

API_TOKEN = 'TOKEN' ADMIN_ID = 'Your Id' MAX_RESTARTS = 5 RESTART_PERIOD = 60 # Seconds

logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') bot = Bot(API_TOKEN)

def start_bot(): """Start the bot script as a subprocess.""" return subprocess.Popen(['python3', 'm.py'])

async def notify_admin(message): """Send a notification message to the admin via Telegram.""" try: await bot.send_message(ADMIN_ID, message) logging.info("Admin notified: %s", message) except Exception as e: logging.error("Failed to send message to admin: %s", e)

async def main(): """Main function to manage bot process lifecycle.""" restart_count = 0 last_restart_time = time.time()

while True:
    if restart_count >= MAX_RESTARTS:
        current_time = time.time()
        if current_time - last_restart_time < RESTART_PERIOD:
            wait_time = RESTART_PERIOD - (current_time - last_restart_time)
            logging.warning("Maximum restart limit reached. Waiting for %.2f seconds...", wait_time)
            await notify_admin(f"⚠️ Maximum restart limit reached. Waiting for {int(wait_time)} seconds before retrying.")
            await asyncio.sleep(wait_time)
        restart_count = 0
        last_restart_time = time.time()

    logging.info("Starting the bot...")
    process = start_bot()
    await notify_admin("🚀 Bot is starting...")

    while process.poll() is None:
        await asyncio.sleep(5)

    logging.warning("Bot process terminated. Restarting in 10 seconds...")
    await notify_admin("⚠️ The bot has crashed and will be restarted in 10 seconds.")
    restart_count += 1
    await asyncio.sleep(10)

if name == 'main': try: asyncio.run(main()) except KeyboardInterrupt: logging.info("Venom script terminated by user.")

Popular repositories Loading

  1. ayannn09786 ayannn09786 Public

    Config files for my GitHub profile.

    1