diff --git a/src/main.rs b/src/main.rs index d75d197..566cd99 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,8 +29,8 @@ async fn main() { let notify_bot = bot.clone(); tokio::spawn(telegram::notification_task(notify_bot, chat_id, rx)); - let cmd_entries_dir = entries_dir.clone(); - tokio::spawn(telegram::bot_task(bot, chat_id, cmd_entries_dir)); + let cmd_data_dir = config.data_dir.clone(); + tokio::spawn(telegram::bot_task(bot, chat_id, cmd_data_dir)); } _ => { tracing::info!("telegram not configured, moderation notifications disabled"); diff --git a/src/telegram.rs b/src/telegram.rs index 0e48359..61d9735 100644 --- a/src/telegram.rs +++ b/src/telegram.rs @@ -41,15 +41,17 @@ pub async fn notification_task(bot: Bot, chat_id: ChatId, mut rx: Receiver<(Entr } /// Run the Telegram bot that listens for /allow_ and /deny_ commands. -pub async fn bot_task(bot: Bot, chat_id: ChatId, entries_dir: PathBuf) { +pub async fn bot_task(bot: Bot, chat_id: ChatId, data_dir: PathBuf) { let handler = Update::filter_message().endpoint( - |bot: Bot, msg: Message, entries_dir: PathBuf, chat_id: ChatId| async move { + |bot: Bot, msg: Message, data_dir: PathBuf, chat_id: ChatId| async move { let text = msg.text().unwrap_or(""); // Only respond to the configured chat if msg.chat.id != chat_id { return respond(()); } + let entries_dir = data_dir.join("entries"); + if let Some(id) = text.strip_prefix("/allow_") { match entries::set_status(&entries_dir, id, Status::Approved) { Ok(name) => { @@ -77,7 +79,7 @@ pub async fn bot_task(bot: Bot, chat_id: ChatId, entries_dir: PathBuf) { ); Dispatcher::builder(bot, handler) - .dependencies(dptree::deps![entries_dir, chat_id]) + .dependencies(dptree::deps![data_dir, chat_id]) .build() .dispatch() .await;