Files
efer-projects/Rust-Telegram-Obsidian/src/main.rs
T
2026-09-26 01:17:10 +03:00

24 lines
828 B
Rust

use teloxide::prelude::*;
use std::fs;
use chrono::Local;
use std::path::Path;
#[tokio::main]
async fn main() {
let bot = Bot::from_env();
teloxide::repl(bot, |bot: Bot, msg: Message| async move {
if let Some(text) = msg.text() {
let timestamp = Local::now().format("%Y-%m-%d_%H-%M-%S").to_string();
let file_name = format!("TNotes/{}.md", timestamp);
// Здесь асинхронная запись через tokio::fs
if let Err(e) = tokio::fs::write(&file_name, text).await {
bot.send_message(msg.chat.id, format!("Ошибка записи: {}", e)).await?;
} else {
bot.send_message(msg.chat.id, "Заметка создана!").await?;
}
}
respond(())
}).await;
}