Skip to content

Commit

Permalink
feat: add backup admin cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
i007c committed Jun 24, 2023
1 parent 4b80181 commit 6890cae
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bchat/modules/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@

from .dev import H_DEV
from .misc import H_MISC
from .sendall import H_SENDALL_CONV
from .shop import H_SHOP

HANDLERS_ADMIN = [
*H_MISC,
*H_SHOP,
*H_DEV,
H_SENDALL_CONV
]
28 changes: 28 additions & 0 deletions bchat/modules/admin/dev.py
Original file line number Diff line number Diff line change
@@ -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)
]
1 change: 1 addition & 0 deletions bchat/modules/admin/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 6890cae

Please sign in to comment.