mirror of https://github.com/coddrago/Heroku
[+] Fix database conversion | Auto-converting old-type config after update
parent
f88c2e0e1b
commit
3ffe206314
|
@ -15,6 +15,7 @@ import collections
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import time
|
import time
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
|
@ -143,7 +144,9 @@ class Database(dict):
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.update(**json.loads(self._db_file.read_text()))
|
db = self._db_file.read_text()
|
||||||
|
db = re.sub(r'(hikka\.)(\S+\":)', lambda m: 'heroku.' + m.group(2), db)
|
||||||
|
self.update(**json.loads(db))
|
||||||
except json.decoder.JSONDecodeError:
|
except json.decoder.JSONDecodeError:
|
||||||
logger.warning("Database read failed! Creating new one...")
|
logger.warning("Database read failed! Creating new one...")
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
|
|
|
@ -233,18 +233,22 @@ 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)
|
||||||
|
|
||||||
|
def _convert(self, backup):
|
||||||
|
fixed = re.sub(r'(hikka\.)(\S+\":)', lambda m: 'heroku.' + m.group(2), backup)
|
||||||
|
txt = io.BytesIO(fixed.encode())
|
||||||
|
txt.name = f"db-converted-{datetime.datetime.now():%d-%m-%Y-%H-%M}.json"
|
||||||
|
return txt
|
||||||
|
|
||||||
async def convert(self, call: BotInlineCall, ans, file):
|
async def convert(self, call: BotInlineCall, ans, file):
|
||||||
if ans == "y":
|
if ans == "y":
|
||||||
await utils.answer(
|
await utils.answer(
|
||||||
call,
|
call,
|
||||||
self.strings["converting_db"]
|
self.strings["converting_db"]
|
||||||
)
|
)
|
||||||
fixed = re.sub(r'(hikka.)(\S+\":)', lambda m: 'heroku.' + m.group(2), file)
|
backup = self._convert(file)
|
||||||
txt = io.BytesIO(fixed.encode())
|
|
||||||
txt.name = f"db-converted-{datetime.datetime.now():%d-%m-%Y-%H-%M}.json"
|
|
||||||
await utils.answer_file(
|
await utils.answer_file(
|
||||||
call,
|
call,
|
||||||
txt,
|
backup,
|
||||||
caption=self.strings("backup_caption").format(
|
caption=self.strings("backup_caption").format(
|
||||||
prefix=utils.escape_html(self.get_prefix())
|
prefix=utils.escape_html(self.get_prefix())
|
||||||
),
|
),
|
||||||
|
@ -288,7 +292,7 @@ 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 re.search(r'"(hikka\.)(\S+\":)', file.decode()):
|
||||||
await utils.answer(message,
|
await utils.answer(message,
|
||||||
self.strings["db_warning"],
|
self.strings["db_warning"],
|
||||||
reply_markup=
|
reply_markup=
|
||||||
|
|
Loading…
Reference in New Issue