Revert "Add lavHost-specific restart and update processors"

This reverts commit 3735d668bd.
pull/1/head
hikariatama 2022-05-06 17:26:00 +00:00
parent 3735d668bd
commit 2b1799492a
1 changed files with 14 additions and 35 deletions

View File

@ -65,8 +65,6 @@ class UpdaterMod(loader.Module):
"restart_confirm": "🔄 <b>Are you sure you want to restart?</b>", "restart_confirm": "🔄 <b>Are you sure you want to restart?</b>",
"update_confirm": "⛵️ <b>Are you sure you want to update?</b>", "update_confirm": "⛵️ <b>Are you sure you want to update?</b>",
"cancel": "🚫 Cancel", "cancel": "🚫 Cancel",
"lavhost_restart": "✌️ <b>Restarting lavHost...</b>",
"lavhost_update": "✌️ <b>Updating lavHost...</b>",
} }
strings_ru = { strings_ru = {
@ -87,8 +85,6 @@ class UpdaterMod(loader.Module):
"_cmd_doc_update": "Обновляет юзербот", "_cmd_doc_update": "Обновляет юзербот",
"_cmd_doc_source": "Ссылка на исходный код проекта", "_cmd_doc_source": "Ссылка на исходный код проекта",
"_cls_doc": "Обновляет юзербот", "_cls_doc": "Обновляет юзербот",
"lavhost_restart": "✌️ <b>Перезагружаю lavHost...</b>",
"lavhost_update": "✌️ <b>Обновляю lavHost...</b>",
} }
def __init__(self): def __init__(self):
@ -119,21 +115,23 @@ class UpdaterMod(loader.Module):
): ):
raise raise
except Exception: except Exception:
message = await utils.answer(message, self.strings("restarting_caption"))
await self.restart_common(message) await self.restart_common(message)
async def inline_restart(self, call: InlineCall): async def inline_restart(self, call: InlineCall):
await call.edit(self.strings("restarting_caption"))
await self.restart_common(call) await self.restart_common(call)
async def inline_close(self, call: InlineCall): async def inline_close(self, call: InlineCall):
await call.delete() await call.delete()
async def save_restart_message(self, call: Union[InlineCall, Message]): async def prerestart_common(self, call: Union[InlineCall, Message]):
self.set( logger.debug(f"Self-update. {sys.executable} -m {utils.get_base_dir()}")
"selfupdatemsg", if hasattr(call, "inline_message_id"):
call.inline_message_id self.set("selfupdatemsg", call.inline_message_id)
if hasattr(call, "inline_message_id") else:
else f"{utils.get_chat_id(call)}:{call.id}", self.set("selfupdatemsg", f"{utils.get_chat_id(call)}:{call.id}")
)
async def restart_common(self, call: Union[InlineCall, Message]): async def restart_common(self, call: Union[InlineCall, Message]):
if ( if (
@ -147,21 +145,7 @@ class UpdaterMod(loader.Module):
else: else:
message = call message = call
call = await utils.answer( await self.prerestart_common(call)
call,
self.strings(
"restarting_caption"
if "LAVHOST" not in os.environ
else "lavhost_restart"
),
)
await self.save_restart_message(call)
if "LAVHOST" in os.environ:
await self._client.send_message("@lavhostbot", "/restart")
return
atexit.register(functools.partial(restart, *sys.argv[1:])) atexit.register(functools.partial(restart, *sys.argv[1:]))
handler = logging.getLogger().handlers[0] handler = logging.getLogger().handlers[0]
handler.setLevel(logging.CRITICAL) handler.setLevel(logging.CRITICAL)
@ -249,20 +233,15 @@ class UpdaterMod(loader.Module):
os.system(f"cd {utils.get_base_dir()} && cd .. && git reset --hard HEAD") # fmt: skip os.system(f"cd {utils.get_base_dir()} && cd .. && git reset --hard HEAD") # fmt: skip
try: try:
if "LAVHOST" in os.environ:
await utils.answer(call, self.strings("lavhost_update"))
await self._client.send_message("@lavhostbot", "/update")
return
try: try:
call = await utils.answer(call, self.strings("downloading")) await utils.answer(call, self.strings("downloading"))
except Exception: except Exception:
pass pass
req_update = await self.download_common() req_update = await self.download_common()
try: try:
call = await utils.answer(call, self.strings("installing")) await utils.answer(call, self.strings("installing"))
except Exception: except Exception:
pass pass
@ -270,7 +249,7 @@ class UpdaterMod(loader.Module):
self.req_common() self.req_common()
try: try:
call = await utils.answer(call, self.strings("restarting_caption")) await utils.answer(call, self.strings("restarting_caption"))
except Exception: except Exception:
pass pass
@ -280,7 +259,7 @@ class UpdaterMod(loader.Module):
await self.inline_update(call, True) await self.inline_update(call, True)
return return
logger.error("Got update loop. Update manually via .terminal") logger.critical("Got update loop. Update manually via .terminal")
return return
@loader.unrestricted @loader.unrestricted