export db command

This commit is contained in:
2026-04-29 06:45:00 +03:00
parent 8a3c6d40a9
commit 8822e8f46a
2 changed files with 42 additions and 0 deletions
+39
View File
@@ -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<void> {
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);
}
}
}
+3
View File
@@ -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(),