From 8822e8f46aa83c7948615c43fc05a2470c8667dc Mon Sep 17 00:00:00 2001 From: Danil Nikolaev Date: Wed, 29 Apr 2026 06:45:00 +0300 Subject: [PATCH] export db command --- src/commands/export-db.ts | 39 +++++++++++++++++++++++++++++++++++++++ src/index.ts | 3 +++ 2 files changed, 42 insertions(+) create mode 100644 src/commands/export-db.ts diff --git a/src/commands/export-db.ts b/src/commands/export-db.ts new file mode 100644 index 0000000..fa79fb2 --- /dev/null +++ b/src/commands/export-db.ts @@ -0,0 +1,39 @@ +import {Command} from "../base/command"; +import {FileOptions, Message} from "typescript-telegram-bot-api"; +import {Requirements} from "../base/requirements"; +import {Requirement} from "../base/requirement"; +import {Environment} from "../common/environment"; +import fs from "node:fs"; +import {logError, replyToMessage, sendErrorPlaceholder} from "../util/utils"; +import {bot} from "../index"; + +export class ExportDb extends Command { + + command = ["exportdb"]; + + argsMode = "none" as const; + + requirements = Requirements.Build(Requirement.BOT_CREATOR); + + async execute(msg: Message): Promise { + const fullPath = Environment.DB_PATH.substring(5); + if (!fs.existsSync(fullPath)) { + await sendErrorPlaceholder(msg); + return; + } + + try { + const buffer = fs.readFileSync(fullPath); + + await bot.sendDocument({ + chat_id: Environment.CREATOR_ID, + document: new FileOptions(buffer, {filename: "database.db", contentType: "application/sql"}), + caption: "Бэкап базы данных", + }); + await replyToMessage({message: msg, text: "Успешно отправлено в ЛС создателю!"}); + } catch (e) { + logError(e); + await sendErrorPlaceholder(msg); + } + } +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 93c30cb..27ed069 100644 --- a/src/index.ts +++ b/src/index.ts @@ -82,6 +82,7 @@ import {clearUpFolderFromOldFiles} from "./util/files"; import {DownloadYtVideo} from "./callback_commands/download-yt-video"; import {YtInfo} from "./callback_commands/yt-info"; import {AdminsList} from "./commands/admins-list"; +import {ExportDb} from "./commands/export-db"; process.setUncaughtExceptionCaptureCallback(logError); @@ -164,6 +165,8 @@ export const commands: Command[] = [ new AdminsRemove(), new AdminsList(), + new ExportDb(), + new Shutdown(), new Leave(),