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"
)
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:
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
@use_chat_lang()
async def ytdl_gendl_callback(self: Client, cq: CallbackQuery, strings):
if not cq.message.reply_to_message.from_user:
return
match = cq.data.split("|")
if cq.from_user.id != cq.message.reply_to_message.from_user.id:
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 os
import sys
from subprocess import run as srun
import requests
@ -7,23 +8,23 @@ from dotenv import load_dotenv
LOGGER = logging.getLogger(__name__)
CONFIG_FILE_URL = os.environ.get("CONFIG_FILE_URL", "")
try:
if len(CONFIG_FILE_URL) == 0:
raise TypeError
CONFIG_FILE_URL = environ.get("CONFIG_FILE_URL", "")
if len(CONFIG_FILE_URL) != 0:
try:
res = requests.get(CONFIG_FILE_URL)
if res.status_code == 200:
with open("config.env", "wb+") as f:
f.write(res.content)
with open("config.env", "wb+") as c:
c.write(res.content)
LOGGER.info("Config env has successfully writed")
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:
LOGGER.error(f"ENV_URL: {e}")
except:
pass
LOGGER.error(f"Something wrong while downloading config.env > {str(e)}")
sys.exit(0)
load_dotenv("config.env", override=True)
load_dotenv('config.env', override=True)
UPSTREAM_REPO_URL = os.environ.get("UPSTREAM_REPO_URL", "")
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:
UPSTREAM_REPO_BRANCH = "master"
if UPSTREAM_REPO_URL is not None:
if os.path.exists(".git"):
srun(["rm", "-rf", ".git"], check=True)
update = srun(
[
f"git init -q \
if UPSTREAM_REPO is not None and UPSTREAM_BRANCH is not None:
if os.path.exists('.git'):
srun(["rm", "-rf", ".git"])
update = srun([f"git init -q \
&& git config --global user.email mail@yasir.eu.org \
&& git config --global user.name yasirarism \
&& git config --global user.name YasirArisM \
&& git add . \
&& git commit -sm update -q \
&& git remote add origin {UPSTREAM_REPO_URL} \
&& git remote add origin {UPSTREAM_REPO} \
&& git fetch origin -q \
&& git reset --hard origin/{UPSTREAM_REPO_BRANCH} -q"
],
shell=True,
check=True,
)
&& git reset --hard origin/{UPSTREAM_BRANCH} -q"], shell=True)
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:
LOGGER.error(
"Something went wrong while updating, check UPSTREAM_REPO if valid or not!"
)
logging.error(f'Something went wrong while updating, check UPSTREAM_REPO if valid or not! return code: {update.returncode}')
sys.exit(1)