mirror of https://github.com/coddrago/Heroku
Add ability to disable automatic backups
parent
74ae9ecb57
commit
6b1d20d0f8
|
@ -19,9 +19,7 @@ import asyncio
|
||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
import datetime
|
import datetime
|
||||||
from telethon.tl.functions.channels import (
|
from telethon.tl.functions.channels import EditPhotoRequest
|
||||||
EditPhotoRequest
|
|
||||||
)
|
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
@ -36,7 +34,8 @@ class HikkaBackupMod(loader.Module):
|
||||||
"name": "HikkaBackup",
|
"name": "HikkaBackup",
|
||||||
"period": "⌚️ <b>Hewwo! I'm Asuna</b> - your personal backup manager. Please, select the periodicity of automatic database backups",
|
"period": "⌚️ <b>Hewwo! I'm Asuna</b> - your personal backup manager. Please, select the periodicity of automatic database backups",
|
||||||
"saved": "✅ Backup period saved. You can re-configure it later with .set_backup_period",
|
"saved": "✅ Backup period saved. You can re-configure it later with .set_backup_period",
|
||||||
"invalid_args": "🚫 <b>Specify correct backup period in hours</b>",
|
"never": "✅ I will not make automatic backups. You can re-configure it later with .set_backup_period",
|
||||||
|
"invalid_args": "🚫 <b>Specify correct backup period in hours, or `0` to disable</b>",
|
||||||
}
|
}
|
||||||
|
|
||||||
async def on_unload(self) -> None:
|
async def on_unload(self) -> None:
|
||||||
|
@ -59,6 +58,7 @@ class HikkaBackupMod(loader.Module):
|
||||||
],
|
],
|
||||||
3,
|
3,
|
||||||
)
|
)
|
||||||
|
+ [[{"text": "🚫 Never", "data": "backup_period/never"}]]
|
||||||
),
|
),
|
||||||
parse_mode="HTML",
|
parse_mode="HTML",
|
||||||
)
|
)
|
||||||
|
@ -97,6 +97,16 @@ class HikkaBackupMod(loader.Module):
|
||||||
if not call.data.startswith("backup_period"):
|
if not call.data.startswith("backup_period"):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if call.data == "backup_period/never":
|
||||||
|
self.set("period", "disabled")
|
||||||
|
await call.answer(self.strings("never"), show_alert=True)
|
||||||
|
|
||||||
|
await self.inline.bot.delete_message(
|
||||||
|
call.message.chat.id,
|
||||||
|
call.message.message_id,
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
period = int(call.data.split("/")[1]) * 60 * 60
|
period = int(call.data.split("/")[1]) * 60 * 60
|
||||||
|
|
||||||
self.set("period", period)
|
self.set("period", period)
|
||||||
|
@ -112,10 +122,15 @@ class HikkaBackupMod(loader.Module):
|
||||||
async def set_backup_periodcmd(self, message: Message) -> None:
|
async def set_backup_periodcmd(self, message: Message) -> None:
|
||||||
"""<time in hours> - Change backup frequency"""
|
"""<time in hours> - Change backup frequency"""
|
||||||
args = utils.get_args_raw(message)
|
args = utils.get_args_raw(message)
|
||||||
if not args or not args.isdigit() or int(args) not in range(1, 200):
|
if not args or not args.isdigit() or int(args) not in range(200):
|
||||||
await utils.answer(message, self.strings("invalid_args"))
|
await utils.answer(message, self.strings("invalid_args"))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not int(args):
|
||||||
|
self.set("period", "disabled")
|
||||||
|
await utils.answer(message, f"<b>{self.strings('never')}</b>")
|
||||||
|
return
|
||||||
|
|
||||||
period = int(args) * 60 * 60
|
period = int(args) * 60 * 60
|
||||||
self.set("period", period)
|
self.set("period", period)
|
||||||
self.set("last_backup", round(time.time()))
|
self.set("last_backup", round(time.time()))
|
||||||
|
@ -133,6 +148,9 @@ class HikkaBackupMod(loader.Module):
|
||||||
await asyncio.sleep(self.get("period"))
|
await asyncio.sleep(self.get("period"))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if self.get("period") == "disabled":
|
||||||
|
return
|
||||||
|
|
||||||
await asyncio.sleep(
|
await asyncio.sleep(
|
||||||
self.get("last_backup") + self.get("period") - time.time()
|
self.get("last_backup") + self.get("period") - time.time()
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue