Improve version checker to notify only on new versions

This commit is contained in:
Whispering Wind
2025-03-12 11:23:26 +03:30
committed by GitHub
parent 242701c793
commit 39fecd942e

View File

@ -2,6 +2,7 @@ import telebot
import subprocess
import shlex
import time
import re
from utils.command import *
def check_version():
@ -9,13 +10,23 @@ def check_version():
try:
args = shlex.split(command)
result = subprocess.check_output(args, stderr=subprocess.STDOUT).decode("utf-8").strip()
notify_admins(result)
panel_version = re.search(r'Panel Version: (\d+\.\d+\.\d+)', result)
latest_version = re.search(r'Latest Version: (\d+\.\d+\.\d+)', result)
if panel_version and latest_version and panel_version.group(1) != latest_version.group(1):
notify_admins(f"🔔 New version available!\n\n{result}")
except subprocess.CalledProcessError as e:
error_message = f"Error checking version: {e.output.decode('utf-8')}"
print(f"Error checking version: {e.output.decode('utf-8')}")
notify_admins(error_message)
def notify_admins(message):
for admin_id in ADMIN_USER_IDS:
bot.send_message(admin_id, message)
try:
bot.send_message(admin_id, message)
except Exception as e:
print(f"Failed to notify admin {admin_id}: {str(e)}")
def version_monitoring():
while True: