Improve version checker to notify only on new versions
This commit is contained in:
@ -2,6 +2,7 @@ import telebot
|
|||||||
import subprocess
|
import subprocess
|
||||||
import shlex
|
import shlex
|
||||||
import time
|
import time
|
||||||
|
import re
|
||||||
from utils.command import *
|
from utils.command import *
|
||||||
|
|
||||||
def check_version():
|
def check_version():
|
||||||
@ -9,13 +10,23 @@ def check_version():
|
|||||||
try:
|
try:
|
||||||
args = shlex.split(command)
|
args = shlex.split(command)
|
||||||
result = subprocess.check_output(args, stderr=subprocess.STDOUT).decode("utf-8").strip()
|
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:
|
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')}")
|
print(f"Error checking version: {e.output.decode('utf-8')}")
|
||||||
|
notify_admins(error_message)
|
||||||
|
|
||||||
def notify_admins(message):
|
def notify_admins(message):
|
||||||
for admin_id in ADMIN_USER_IDS:
|
for admin_id in ADMIN_USER_IDS:
|
||||||
|
try:
|
||||||
bot.send_message(admin_id, message)
|
bot.send_message(admin_id, message)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Failed to notify admin {admin_id}: {str(e)}")
|
||||||
|
|
||||||
def version_monitoring():
|
def version_monitoring():
|
||||||
while True:
|
while True:
|
||||||
|
|||||||
Reference in New Issue
Block a user