2022-12-12 10:13:58 +01:00
|
|
|
from os import sep, makedirs, remove
|
|
|
|
from uuid import uuid1
|
2022-12-27 18:46:17 +01:00
|
|
|
from app import app
|
2022-12-05 18:49:51 +01:00
|
|
|
from pyrogram import filters
|
2022-12-27 13:36:54 +01:00
|
|
|
from pyrogram.types import Message
|
|
|
|
from pyrogram.client import Client
|
2022-12-05 18:49:51 +01:00
|
|
|
from pyrogram.enums.chat_action import ChatAction
|
2022-12-16 15:04:42 +01:00
|
|
|
from modules.logging import logWrite
|
2022-12-15 14:52:33 +01:00
|
|
|
from modules.utils import should_quote, jsonSave
|
2022-12-12 10:13:58 +01:00
|
|
|
from modules.database import col_applications
|
2022-12-27 18:46:17 +01:00
|
|
|
from modules import custom_filters
|
2022-12-05 18:49:51 +01:00
|
|
|
|
|
|
|
# Applications command =========================================================================================================
|
2023-01-03 20:34:13 +01:00
|
|
|
@app.on_message(custom_filters.enabled_applications & ~filters.scheduled & filters.command(["applications"], prefixes=["/"]) & custom_filters.admin)
|
2022-12-27 13:36:54 +01:00
|
|
|
async def cmd_applications(app: Client, msg: Message):
|
2022-12-05 18:49:51 +01:00
|
|
|
|
2022-12-27 18:46:17 +01:00
|
|
|
logWrite(f"Admin {msg.from_user.id} requested export of a database")
|
|
|
|
await app.send_chat_action(msg.chat.id, ChatAction.UPLOAD_DOCUMENT)
|
|
|
|
filename = uuid1()
|
|
|
|
output = []
|
|
|
|
for entry in col_applications.find():
|
|
|
|
del entry["_id"]
|
|
|
|
entry["date"] = entry["date"].strftime("%d.%m.%Y, %H:%M")
|
|
|
|
entry["application"]["2"] = entry["application"]["2"].strftime("%d.%m.%Y, %H:%M")
|
|
|
|
output.append(entry)
|
|
|
|
makedirs("tmp", exist_ok=True)
|
|
|
|
jsonSave(output, f"tmp{sep}{filename}.json")
|
|
|
|
await msg.reply_document(document=f"tmp{sep}{filename}.json", file_name="applications", quote=should_quote(msg))
|
|
|
|
remove(f"tmp{sep}{filename}.json")
|
2022-12-05 18:49:51 +01:00
|
|
|
# ==============================================================================================================================
|