⬇️ Remove auto-update

This commit is contained in:
xtaodada 2022-03-13 20:24:10 +08:00
parent 36f1af2f04
commit 85e411c8e9
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659

View File

@ -3,20 +3,15 @@
import platform import platform
from datetime import datetime from datetime import datetime
from distutils.util import strtobool from distutils.util import strtobool
from json import JSONDecodeError, loads, load
from os import remove from os import remove
from os.path import exists
from subprocess import run, PIPE from subprocess import run, PIPE
from sys import executable from sys import executable
from git import Repo from git import Repo
from git.exc import GitCommandError, InvalidGitRepositoryError, NoSuchPathError from git.exc import GitCommandError, InvalidGitRepositoryError, NoSuchPathError
from telethon.tl.functions.channels import GetFullChannelRequest from pagermaid import log, config, silent, redis_status, redis
from pagermaid import log, config, silent, scheduler, bot, version, working_dir, logs, redis_status, redis
from pagermaid.listener import listener from pagermaid.listener import listener
from pagermaid.modules.plugin import remove_plugin, update_version, download
from pagermaid.utils import execute, lang, alias_command from pagermaid.utils import execute, lang, alias_command
try: try:
@ -27,56 +22,6 @@ except KeyError:
need_update_check = True need_update_check = True
@scheduler.scheduled_job("cron", minute="*/30", id="0")
async def run_every_30_minute():
try:
await bot(GetFullChannelRequest("PGMUPD1"))
except: # noqa
return
need_restart = False
async for msg in bot.iter_messages("PGMUPD1"):
if msg.text:
try:
security_data = loads(msg.text.strip("`"))
except JSONDecodeError:
continue
for data in security_data["data"]:
if data["mode"] == "master":
if version < data["version"]:
logs.info(lang('update_master'))
await execute("git reset --hard")
await execute("git pull")
await execute(f"{executable} -m pip install -r requirements.txt --upgrade")
await execute(f"{executable} -m pip install -r requirements.txt")
need_restart = True
break
elif data["mode"] == "plugins":
if not exists(f"{working_dir}/plugins/version.json"):
continue
with open(f"{working_dir}/plugins/version.json", 'r', encoding="utf-8") as f:
try:
version_json = load(f)
except JSONDecodeError:
continue
try:
plugin_version = version_json.get(data["name"])
if plugin_version is None:
continue
except AttributeError:
continue
if (float(data["version"]) - float(plugin_version)) > 0:
logs.info(lang('update_plugins'))
remove_plugin(data["name"])
await download(data["name"])
update_version(data["name"], data["version"])
need_restart = True
if need_restart:
await bot.disconnect()
@listener(is_plugin=False, outgoing=True, command=alias_command("update"), @listener(is_plugin=False, outgoing=True, command=alias_command("update"),
description=lang('update_des'), description=lang('update_des'),
parameters="<true/debug>") parameters="<true/debug>")