From 6890caedd854df474407f9cd25701f2a9ea834e0 Mon Sep 17 00:00:00 2001 From: 007 Date: Sun, 25 Jun 2023 00:31:43 +0330 Subject: [PATCH] feat: add backup admin cmd --- bchat/modules/admin/__init__.py | 2 ++ bchat/modules/admin/dev.py | 28 ++++++++++++++++++++++++++++ bchat/modules/admin/misc.py | 1 + 3 files changed, 31 insertions(+) create mode 100644 bchat/modules/admin/dev.py diff --git a/bchat/modules/admin/__init__.py b/bchat/modules/admin/__init__.py index 742bfc3..5d20110 100644 --- a/bchat/modules/admin/__init__.py +++ b/bchat/modules/admin/__init__.py @@ -1,4 +1,5 @@ +from .dev import H_DEV from .misc import H_MISC from .sendall import H_SENDALL_CONV from .shop import H_SHOP @@ -6,5 +7,6 @@ HANDLERS_ADMIN = [ *H_MISC, *H_SHOP, + *H_DEV, H_SENDALL_CONV ] diff --git a/bchat/modules/admin/dev.py b/bchat/modules/admin/dev.py new file mode 100644 index 0000000..96ee368 --- /dev/null +++ b/bchat/modules/admin/dev.py @@ -0,0 +1,28 @@ + +import logging + +from deps import require_admin +from settings import DATABASE_PATH +from telegram import Update +from telegram.ext import CommandHandler, ContextTypes + +Ctx = ContextTypes.DEFAULT_TYPE + + +MAX_FILE_SIZE = 50 * 1024 * 1024 + + +@require_admin +async def backup(update: Update, ctx: Ctx): + msg = update.effective_message + + if DATABASE_PATH.stat().st_size < 50 * 1024 * 10: + await msg.reply_document(DATABASE_PATH, caption='main db') + logging.info('a backup was made') + else: + await msg.reply_text('main db is too big ❌') + + +H_DEV = [ + CommandHandler(['backup'], backup) +] diff --git a/bchat/modules/admin/misc.py b/bchat/modules/admin/misc.py index e604f9d..8e5eb42 100644 --- a/bchat/modules/admin/misc.py +++ b/bchat/modules/admin/misc.py @@ -102,6 +102,7 @@ async def help_cmd(update: Update, ctx: Ctx): '/help -> for this message\n' '/stats -> user count\n\n' '/update_db -> only for developer\n' + '/backup -> get backup of database\n\n' '/sendall -> send a message to all users\n' '/seen_all -> seen all of your directs\n\n' '/charge_codes -> get unused codes\n'