Added updates checker

This commit is contained in:
Profitroll
2023-03-22 11:03:03 +01:00
parent 5ad52aa3f8
commit cc6523f604
4 changed files with 46 additions and 7 deletions

View File

@@ -1,18 +1,20 @@
from os import getpid, path
from datetime import datetime
from os import getpid, path
from sys import exit
from time import time
from traceback import format_exc
from modules.cli import *
from modules.http_client import http_session
from modules.logger import logWrite
from modules.scheduler import scheduler
from modules.utils import configGet, jsonLoad, jsonSave, killProc, locale
from modules.utils import configGet, jsonLoad, jsonSave, locale
# Import ===================================================================================================================================
try:
from pyrogram.sync import idle
from pyrogram.errors import bad_request_400
from dateutil.relativedelta import relativedelta
from pyrogram.errors import bad_request_400
from pyrogram.sync import idle
from modules.app import app
except ModuleNotFoundError:
@@ -22,6 +24,7 @@ except ModuleNotFoundError:
pid = getpid()
version = 0.1
# Work in progress
# def check_forwards(app):
@@ -59,9 +62,10 @@ pid = getpid()
# check_forwards(app)
from plugins.callbacks.shutdown import *
# Imports ==================================================================================================================================
from plugins.commands.general import *
from plugins.callbacks.shutdown import *
if configGet("submit", "mode"):
from plugins.callbacks.nothing import *
@@ -168,6 +172,38 @@ async def main():
f"Could not send startup message to bot owner. Perhaps user has not started the bot yet."
)
if configGet("update", "reports"):
try:
check_update = await http_session.get(
"https://git.end-play.xyz/api/v1/repos/profitroll/TelegramPoster/releases?page=1&limit=1"
)
response = await check_update.json()
if len(response) == 0:
raise ValueError("No bot releases on git found.")
if float(response[0]["tag_name"].replace("v.", "")) > version:
logWrite(
f'New version {response[0]["tag_name"].replace("v.", "")} found (current {version})'
)
await app.send_message(
configGet("owner"),
locale(
"update_available",
"message",
).format(
response[0]["tag_name"],
response[0]["html_url"],
response[0]["body"],
),
)
else:
logWrite(f"No updates found, bot is up to date.")
except bad_request_400.PeerIdInvalid:
logWrite(
f"Could not send startup message to bot owner. Perhaps user has not started the bot yet."
)
except Exception as exp:
logWrite(f"Update check failed due to {exp}: {format_exc()}")
if configGet("post", "mode"):
scheduler.start()