auto updater tess

This commit is contained in:
yasirarism 2023-07-01 20:50:35 +07:00 committed by GitHub
parent 5c642ddeb2
commit ffd8794db0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 33 deletions

View file

@ -149,7 +149,6 @@ async def pypi_getdata(self: Client, callback_query: CallbackQuery):
f"<b>Pip Command:</b> pip3 install {res['info'].get('name', 'Unknown')}\n" f"<b>Pip Command:</b> pip3 install {res['info'].get('name', 'Unknown')}\n"
) )
msg += f"<b>Keywords:</b> {res['info'].get('keywords', 'Unknown')}\n" msg += f"<b>Keywords:</b> {res['info'].get('keywords', 'Unknown')}\n"
await callback_query.message.edit_msg(msg, reply_markup=keyboard)
except Exception as err: except Exception as err:
await callback_query.message.edit_msg(f"ERROR: {err}", reply_markup=keyboard) await callback_query.message.edit_msg(f"ERROR: {err}", reply_markup=keyboard)
return
await callback_query.message.edit_msg(msg, reply_markup=keyboard)

View file

@ -168,6 +168,8 @@ async def ytdl_extractinfo_callback(self: Client, cq: CallbackQuery, strings):
@ratelimiter @ratelimiter
@use_chat_lang() @use_chat_lang()
async def ytdl_gendl_callback(self: Client, cq: CallbackQuery, strings): async def ytdl_gendl_callback(self: Client, cq: CallbackQuery, strings):
if not cq.message.reply_to_message.from_user:
return
match = cq.data.split("|") match = cq.data.split("|")
if cq.from_user.id != cq.message.reply_to_message.from_user.id: if cq.from_user.id != cq.message.reply_to_message.from_user.id:
return await cq.answer(strings("unauth"), True) return await cq.answer(strings("unauth"), True)

View file

@ -1 +1 @@
python3 -m misskaty python3 update.py && python3 -m misskaty

View file

@ -1,5 +1,6 @@
import logging import logging
import os import os
import sys
from subprocess import run as srun from subprocess import run as srun
import requests import requests
@ -7,23 +8,23 @@ from dotenv import load_dotenv
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
CONFIG_FILE_URL = os.environ.get("CONFIG_FILE_URL", "") CONFIG_FILE_URL = environ.get("CONFIG_FILE_URL", "")
try: if len(CONFIG_FILE_URL) != 0:
if len(CONFIG_FILE_URL) == 0:
raise TypeError
try: try:
res = requests.get(CONFIG_FILE_URL) res = requests.get(CONFIG_FILE_URL)
if res.status_code == 200: if res.status_code == 200:
with open("config.env", "wb+") as f: with open("config.env", "wb+") as c:
f.write(res.content) c.write(res.content)
LOGGER.info("Config env has successfully writed")
else: else:
LOGGER.error(f"config.env err: {res.status_code}") LOGGER.info(
f"config.env error: {res.status_code}\nMake sure ur config.env found in workdir, will continuing with config.env on workdir"
)
except Exception as e: except Exception as e:
LOGGER.error(f"ENV_URL: {e}") LOGGER.error(f"Something wrong while downloading config.env > {str(e)}")
except: sys.exit(0)
pass
load_dotenv("config.env", override=True) load_dotenv('config.env', override=True)
UPSTREAM_REPO_URL = os.environ.get("UPSTREAM_REPO_URL", "") UPSTREAM_REPO_URL = os.environ.get("UPSTREAM_REPO_URL", "")
if len(UPSTREAM_REPO_URL) == 0: if len(UPSTREAM_REPO_URL) == 0:
@ -33,28 +34,19 @@ UPSTREAM_REPO_BRANCH = os.environ.get("UPSTREAM_REPO_BRANCH", "")
if len(UPSTREAM_REPO_BRANCH) == 0: if len(UPSTREAM_REPO_BRANCH) == 0:
UPSTREAM_REPO_BRANCH = "master" UPSTREAM_REPO_BRANCH = "master"
if UPSTREAM_REPO_URL is not None: if UPSTREAM_REPO is not None and UPSTREAM_BRANCH is not None:
if os.path.exists(".git"): if os.path.exists('.git'):
srun(["rm", "-rf", ".git"], check=True) srun(["rm", "-rf", ".git"])
update = srun([f"git init -q \
update = srun(
[
f"git init -q \
&& git config --global user.email mail@yasir.eu.org \ && git config --global user.email mail@yasir.eu.org \
&& git config --global user.name yasirarism \ && git config --global user.name YasirArisM \
&& git add . \ && git add . \
&& git commit -sm update -q \ && git commit -sm update -q \
&& git remote add origin {UPSTREAM_REPO_URL} \ && git remote add origin {UPSTREAM_REPO} \
&& git fetch origin -q \ && git fetch origin -q \
&& git reset --hard origin/{UPSTREAM_REPO_BRANCH} -q" && git reset --hard origin/{UPSTREAM_BRANCH} -q"], shell=True)
],
shell=True,
check=True,
)
if update.returncode == 0: if update.returncode == 0:
LOGGER.error("Successfully updated with latest commit from UPSTREAM_REPO") logging.info(f'Successfully updated with latest commit branch > {UPSTREAM_BRANCH}')
else: else:
LOGGER.error( logging.error(f'Something went wrong while updating, check UPSTREAM_REPO if valid or not! return code: {update.returncode}')
"Something went wrong while updating, check UPSTREAM_REPO if valid or not!" sys.exit(1)
)