All current work
This commit is contained in:
@@ -0,0 +1 @@
|
||||
/target
|
||||
Generated
+2007
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "Rust-Telegram-Obsidian"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
teloxide = { version = "0.17", features = ["macros"] }
|
||||
tokio = { version = "1.0", features = ["full"] }
|
||||
chrono = "0.4" # Для генерации дат
|
||||
anyhow = "1.0"
|
||||
@@ -0,0 +1,24 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user