mirror of https://github.com/coddrago/Heroku
update heroku_backup.py
parent
0fbdba8a9c
commit
9bd6aa32e0
|
@ -17,6 +17,7 @@ import io
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import time
|
import time
|
||||||
import zipfile
|
import zipfile
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
@ -232,6 +233,37 @@ class HerokuBackupMod(loader.Module):
|
||||||
logger.exception("Restore from backupall failed")
|
logger.exception("Restore from backupall failed")
|
||||||
await call.answer(self.strings("reply_to_file"), show_alert=True)
|
await call.answer(self.strings("reply_to_file"), show_alert=True)
|
||||||
|
|
||||||
|
async def convert(self, call: BotInlineCall, ans, file):
|
||||||
|
if ans == "y":
|
||||||
|
await utils.answer(
|
||||||
|
call,
|
||||||
|
self.strings["converting_db"]
|
||||||
|
)
|
||||||
|
fixed = re.sub(r'(hikka.)(\S+\":)', lambda m: 'heroku.' + m.group(2), file)
|
||||||
|
txt = io.BytesIO(fixed.encode())
|
||||||
|
txt.name = f"db-converted-{datetime.datetime.now():%d-%m-%Y-%H-%M}.json"
|
||||||
|
await utils.answer_file(
|
||||||
|
call,
|
||||||
|
txt,
|
||||||
|
caption=self.strings("backup_caption").format(
|
||||||
|
prefix=utils.escape_html(self.get_prefix())
|
||||||
|
),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
await utils.answer(
|
||||||
|
call,
|
||||||
|
self.strings["advice_converting"],
|
||||||
|
reply_markup=
|
||||||
|
[
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"text": self.strings["close_btn"],
|
||||||
|
"action": "close"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
@loader.command()
|
@loader.command()
|
||||||
async def backupdb(self, message: Message):
|
async def backupdb(self, message: Message):
|
||||||
txt = io.BytesIO(json.dumps(self._db).encode())
|
txt = io.BytesIO(json.dumps(self._db).encode())
|
||||||
|
@ -256,6 +288,25 @@ class HerokuBackupMod(loader.Module):
|
||||||
|
|
||||||
file = await reply.download_media(bytes)
|
file = await reply.download_media(bytes)
|
||||||
decoded_text = json.loads(file.decode())
|
decoded_text = json.loads(file.decode())
|
||||||
|
if re.match(r'(hikka.)(\S+\":)', file.decode()):
|
||||||
|
if self.strings.get("warn") is not None:
|
||||||
|
await utils.answer(message,
|
||||||
|
self.strings["db_warning"],
|
||||||
|
reply_markup=
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"text": "❌",
|
||||||
|
"callback": self.convert,
|
||||||
|
"args": ("n", file.decode(),),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"text": "✅",
|
||||||
|
"callback": self.convert,
|
||||||
|
"args": ("y", file.decode(),),
|
||||||
|
}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
with contextlib.suppress(KeyError):
|
with contextlib.suppress(KeyError):
|
||||||
decoded_text["heroku.inline"].pop("bot_token")
|
decoded_text["heroku.inline"].pop("bot_token")
|
||||||
|
|
|
@ -142,7 +142,7 @@ class HerokuInfoMod(loader.Module):
|
||||||
platform = platform.replace(emoji, icon)
|
platform = platform.replace(emoji, icon)
|
||||||
return (
|
return (
|
||||||
(
|
(
|
||||||
"<b>🪐 Heroku</b>\n"
|
"🪐 Heroku\n"
|
||||||
if self.config["show_heroku"]
|
if self.config["show_heroku"]
|
||||||
else ""
|
else ""
|
||||||
)
|
)
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
# You can redistribute it and/or modify it under the terms of the GNU AGPLv3
|
# You can redistribute it and/or modify it under the terms of the GNU AGPLv3
|
||||||
# 🔑 https://www.gnu.org/licenses/agpl-3.0.html
|
# 🔑 https://www.gnu.org/licenses/agpl-3.0.html
|
||||||
|
|
||||||
__version__ = (1, 6, 9)
|
__version__ = (1, 7, 0)
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
|
@ -254,7 +254,7 @@ class Web:
|
||||||
return web.Response(status=403, body="Forbidden by JamHost EULA")
|
return web.Response(status=403, body="Forbidden by JamHost EULA")
|
||||||
|
|
||||||
if "HIKKAHOST" in os.environ:
|
if "HIKKAHOST" in os.environ:
|
||||||
return web.Response(status=403, body="Forbidden by HerokuHost EULA")
|
return web.Response(status=403, body="Forbidden by HikkaHost EULA")
|
||||||
|
|
||||||
if not self._check_session(request):
|
if not self._check_session(request):
|
||||||
return web.Response(status=401)
|
return web.Response(status=401)
|
||||||
|
@ -335,7 +335,7 @@ class Web:
|
||||||
return web.Response(status=403, body="Forbidden by JamHost EULA")
|
return web.Response(status=403, body="Forbidden by JamHost EULA")
|
||||||
|
|
||||||
if "HIKKAHOST" in os.environ:
|
if "HIKKAHOST" in os.environ:
|
||||||
return web.Response(status=403, body="Forbidden by HerokuHost EULA")
|
return web.Response(status=403, body="Forbidden by HikkaHost EULA")
|
||||||
|
|
||||||
if self._pending_client:
|
if self._pending_client:
|
||||||
return web.Response(status=208, body="Already pending")
|
return web.Response(status=208, body="Already pending")
|
||||||
|
|
Loading…
Reference in New Issue